mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-04 23:21:55 +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:
@@ -0,0 +1,14 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
|
||||
module Simplex.Chat.Options.DB
|
||||
#if defined(dbPostgres)
|
||||
( module Simplex.Chat.Options.Postgres,
|
||||
)
|
||||
where
|
||||
import Simplex.Chat.Options.Postgres
|
||||
#else
|
||||
( module Simplex.Chat.Options.SQLite,
|
||||
)
|
||||
where
|
||||
import Simplex.Chat.Options.SQLite
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
{-# LANGUAGE ApplicativeDo #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
|
||||
module Simplex.Chat.Options.Postgres where
|
||||
|
||||
import Options.Applicative
|
||||
|
||||
data ChatDbOpts = ChatDbOpts
|
||||
{ dbName :: String,
|
||||
dbUser :: String,
|
||||
dbSchemaPrefix :: String
|
||||
}
|
||||
|
||||
chatDbOptsP :: FilePath -> String -> Parser ChatDbOpts
|
||||
chatDbOptsP _appDir defaultDbName = do
|
||||
dbName <-
|
||||
strOption
|
||||
( long "database"
|
||||
<> short 'd'
|
||||
<> metavar "DB_NAME"
|
||||
<> help "Database name"
|
||||
<> value defaultDbName
|
||||
<> showDefault
|
||||
)
|
||||
dbUser <-
|
||||
strOption
|
||||
( long "database-user"
|
||||
<> short 'u'
|
||||
<> metavar "DB_USER"
|
||||
<> help "Database user"
|
||||
<> value "simplex"
|
||||
<> showDefault
|
||||
)
|
||||
pure ChatDbOpts {dbName, dbUser, dbSchemaPrefix = ""}
|
||||
|
||||
dbString :: ChatDbOpts -> String
|
||||
dbString ChatDbOpts {dbName} = dbName
|
||||
@@ -0,0 +1,44 @@
|
||||
{-# LANGUAGE ApplicativeDo #-}
|
||||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Simplex.Chat.Options.SQLite where
|
||||
|
||||
import Data.ByteArray (ScrubbedBytes)
|
||||
import Options.Applicative
|
||||
import System.FilePath (combine)
|
||||
|
||||
data ChatDbOpts = ChatDbOpts
|
||||
{ dbFilePrefix :: String,
|
||||
dbKey :: ScrubbedBytes,
|
||||
vacuumOnMigration :: Bool
|
||||
}
|
||||
|
||||
chatDbOptsP :: FilePath -> FilePath -> Parser ChatDbOpts
|
||||
chatDbOptsP appDir defaultDbName = do
|
||||
dbFilePrefix <-
|
||||
strOption
|
||||
( long "database"
|
||||
<> short 'd'
|
||||
<> metavar "DB_FILE"
|
||||
<> help "Path prefix to chat and agent database files"
|
||||
<> value (combine appDir defaultDbName)
|
||||
<> showDefault
|
||||
)
|
||||
dbKey <-
|
||||
strOption
|
||||
( long "key"
|
||||
<> short 'k'
|
||||
<> metavar "KEY"
|
||||
<> help "Database encryption key/pass-phrase"
|
||||
<> value ""
|
||||
)
|
||||
disableVacuum <-
|
||||
switch
|
||||
( long "disable-vacuum"
|
||||
<> help "Do not vacuum database after migrations"
|
||||
)
|
||||
pure ChatDbOpts {dbFilePrefix, dbKey, vacuumOnMigration = not disableVacuum}
|
||||
|
||||
dbString :: ChatDbOpts -> String
|
||||
dbString ChatDbOpts {dbFilePrefix} = dbFilePrefix <> "_chat.db, " <> dbFilePrefix <> "_agent.db"
|
||||
Reference in New Issue
Block a user