mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-12 13:05:15 +00:00
cli: option to disable vacuum on migration
This commit is contained in:
+4
-4
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user