Skip to content

Commit

Permalink
Provide DB-specific locations through conditional compilation
Browse files Browse the repository at this point in the history
Use a single data structure, `databaseLocation`, to describe either a work directory or in-memory when compiled for SQLite
or a remote URL when compiled for PostgreSQL. This provides strong type safety but comes at the cost of having to include a
argument parser in the DB modules, which is not really where it belongs. Alternatively, conditional compilation could be
added to the argument parsing module, but that also seems out of place. Ultimately, including all 3 alternatives in
`databaseLocation` and validating at runtime may be a cleaner solution, despite the loss of type safety.
  • Loading branch information
domMayhew committed May 28, 2024
1 parent 153bd4c commit 2701b34
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 506 deletions.
8 changes: 3 additions & 5 deletions src/Kupo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Kupo.App.Database
( ConnectionType (..)
, DBPool (..)
, copyDatabase
, mkDBPool
)
import Kupo.App.Health
( connectionStatusToggle
Expand Down Expand Up @@ -132,9 +133,6 @@ import System.Exit
( ExitCode (..)
)

import Kupo.App.Database.SQLite
( mkDBPool
)
import qualified Kupo.Data.Health as Health

--
Expand Down Expand Up @@ -190,7 +188,7 @@ kupoWith tr withProducer withFetchBlock =
, configuration = config@Configuration
{ serverHost
, serverPort
, workDir
, databaseLocation
, inputManagement
, longestRollback
, deferIndexes
Expand All @@ -205,7 +203,7 @@ kupoWith tr withProducer withFetchBlock =
-- , maxConcurrentWriters = if isReadOnlyReplica config then 0 else maxConcurrentWriters
-- }

dbPool <- liftIO $ mkDBPool (isReadOnlyReplica config) (tracerDatabase tr) workDir longestRollback
dbPool <- liftIO $ mkDBPool (isReadOnlyReplica config) (tracerDatabase tr) databaseLocation longestRollback

let run action
| isReadOnlyReplica config =
Expand Down
9 changes: 7 additions & 2 deletions src/Kupo/App/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ module Kupo.App.Database
, rollbackQryDeleteCheckpoints

-- * Setup
, copyDatabase
, ConnectionType (..)
, DBPool (..)
, mkDBPool
, copyDatabase

-- ** Option Parser
, databaseLocationOptionParser

-- * Internal
, installIndexes
Expand All @@ -50,10 +54,11 @@ module Kupo.App.Database
import Kupo.App.Database.Postgres
#else
import Kupo.App.Database.SQLite
#endif

import Kupo.App.Database.Types
( ConnectionType (..)
, DBPool (..)
, DBTransaction
, Database (..)
)
#endif

0 comments on commit 2701b34

Please sign in to comment.