Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: option to confirm up migrations #4150

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Simplex/Chat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-}

Check warning on line 15 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-8.10.7

unrecognised warning flag: -fno-warn-ambiguous-fields

Check warning on line 15 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-8.10.7

unrecognised warning flag: -fno-warn-ambiguous-fields

module Simplex.Chat where

Expand Down Expand Up @@ -218,11 +218,12 @@
newChatController
ChatDatabase {chatStore, agentStore}
user
cfg@ChatConfig {agentConfig = aCfg, defaultServers, inlineFiles, deviceNameForRemote}
ChatOpts {coreOptions = CoreChatOpts {smpServers, xftpServers, simpleNetCfg, logLevel, logConnections, logServerHosts, logFile, tbqSize, highlyAvailable}, deviceName, optFilesFolder, optTempDirectory, showReactions, allowInstantFiles, autoAcceptFileSize}
cfg@ChatConfig {agentConfig = aCfg, defaultServers, inlineFiles, deviceNameForRemote, confirmMigrations}
ChatOpts {coreOptions = CoreChatOpts {smpServers, xftpServers, simpleNetCfg, logLevel, logConnections, logServerHosts, logFile, tbqSize, highlyAvailable, yesToUpMigrations}, deviceName, optFilesFolder, optTempDirectory, showReactions, allowInstantFiles, autoAcceptFileSize}
backgroundMode = do
let inlineFiles' = if allowInstantFiles || autoAcceptFileSize > 0 then inlineFiles else inlineFiles {sendChunks = 0, receiveInstant = False}
config = cfg {logLevel, showReactions, tbqSize, subscriptionEvents = logConnections, hostEvents = logServerHosts, defaultServers = configServers, inlineFiles = inlineFiles', autoAcceptFileSize, highlyAvailable}
confirmMigrations' = if confirmMigrations == MCConsole && yesToUpMigrations then MCYesUp else confirmMigrations
config = cfg {logLevel, showReactions, tbqSize, subscriptionEvents = logConnections, hostEvents = logServerHosts, defaultServers = configServers, inlineFiles = inlineFiles', autoAcceptFileSize, highlyAvailable, confirmMigrations = confirmMigrations'}
firstTime = dbNew chatStore
currentUser <- newTVarIO user
currentRemoteHost <- newTVarIO Nothing
Expand Down Expand Up @@ -370,7 +371,7 @@
. map (\ServerCfg {server} -> server)
. filter (\ServerCfg {enabled} -> enabled)

cfgServers :: UserProtocol p => SProtocolType p -> (DefaultAgentServers -> NonEmpty (ProtoServerWithAuth p))

Check warning on line 374 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-20.04-9.6.3

Redundant constraint: UserProtocol p

Check warning on line 374 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-ubuntu-22.04-9.6.3

Redundant constraint: UserProtocol p

Check warning on line 374 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-macos-latest-9.6.3

Redundant constraint: UserProtocol p

Check warning on line 374 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-macos-13-9.6.3

Redundant constraint: UserProtocol p

Check warning on line 374 in src/Simplex/Chat.hs

View workflow job for this annotation

GitHub Actions / build-windows-latest-9.6.3

Redundant constraint: UserProtocol p
cfgServers p DefaultAgentServers {smp, xftp} = case p of
SPSMP -> smp
SPXFTP -> xftp
Expand Down
3 changes: 2 additions & 1 deletion src/Simplex/Chat/Mobile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ mobileChatOpts dbFilePrefix =
logAgent = Nothing,
logFile = Nothing,
tbqSize = 1024,
highlyAvailable = False
highlyAvailable = False,
yesToUpMigrations = False
},
deviceName = Nothing,
chatCmd = "",
Expand Down
12 changes: 10 additions & 2 deletions src/Simplex/Chat/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ data CoreChatOpts = CoreChatOpts
logAgent :: Maybe LogLevel,
logFile :: Maybe FilePath,
tbqSize :: Natural,
highlyAvailable :: Bool
highlyAvailable :: Bool,
yesToUpMigrations :: Bool
}

data ChatCmdLog = CCLAll | CCLMessages | CCLNone
Expand Down Expand Up @@ -204,6 +205,12 @@ coreChatOptsP appDir defaultDbFileName = do
( long "ha"
<> help "Run as a highly available client (this may increase traffic in groups)"
)
yesToUpMigrations <-
switch
( long "--yes-migrate"
<> short 'y'
<> help "Automatically confirm \"up\" database migrations"
)
pure
CoreChatOpts
{ dbFilePrefix,
Expand All @@ -217,7 +224,8 @@ coreChatOptsP appDir defaultDbFileName = do
logAgent = if logAgent || logLevel == CLLDebug then Just $ agentLogLevel logLevel else Nothing,
logFile,
tbqSize,
highlyAvailable
highlyAvailable,
yesToUpMigrations
}
where
useTcpTimeout p t = 1000000 * if t > 0 then t else maybe 7 (const 15) p
Expand Down
3 changes: 2 additions & 1 deletion tests/ChatClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ testCoreOpts =
logAgent = Nothing,
logFile = Nothing,
tbqSize = 16,
highlyAvailable = False
highlyAvailable = False,
yesToUpMigrations = False
}

getTestOpts :: Bool -> ScrubbedBytes -> ChatOpts
Expand Down