Only set wal after vacuum-into copies

This commit is contained in:
Chris Penner 2023-06-13 10:36:30 -06:00
parent 38b778009d
commit 24b5f17338
3 changed files with 6 additions and 1 deletions

View File

@ -104,7 +104,6 @@ openConnection name file = do
_ -> "file:" <> file <> "?mode=ro"
conn0 <- Sqlite.open sqliteURI `catch` rethrowAsSqliteConnectException name file
let conn = Connection {conn = conn0, file, name}
execute conn [Sql.sql| PRAGMA journal_mode = wal |]
execute conn [Sql.sql| PRAGMA foreign_keys = ON |]
execute conn [Sql.sql| PRAGMA busy_timeout = 60000 |]
pure conn

View File

@ -783,3 +783,6 @@ copyCodebase src dest = liftIO $ do
createDirectoryIfMissing True (makeCodebaseDirPath dest)
withConnection ("copy-from:" <> src) src $ \srcConn -> do
Sqlite.vacuumInto srcConn (makeCodebasePath dest)
-- We need to reset the journal mode because vacuum-into clears it.
withConnection ("copy-to:" <> dest) dest $ \destConn -> do
Sqlite.trySetJournalMode destConn Sqlite.JournalMode'WAL

View File

@ -192,5 +192,8 @@ backupCodebaseIfNecessary backupStrategy localOrRemote conn currentSchemaVersion
| otherwise -> do
backupPath <- getPOSIXTime <&> (\t -> root </> backupCodebasePath currentSchemaVersion t)
Sqlite.vacuumInto conn backupPath
-- vacuum-into clears the journal mode, so we need to set it again.
Sqlite.withConnection "backup" backupPath \backupConn -> do
Sqlite.trySetJournalMode backupConn Sqlite.JournalMode'WAL
putStrLn ("📋 I backed up your codebase to " ++ (root </> backupPath))
putStrLn "⚠️ Please close all other ucm processes and wait for the migration to complete before interacting with your codebase."