Skip to content

Commit 32f6a5f

Browse files
committed
add cmd line docs and update rollback queries
1 parent 4e51ef9 commit 32f6a5f

File tree

4 files changed

+97
-42
lines changed

4 files changed

+97
-42
lines changed

cardano-db/src/Cardano/Db/Operations/Delete.hs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -145,43 +145,6 @@ deleteUsingEpochNo epochN = do
145145
pure [("GovActionProposal Nulled", a + b + c + e)]
146146
pure $ countLogs <> nullLogs
147147

148-
queryDelete ::
149-
forall m record field.
150-
(MonadIO m, PersistEntity record, PersistField field, PersistEntityBackend record ~ SqlBackend) =>
151-
EntityField record field ->
152-
field ->
153-
ReaderT SqlBackend m ()
154-
queryDelete fieldIdField fieldId = do
155-
mRecordId <- queryMinRefId fieldIdField fieldId
156-
case mRecordId of
157-
Nothing -> pure ()
158-
Just recordId -> deleteWhere [persistIdField @record >=. recordId]
159-
160-
queryDeleteAndLog ::
161-
forall m record field.
162-
(MonadIO m, PersistEntity record, PersistField field, PersistEntityBackend record ~ SqlBackend) =>
163-
Text ->
164-
EntityField record field ->
165-
field ->
166-
ReaderT SqlBackend m [(Text, Int64)]
167-
queryDeleteAndLog tableName txIdField fieldId = do
168-
mRecordId <- queryMinRefId txIdField fieldId
169-
case mRecordId of
170-
Nothing -> pure [(tableName, 0)]
171-
Just recordId -> do
172-
count <- deleteWhereCount [persistIdField @record >=. recordId]
173-
pure [(tableName, count)]
174-
175-
onlyDelete ::
176-
forall m record.
177-
(MonadIO m, PersistEntity record, PersistEntityBackend record ~ SqlBackend) =>
178-
Text ->
179-
[Filter record] ->
180-
ReaderT SqlBackend m [(Text, Int64)]
181-
onlyDelete tableName filters = do
182-
count <- deleteWhereCount filters
183-
pure [(tableName, count)]
184-
185148
deleteTablesAfterBlockId ::
186149
MonadIO m =>
187150
TxOutTableType ->
@@ -334,6 +297,43 @@ deleteTablesAfterTxId txOutTableType mtxId minIdsW = do
334297
-- Return the combined logs of all operations
335298
pure $ minIdsLogs <> txIdLogs
336299

300+
queryDelete ::
301+
forall m record field.
302+
(MonadIO m, PersistEntity record, PersistField field, PersistEntityBackend record ~ SqlBackend) =>
303+
EntityField record field ->
304+
field ->
305+
ReaderT SqlBackend m ()
306+
queryDelete fieldIdField fieldId = do
307+
mRecordId <- queryMinRefId fieldIdField fieldId
308+
case mRecordId of
309+
Nothing -> pure ()
310+
Just recordId -> deleteWhere [persistIdField @record >=. recordId]
311+
312+
queryDeleteAndLog ::
313+
forall m record field.
314+
(MonadIO m, PersistEntity record, PersistField field, PersistEntityBackend record ~ SqlBackend) =>
315+
Text ->
316+
EntityField record field ->
317+
field ->
318+
ReaderT SqlBackend m [(Text, Int64)]
319+
queryDeleteAndLog tableName txIdField fieldId = do
320+
mRecordId <- queryMinRefId txIdField fieldId
321+
case mRecordId of
322+
Nothing -> pure [(tableName, 0)]
323+
Just recordId -> do
324+
count <- deleteWhereCount [persistIdField @record >=. recordId]
325+
pure [(tableName, count)]
326+
327+
onlyDelete ::
328+
forall m record.
329+
(MonadIO m, PersistEntity record, PersistEntityBackend record ~ SqlBackend) =>
330+
Text ->
331+
[Filter record] ->
332+
ReaderT SqlBackend m [(Text, Int64)]
333+
onlyDelete tableName filters = do
334+
count <- deleteWhereCount filters
335+
pure [(tableName, count)]
336+
337337
queryThenNull ::
338338
forall m record field.
339339
(MonadIO m, PersistEntity record, PersistField field, PersistEntityBackend record ~ SqlBackend) =>

cardano-db/src/Cardano/Db/Operations/Other/ConsumedTxOut.hs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ runExtraMigrations trce txOutTableType blockNoDiff pcm = do
122122
DBExtraMigration "runExtraMigrations: The configuration option 'tx_out.use_address_table' was previously set and the database updated. Unfortunately reverting this isn't possible."
123123
-- Has the user given txout address config && the migration wasn't previously set
124124
when (isTxOutVariant && not isTxOutAddressSet) $ do
125-
updateTxOutAndCreateAddress
125+
updateTxOutAndCreateAddress trce
126126
insertExtraMigration TxOutAddressPreviouslySet
127127
-- first check if pruneTxOut flag is missing and it has previously been used
128128
when (isPruneTxOutPreviouslySet migrationValues && not (pcmPruneTxOut pcm)) $
@@ -415,18 +415,29 @@ createPruneConstraintTxOut = do
415415
exceptHandler e =
416416
liftIO $ throwIO (DBPruneConsumed $ show e)
417417

418+
-- Be very mindfull that these queries can fail silently and make tests fail making it hard to know why.
419+
-- To help mitigate this, logs are printed after each query is ran, so one can know where it stopped.
418420
updateTxOutAndCreateAddress ::
419421
forall m.
420422
( MonadBaseControl IO m
421423
, MonadIO m
422424
) =>
425+
Trace IO Text ->
423426
ReaderT SqlBackend m ()
424-
updateTxOutAndCreateAddress = do
427+
updateTxOutAndCreateAddress trc = do
425428
handle exceptHandler $ rawExecute dropViewsQuery []
429+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Dropped views"
426430
handle exceptHandler $ rawExecute alterTxOutQuery []
431+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Altered tx_out"
432+
handle exceptHandler $ rawExecute alterCollateralTxOutQuery []
433+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Altered collateral_tx_out"
427434
handle exceptHandler $ rawExecute createAddressTableQuery []
435+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Created address table"
428436
handle exceptHandler $ rawExecute createIndexPaymentCredQuery []
437+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Created index payment_cred"
429438
handle exceptHandler $ rawExecute createIndexRawQuery []
439+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Created index raw"
440+
liftIO $ logInfo trc "updateTxOutAndCreateAddress: Completed"
430441
where
431442
dropViewsQuery =
432443
Text.unlines
@@ -440,8 +451,16 @@ updateTxOutAndCreateAddress = do
440451
, " ADD COLUMN \"address_id\" INT8 NOT NULL,"
441452
, " DROP COLUMN \"address\","
442453
, " DROP COLUMN \"address_has_script\","
443-
, " DROP COLUMN \"payment_cred\","
444-
, " DROP COLUMN \"stake_address_id\""
454+
, " DROP COLUMN \"payment_cred\""
455+
]
456+
457+
alterCollateralTxOutQuery =
458+
Text.unlines
459+
[ "ALTER TABLE \"collateral_tx_out\""
460+
, " ADD COLUMN \"address_id\" INT8 NOT NULL,"
461+
, " DROP COLUMN \"address\","
462+
, " DROP COLUMN \"address_has_script\","
463+
, " DROP COLUMN \"payment_cred\""
445464
]
446465

447466
createAddressTableQuery =

cardano-db/test/Test/IO/Cardano/Db/Util.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ assertBool msg bool =
3636
deleteAllBlocks :: MonadIO m => ReaderT SqlBackend m ()
3737
deleteAllBlocks = do
3838
mblkId <- queryMinBlock
39-
whenJust mblkId $ \(blkId, epochN) -> deleteBlocksForTests TxOutCore blkId epochN
39+
whenJust mblkId $ uncurry (deleteBlocksForTests TxOutCore)
4040

4141
dummyUTCTime :: UTCTime
4242
dummyUTCTime = UTCTime (ModifiedJulianDay 0) 0

doc/command-line-options

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### Command Line Options
2+
3+
- **General Options:**
4+
- `--config FILEPATH`: Path to the db-sync node config file
5+
- `--socket-path FILEPATH`: Path to a cardano-node socket
6+
- `--state-dir FILEPATH`: The directory for persisting ledger state.
7+
- `--schema-dir FILEPATH`: The directory containing the migrations.
8+
- `--pg-pass-env ENV`: Alternative env variable to use, defaults to `PGPASSFILE` env variable.
9+
- `--disable-epoch`: Makes epoch table remain empty.
10+
- `--skip-fix`: Disables the db-sync fix procedure for the wrong datum and redeemer_data bytes.
11+
- `--force-indexes`: Forces the Index creation at the start of db-sync. Normally they're created later.
12+
- `--fix-only`: Runs only the db-sync fix procedure for the wrong datum, redeemer_data, and plutus script bytes and exits.
13+
- `--disable-cache`: Disables the db-sync caches. Reduces memory usage but it takes longer to sync.
14+
- `--rollback-to-slot SLOTNO`: Force a rollback to the specified slot, if the given slot doesn't exist it will use the next greater slot.
15+
- `--disable-in-out`: Disables the `tx_in` and `tx_out` table.
16+
17+
- **Deprecated Options (for historical reference only):**
18+
- For more details, refer to [Configuration Documentation](https://github.com/IntersectMBO/cardano-db-sync/blob/master/doc/configuration.md)
19+
- `--disable-offline-data`
20+
- `--disable-ledger`
21+
- `--dont-use-ledger`
22+
- `--keep-tx-metadata`
23+
- `--disable-shelley`
24+
- `--disable-multiassets`
25+
- `--disable-metadata`
26+
- `--disable-plutus-extra`
27+
- `--disable-gov`
28+
- `--disable-offchain-pool-data`
29+
- `--force-tx-in`
30+
- `--disable-all`
31+
- `--full`
32+
- `--only-utxo`
33+
- `--only-gov`
34+
- `--consumed-tx-out`
35+
- `--prune-tx-out`
36+
- `--bootstrap-tx-out`

0 commit comments

Comments
 (0)