mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-22 21:52:28 +00:00
core: support postgres backend (#5403)
* postgres: modules structure (#5401) * postgres: schema, field conversions (#5430) * postgres: rework chat list pagination query (#5441) * prepare cabal for merge * restore cabal changes * simplexmq * postgres: implementation wip (tests don't pass) (#5481) * restore ios file * postgres: implementation - tests pass (#5487) * refactor DB options * refactor * line * style * style * refactor * $ * update simplexmq * constraintError * handleDBErrors * fix * remove param * Ok * case * case * case * comment --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
1 parent
13fae855fc
commit
e05a35e26e
187 files changed
+2847
-1291
No files matched your search
+15
-38
@@ -14,12 +14,12 @@ module Simplex.Chat.Options
|
||||
getChatOpts,
|
||||
protocolServersP,
|
||||
defaultHostMode,
|
||||
printDbOpts,
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Logger.Simple (LogLevel (..))
|
||||
import qualified Data.Attoparsec.ByteString.Char8 as A
|
||||
import Data.ByteArray (ScrubbedBytes)
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Text (Text)
|
||||
@@ -34,7 +34,7 @@ import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Parsers (parseAll)
|
||||
import Simplex.Messaging.Protocol (ProtoServerWithAuth, ProtocolTypeI, SMPServerWithAuth, XFTPServerWithAuth)
|
||||
import Simplex.Messaging.Transport.Client (SocksProxyWithAuth (..), SocksAuth (..), defaultSocksProxyWithAuth)
|
||||
import System.FilePath (combine)
|
||||
import Simplex.Chat.Options.DB
|
||||
|
||||
data ChatOpts = ChatOpts
|
||||
{ coreOptions :: CoreChatOpts,
|
||||
@@ -54,8 +54,7 @@ data ChatOpts = ChatOpts
|
||||
}
|
||||
|
||||
data CoreChatOpts = CoreChatOpts
|
||||
{ dbFilePrefix :: String,
|
||||
dbKey :: ScrubbedBytes,
|
||||
{ dbOptions :: ChatDbOpts,
|
||||
smpServers :: [SMPServerWithAuth],
|
||||
xftpServers :: [XFTPServerWithAuth],
|
||||
simpleNetCfg :: SimpleNetCfg,
|
||||
@@ -66,8 +65,7 @@ data CoreChatOpts = CoreChatOpts
|
||||
logFile :: Maybe FilePath,
|
||||
tbqSize :: Natural,
|
||||
highlyAvailable :: Bool,
|
||||
yesToUpMigrations :: Bool,
|
||||
vacuumOnMigration :: Bool
|
||||
yesToUpMigrations :: Bool
|
||||
}
|
||||
|
||||
data ChatCmdLog = CCLAll | CCLMessages | CCLNone
|
||||
@@ -82,24 +80,8 @@ agentLogLevel = \case
|
||||
CLLImportant -> LogInfo
|
||||
|
||||
coreChatOptsP :: FilePath -> FilePath -> Parser CoreChatOpts
|
||||
coreChatOptsP appDir defaultDbFileName = do
|
||||
dbFilePrefix <-
|
||||
strOption
|
||||
( long "database"
|
||||
<> short 'd'
|
||||
<> metavar "DB_FILE"
|
||||
<> help "Path prefix to chat and agent database files"
|
||||
<> value defaultDbFilePath
|
||||
<> showDefault
|
||||
)
|
||||
dbKey <-
|
||||
strOption
|
||||
( long "key"
|
||||
<> short 'k'
|
||||
<> metavar "KEY"
|
||||
<> help "Database encryption key/pass-phrase"
|
||||
<> value ""
|
||||
)
|
||||
coreChatOptsP appDir defaultDbName = do
|
||||
dbOptions <- chatDbOptsP appDir defaultDbName
|
||||
smpServers <-
|
||||
option
|
||||
parseProtocolServers
|
||||
@@ -241,15 +223,9 @@ 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,
|
||||
dbKey,
|
||||
{ dbOptions,
|
||||
smpServers,
|
||||
xftpServers,
|
||||
simpleNetCfg =
|
||||
@@ -271,12 +247,10 @@ coreChatOptsP appDir defaultDbFileName = do
|
||||
logFile,
|
||||
tbqSize,
|
||||
highlyAvailable,
|
||||
yesToUpMigrations,
|
||||
vacuumOnMigration = not disableVacuum
|
||||
yesToUpMigrations
|
||||
}
|
||||
where
|
||||
useTcpTimeout p t = 1000000 * if t > 0 then t else maybe 7 (const 15) p
|
||||
defaultDbFilePath = combine appDir defaultDbFileName
|
||||
|
||||
defaultHostMode :: Maybe SocksProxyWithAuth -> HostMode
|
||||
defaultHostMode = \case
|
||||
@@ -284,8 +258,8 @@ defaultHostMode = \case
|
||||
_ -> HMPublic
|
||||
|
||||
chatOptsP :: FilePath -> FilePath -> Parser ChatOpts
|
||||
chatOptsP appDir defaultDbFileName = do
|
||||
coreOptions <- coreChatOptsP appDir defaultDbFileName
|
||||
chatOptsP appDir defaultDbName = do
|
||||
coreOptions <- coreChatOptsP appDir defaultDbName
|
||||
deviceName <-
|
||||
optional $
|
||||
strOption
|
||||
@@ -432,12 +406,15 @@ parseChatCmdLog = eitherReader $ \case
|
||||
_ -> Left "Invalid chat command log level"
|
||||
|
||||
getChatOpts :: FilePath -> FilePath -> IO ChatOpts
|
||||
getChatOpts appDir defaultDbFileName =
|
||||
getChatOpts appDir defaultDbName =
|
||||
execParser $
|
||||
info
|
||||
(helper <*> versionOption <*> chatOptsP appDir defaultDbFileName)
|
||||
(helper <*> versionOption <*> chatOptsP appDir defaultDbName)
|
||||
(header versionStr <> fullDesc <> progDesc "Start chat with DB_FILE file and use SERVER as SMP server")
|
||||
where
|
||||
versionStr = versionString versionNumber
|
||||
versionOption = infoOption versionAndUpdate (long "version" <> short 'v' <> help "Show version")
|
||||
versionAndUpdate = versionStr <> "\n" <> updateStr
|
||||
|
||||
printDbOpts :: CoreChatOpts -> IO ()
|
||||
printDbOpts opts = putStrLn $ "db: " <> dbString (dbOptions opts)
|
||||
Reference in new issue
Block a user