cli: option to disable vacuum on migration

This commit is contained in:
Evgeny Poberezkin
2024-12-28 12:50:47 +00:00
parent d37d309f85
commit 483d888fe2
9 changed files with 36 additions and 27 deletions
+4 -4
View File
@@ -183,10 +183,10 @@ fluxXFTPServers =
logCfg :: LogConfig
logCfg = LogConfig {lc_file = Nothing, lc_stderr = True}
createChatDatabase :: FilePath -> ScrubbedBytes -> Bool -> MigrationConfirmation -> IO (Either MigrationError ChatDatabase)
createChatDatabase filePrefix key keepKey confirmMigrations = runExceptT $ do
chatStore <- ExceptT $ createChatStore (chatStoreFile filePrefix) key keepKey confirmMigrations
agentStore <- ExceptT $ createAgentStore (agentStoreFile filePrefix) key keepKey confirmMigrations
createChatDatabase :: FilePath -> ScrubbedBytes -> Bool -> MigrationConfirmation -> Bool -> IO (Either MigrationError ChatDatabase)
createChatDatabase filePrefix key keepKey confirmMigrations vacuum = runExceptT $ do
chatStore <- ExceptT $ createChatStore (chatStoreFile filePrefix) key keepKey confirmMigrations vacuum
agentStore <- ExceptT $ createAgentStore (agentStoreFile filePrefix) key keepKey confirmMigrations vacuum
pure ChatDatabase {chatStore, agentStore}
newChatController :: ChatDatabase -> Maybe User -> ChatConfig -> ChatOpts -> Bool -> IO ChatController
+2 -2
View File
@@ -34,14 +34,14 @@ import Text.Read (readMaybe)
import UnliftIO.Async
simplexChatCore :: ChatConfig -> ChatOpts -> (User -> ChatController -> IO ()) -> IO ()
simplexChatCore cfg@ChatConfig {confirmMigrations, testView} opts@ChatOpts {coreOptions = CoreChatOpts {dbFilePrefix, dbKey, logAgent, yesToUpMigrations}} chat =
simplexChatCore cfg@ChatConfig {confirmMigrations, testView} opts@ChatOpts {coreOptions = CoreChatOpts {dbFilePrefix, dbKey, logAgent, yesToUpMigrations, vaccumOnMigration}} chat =
case logAgent of
Just level -> do
setLogLevel level
withGlobalLogging logCfg initRun
_ -> initRun
where
initRun = createChatDatabase dbFilePrefix dbKey False confirm' >>= either exit run
initRun = createChatDatabase dbFilePrefix dbKey False confirm' vaccumOnMigration >>= either exit run
confirm' = if confirmMigrations == MCConsole && yesToUpMigrations then MCYesUp else confirmMigrations
exit e = do
putStrLn $ "Error opening database: " <> show e
+3 -2
View File
@@ -201,7 +201,8 @@ mobileChatOpts dbFilePrefix =
logFile = Nothing,
tbqSize = 1024,
highlyAvailable = False,
yesToUpMigrations = False
yesToUpMigrations = False,
vaccumOnMigration = True
},
deviceName = Nothing,
chatCmd = "",
@@ -245,7 +246,7 @@ chatMigrateInitKey dbFilePrefix dbKey keepKey confirm backgroundMode = runExcept
newChatController db user_ defaultMobileConfig (mobileChatOpts dbFilePrefix) backgroundMode
migrate createStore dbFile confirmMigrations =
ExceptT $
(first (DBMErrorMigration dbFile) <$> createStore dbFile dbKey keepKey confirmMigrations)
(first (DBMErrorMigration dbFile) <$> createStore dbFile dbKey keepKey confirmMigrations True)
`catch` (pure . checkDBError)
`catchAll` (pure . dbError)
where
+9 -2
View File
@@ -66,7 +66,8 @@ data CoreChatOpts = CoreChatOpts
logFile :: Maybe FilePath,
tbqSize :: Natural,
highlyAvailable :: Bool,
yesToUpMigrations :: Bool
yesToUpMigrations :: Bool,
vaccumOnMigration :: Bool
}
data ChatCmdLog = CCLAll | CCLMessages | CCLNone
@@ -240,6 +241,11 @@ coreChatOptsP appDir defaultDbFileName = do
<> short 'y'
<> help "Automatically confirm \"up\" database migrations"
)
disableVacuum <-
switch
( long "disable-vacuum"
<> help "Do not vacuum database after migrations"
)
pure
CoreChatOpts
{ dbFilePrefix,
@@ -265,7 +271,8 @@ coreChatOptsP appDir defaultDbFileName = do
logFile,
tbqSize,
highlyAvailable,
yesToUpMigrations
yesToUpMigrations,
vaccumOnMigration = not disableVacuum
}
where
useTcpTimeout p t = 1000000 * if t > 0 then t else maybe 7 (const 15) p
+1 -1
View File
@@ -21,7 +21,7 @@ import Simplex.Messaging.Agent.Store.SQLite (createDBStore)
import Simplex.Messaging.Agent.Store.SQLite.Common (DBStore (..), withTransaction)
import Simplex.Messaging.Agent.Store.Shared (MigrationConfirmation, MigrationError)
createChatStore :: FilePath -> ScrubbedBytes -> Bool -> MigrationConfirmation -> IO (Either MigrationError DBStore)
createChatStore :: FilePath -> ScrubbedBytes -> Bool -> MigrationConfirmation -> Bool -> IO (Either MigrationError DBStore)
createChatStore dbPath key keepKey = createDBStore dbPath key keepKey migrations
chatStoreFile :: FilePath -> FilePath