@@ -15,7 +15,7 @@ module Cardano.DbSync (
15
15
LedgerStateDir (.. ),
16
16
NetworkName (.. ),
17
17
SocketPath (.. ),
18
- Db . MigrationDir (.. ),
18
+ DB . MigrationDir (.. ),
19
19
runDbSyncNode ,
20
20
runMigrationsOnly ,
21
21
runDbSync ,
@@ -40,8 +40,10 @@ import Prelude (id)
40
40
41
41
import Cardano.BM.Trace (Trace , logError , logInfo , logWarning )
42
42
import qualified Cardano.Crypto as Crypto
43
+ import Cardano.Prelude hiding (Nat , (%) )
44
+ import Cardano.Slotting.Slot (EpochNo (.. ))
45
+
43
46
import qualified Cardano.Db as DB
44
- import qualified Cardano.Db as Db
45
47
import Cardano.DbSync.Api
46
48
import Cardano.DbSync.Api.Types (InsertOptions (.. ), RunMigration , SyncEnv (.. ), SyncOptions (.. ), envLedgerEnv )
47
49
import Cardano.DbSync.Config (configureLogging )
@@ -57,8 +59,6 @@ import Cardano.DbSync.Rollback (unsafeRollback)
57
59
import Cardano.DbSync.Sync (runSyncNodeClient )
58
60
import Cardano.DbSync.Tracing.ToObjectOrphans ()
59
61
import Cardano.DbSync.Types
60
- import Cardano.Prelude hiding (Nat , (%) )
61
- import Cardano.Slotting.Slot (EpochNo (.. ))
62
62
63
63
runDbSyncNode :: MetricSetters -> [(Text , Text )] -> SyncNodeParams -> SyncNodeConfig -> IO ()
64
64
runDbSyncNode metricsSetters knownMigrations params syncNodeConfigFromFile =
@@ -84,25 +84,24 @@ runMigrationsOnly knownMigrations trce params syncNodeConfigFromFile = do
84
84
logInfo trce $ textShow syncOpts
85
85
86
86
-- Read the PG connection info
87
- pgConfig <- runOrThrowIO (Db . readPGPass $ enpPGPassSource params)
87
+ pgConfig <- runOrThrowIO (DB . readPGPass $ enpPGPassSource params)
88
88
89
- mErrors <- liftIO $ Db . validateMigrations dbMigrationDir knownMigrations
89
+ mErrors <- liftIO $ DB . validateMigrations dbMigrationDir knownMigrations
90
90
whenJust mErrors $ \ (unknown, stage4orNewStage3) ->
91
91
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
94
94
95
95
logInfo trce " Schema migration files validated"
96
96
97
97
let runMigration mode = do
98
- msg <- Db . getMaintenancePsqlConf pgConfig
98
+ msg <- DB . getMaintenancePsqlConf pgConfig
99
99
logInfo trce $ " Running database migrations in mode " <> textShow mode
100
100
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)
103
102
104
103
-- Always run Initial mode only - never indexes
105
- (ranMigrations, unofficial) <- runMigration Db . Initial
104
+ (ranMigrations, unofficial) <- runMigration DB . Initial
106
105
unless (null unofficial) $
107
106
logWarning trce $
108
107
" Unofficial migration scripts found: "
@@ -114,7 +113,7 @@ runMigrationsOnly knownMigrations trce params syncNodeConfigFromFile = do
114
113
115
114
logInfo trce " New user indexes were not created. They may be created later if necessary."
116
115
where
117
- dbMigrationDir :: Db . MigrationDir
116
+ dbMigrationDir :: DB . MigrationDir
118
117
dbMigrationDir = enpMigrationDir params
119
118
syncOpts = extractSyncOptions params False syncNodeConfigFromFile
120
119
txOutConfig = sioTxOut $ dncInsertOptions syncNodeConfigFromFile
@@ -132,9 +131,9 @@ runDbSync metricsSetters iomgr trce params syncNodeConfigFromFile abortOnPanic =
132
131
logInfo trce $ textShow syncOpts
133
132
134
133
-- Read the PG connection info
135
- pgConfig <- runOrThrowIO (Db . readPGPass $ enpPGPassSource params)
134
+ pgConfig <- runOrThrowIO (DB . readPGPass $ enpPGPassSource params)
136
135
137
- dbConnectionSetting <- case Db . toConnectionSetting pgConfig of
136
+ dbConnectionSetting <- case DB . toConnectionSetting pgConfig of
138
137
Left err -> do
139
138
let syncNodeErr = SNErrPGConfig (" Invalid database connection setting: " <> err)
140
139
logError trce $ show syncNodeErr
@@ -147,11 +146,11 @@ runDbSync metricsSetters iomgr trce params syncNodeConfigFromFile abortOnPanic =
147
146
148
147
-- This runMigration is ONLY for delayed migrations during sync (like indexes)
149
148
let runDelayedMigration mode = do
150
- msg <- Db . getMaintenancePsqlConf pgConfig
149
+ msg <- DB . getMaintenancePsqlConf pgConfig
151
150
logInfo trce $ " Running database migrations in mode " <> textShow mode
152
151
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)
155
154
156
155
runSyncNode
157
156
metricsSetters
@@ -163,7 +162,7 @@ runDbSync metricsSetters iomgr trce params syncNodeConfigFromFile abortOnPanic =
163
162
params
164
163
syncOpts
165
164
where
166
- dbMigrationDir :: Db . MigrationDir
165
+ dbMigrationDir :: DB . MigrationDir
167
166
dbMigrationDir = enpMigrationDir params
168
167
syncOpts = extractSyncOptions params abortOnPanic syncNodeConfigFromFile
169
168
txOutConfig = sioTxOut $ dncInsertOptions syncNodeConfigFromFile
@@ -198,7 +197,7 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
198
197
logInfo trce $ " Using alonzo genesis file from: " <> (show . unGenesisFile $ dncAlonzoGenesisFile syncNodeConfigFromFile)
199
198
200
199
let useLedger = shouldUseLedger (sioLedger $ dncInsertOptions syncNodeConfigFromFile)
201
- -- Our main thread
200
+ -- The main thread
202
201
bracket
203
202
(acquireDbConnection [dbConnSetting])
204
203
HsqlC. release
@@ -207,8 +206,8 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
207
206
let isLogingEnabled = dncEnableDbLogging syncNodeConfigFromFile
208
207
dbEnv =
209
208
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
212
211
genCfg <- readCardanoGenesisConfig syncNodeConfigFromFile
213
212
isJsonbInSchema <- liftDbError $ DB. queryJsonbInSchemaExists dbConn
214
213
logProtocolMagicId trce $ genesisProtocolMagicId genCfg
@@ -235,7 +234,7 @@ runSyncNode metricsSetters trce iomgr dbConnSetting runDelayedMigrationFnc syncN
235
234
liftIO $ runConsumedTxOutMigrationsMaybe syncEnv
236
235
unless useLedger $ liftIO $ do
237
236
logInfo trce " Migrating to a no ledger schema"
238
- Db . noLedgerMigrations dbEnv trce
237
+ DB . noLedgerMigrations dbEnv trce
239
238
insertValidateGenesisDist syncEnv (dncNetworkName syncNodeConfigFromFile) genCfg (useShelleyInit syncNodeConfigFromFile)
240
239
241
240
-- communication channel between datalayer thread and chainsync-client thread
@@ -335,7 +334,7 @@ extractSyncOptions snp aop snc =
335
334
startupReport :: Trace IO Text -> Bool -> SyncNodeParams -> IO ()
336
335
startupReport trce aop params = do
337
336
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]
339
338
logInfo trce $ mconcat [" Enviroment variable DbSyncAbortOnPanic: " , textShow aop]
340
339
logInfo trce $ textShow params
341
340
0 commit comments