2022-04-05 12:44:22 +04:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module SchemaDump where
|
|
|
|
|
|
|
|
import ChatClient (withTmpFiles)
|
2022-07-04 11:15:25 +01:00
|
|
|
import Control.DeepSeq
|
2022-04-05 12:44:22 +04:00
|
|
|
import Control.Monad (void)
|
|
|
|
import Simplex.Chat.Store (createStore)
|
|
|
|
import System.Process (readCreateProcess, shell)
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
testDB :: FilePath
|
|
|
|
testDB = "tests/tmp/test_chat.db"
|
|
|
|
|
|
|
|
schema :: FilePath
|
|
|
|
schema = "src/Simplex/Chat/Migrations/chat_schema.sql"
|
|
|
|
|
|
|
|
schemaDumpTest :: Spec
|
|
|
|
schemaDumpTest =
|
|
|
|
it "verify and overwrite schema dump" testVerifySchemaDump
|
|
|
|
|
|
|
|
testVerifySchemaDump :: IO ()
|
|
|
|
testVerifySchemaDump =
|
|
|
|
withTmpFiles $ do
|
2022-08-30 12:49:07 +01:00
|
|
|
void $ createStore testDB "" False
|
2022-04-05 12:44:22 +04:00
|
|
|
void $ readCreateProcess (shell $ "touch " <> schema) ""
|
|
|
|
savedSchema <- readFile schema
|
2022-07-04 11:15:25 +01:00
|
|
|
savedSchema `deepseq` pure ()
|
2022-06-27 19:41:25 +01:00
|
|
|
void $ readCreateProcess (shell $ "sqlite3 " <> testDB <> " '.schema --indent' > " <> schema) ""
|
2022-04-05 12:44:22 +04:00
|
|
|
currentSchema <- readFile schema
|
|
|
|
savedSchema `shouldBe` currentSchema
|