@@ -15,7 +15,7 @@ module Cardano.DbSync (
1515 LedgerStateDir (.. ),
1616 NetworkName (.. ),
1717 SocketPath (.. ),
18- Db . MigrationDir (.. ),
18+ DB . MigrationDir (.. ),
1919 runDbSyncNode ,
2020 runMigrationsOnly ,
2121 runDbSync ,
@@ -40,8 +40,10 @@ import Prelude (id)
4040
4141import Cardano.BM.Trace (Trace , logError , logInfo , logWarning )
4242import qualified Cardano.Crypto as Crypto
43+ import Cardano.Prelude hiding (Nat , (%) )
44+ import Cardano.Slotting.Slot (EpochNo (.. ))
45+
4346import qualified Cardano.Db as DB
44- import qualified Cardano.Db as Db
4547import Cardano.DbSync.Api
4648import Cardano.DbSync.Api.Types (InsertOptions (.. ), RunMigration , SyncEnv (.. ), SyncOptions (.. ), envLedgerEnv )
4749import Cardano.DbSync.Config (configureLogging )
@@ -57,8 +59,6 @@ import Cardano.DbSync.Rollback (unsafeRollback)
5759import Cardano.DbSync.Sync (runSyncNodeClient )
5860import Cardano.DbSync.Tracing.ToObjectOrphans ()
5961import Cardano.DbSync.Types
60- import Cardano.Prelude hiding (Nat , (%) )
61- import Cardano.Slotting.Slot (EpochNo (.. ))
6262
6363runDbSyncNode :: MetricSetters -> [(Text , Text )] -> SyncNodeParams -> SyncNodeConfig -> IO ()
6464runDbSyncNode metricsSetters knownMigrations params syncNodeConfigFromFile =
@@ -84,25 +84,24 @@ runMigrationsOnly knownMigrations trce params syncNodeConfigFromFile = do
8484 logInfo trce $ textShow syncOpts
8585
8686 -- Read the PG connection info
87- pgConfig <- runOrThrowIO (Db . readPGPass $ enpPGPassSource params)
87+ pgConfig <- runOrThrowIO (DB . readPGPass $ enpPGPassSource params)
8888
89- mErrors <- liftIO $ Db . validateMigrations dbMigrationDir knownMigrations
89+ mErrors <- liftIO $ DB . validateMigrations dbMigrationDir knownMigrations
9090 whenJust mErrors $ \ (unknown, stage4orNewStage3) ->
9191 if stage4orNewStage3
92- then logWarning trce $ Db . renderMigrationValidateError unknown
93- else logError trce $ Db . renderMigrationValidateError unknown
92+ then logWarning trce $ DB . renderMigrationValidateError unknown
93+ else logError trce $ DB . renderMigrationValidateError unknown
9494
9595 logInfo trce " Schema migration files validated"
9696
9797 let runMigration mode = do
98- msg <- Db . getMaintenancePsqlConf pgConfig
98+ msg <- DB . getMaintenancePsqlConf pgConfig
9999 logInfo trce $ " Running database migrations in mode " <> textShow mode
100100 logInfo trce msg
101- -- No index warning here - runMigrationsOnly never runs indexes
102- Db. runMigrations pgConfig True dbMigrationDir (Just $ Db. LogFileDir " /tmp" ) mode (txOutConfigToTableType txOutConfig)
101+ DB. runMigrations pgConfig True dbMigrationDir (Just $ DB. LogFileDir " /tmp" ) mode (txOutConfigToTableType txOutConfig)
103102
104103 -- Always run Initial mode only - never indexes
105- (ranMigrations, unofficial) <- runMigration Db . Initial
104+ (ranMigrations, unofficial) <- runMigration DB . Initial
106105 unless (null unofficial) $
107106 logWarning trce $
108107 " Unofficial migration scripts found: "
@@ -114,7 +113,7 @@ runMigrationsOnly knownMigrations trce params syncNodeConfigFromFile = do
114113
115114 logInfo trce " New user indexes were not created. They may be created later if necessary."
116115 where
117- dbMigrationDir :: Db . MigrationDir
116+ dbMigrationDir :: DB . MigrationDir
118117 dbMigrationDir = enpMigrationDir params
119118 syncOpts = extractSyncOptions params False syncNodeConfigFromFile
120119 txOutConfig = sioTxOut $ dncInsertOptions syncNodeConfigFromFile
@@ -132,9 +131,9 @@ runDbSync metricsSetters iomgr trce params syncNodeConfigFromFile abortOnPanic =
132131 logInfo trce $ textShow syncOpts
133132
134133 -- Read the PG connection info
135- pgConfig <- runOrThrowIO (Db . readPGPass $ enpPGPassSource params)
134+ pgConfig <- runOrThrowIO (DB . readPGPass $ enpPGPassSource params)
136135
137- dbConnectionSetting <- case Db . toConnectionSetting pgConfig of
136+ dbConnectionSetting <- case DB . toConnectionSetting pgConfig of
138137 Left err -> do
139138 let syncNodeErr = SNErrPGConfig (" Invalid database connection setting: " <> err)
140139 logError trce $ show syncNodeErr
@@ -147,11 +146,11 @@ runDbSync metricsSetters iomgr trce params syncNodeConfigFromFile abortOnPanic =
147146
148147 -- This runMigration is ONLY for delayed migrations during sync (like indexes)
149148 let runDelayedMigration mode = do
150- msg <- Db . getMaintenancePsqlConf pgConfig
149+ msg <- DB . getMaintenancePsqlConf pgConfig
151150 logInfo trce $ " Running database migrations in mode " <> textShow mode
152151 logInfo trce msg
153- when (mode `elem` [Db . Indexes , Db . Full ]) $ logWarning trce indexesMsg
154- Db . runMigrations pgConfig True dbMigrationDir (Just $ Db . LogFileDir " /tmp" ) mode (txOutConfigToTableType txOutConfig)
152+ when (mode `elem` [DB . Indexes , DB . Full ]) $ logWarning trce indexesMsg
153+ DB . runMigrations pgConfig True dbMigrationDir (Just $ DB . LogFileDir " /tmp" ) mode (txOutConfigToTableType txOutConfig)
155154
156155 runSyncNode
157156 metricsSetters
@@ -163,7 +162,7 @@ runDbSync metricsSetters iomgr trce params syncNodeConfigFromFile abortOnPanic =
163162 params
164163 syncOpts
165164 where
166- dbMigrationDir :: Db . MigrationDir
165+ dbMigrationDir :: DB . MigrationDir
167166 dbMigrationDir = enpMigrationDir params
168167 syncOpts = extractSyncOptions params abortOnPanic syncNodeConfigFromFile
169168 txOutConfig = sioTxOut $ dncInsertOptions syncNodeConfigFromFile
@@ -198,7 +197,7 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
198197 logInfo trce $ " Using alonzo genesis file from: " <> (show . unGenesisFile $ dncAlonzoGenesisFile syncNodeConfigFromFile)
199198
200199 let useLedger = shouldUseLedger (sioLedger $ dncInsertOptions syncNodeConfigFromFile)
201- -- Our main thread
200+ -- The main thread
202201 bracket
203202 (acquireDbConnection [dbConnSetting])
204203 HsqlC. release
@@ -207,8 +206,8 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
207206 let isLogingEnabled = dncEnableDbLogging syncNodeConfigFromFile
208207 dbEnv =
209208 if isLogingEnabled
210- then Db . DbEnv dbConn isLogingEnabled (Just trce)
211- else Db . DbEnv dbConn isLogingEnabled Nothing
209+ then DB . DbEnv dbConn isLogingEnabled (Just trce)
210+ else DB . DbEnv dbConn isLogingEnabled Nothing
212211 genCfg <- readCardanoGenesisConfig syncNodeConfigFromFile
213212 isJsonbInSchema <- liftDbError $ DB. queryJsonbInSchemaExists dbConn
214213 logProtocolMagicId trce $ genesisProtocolMagicId genCfg
@@ -235,7 +234,7 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
235234 liftIO $ runConsumedTxOutMigrationsMaybe syncEnv
236235 unless useLedger $ liftIO $ do
237236 logInfo trce " Migrating to a no ledger schema"
238- Db . noLedgerMigrations dbEnv trce
237+ DB . noLedgerMigrations dbEnv trce
239238 insertValidateGenesisDist syncEnv (dncNetworkName syncNodeConfigFromFile) genCfg (useShelleyInit syncNodeConfigFromFile)
240239
241240 -- communication channel between datalayer thread and chainsync-client thread
@@ -335,7 +334,7 @@ extractSyncOptions snp aop snc =
335334startupReport :: Trace IO Text -> Bool -> SyncNodeParams -> IO ()
336335startupReport trce aop params = do
337336 logInfo trce $ mconcat [" Version number: " , Text. pack (showVersion version)]
338- logInfo trce $ mconcat [" Git hash: " , Db . gitRev]
337+ logInfo trce $ mconcat [" Git hash: " , DB . gitRev]
339338 logInfo trce $ mconcat [" Enviroment variable DbSyncAbortOnPanic: " , textShow aop]
340339 logInfo trce $ textShow params
341340
0 commit comments