@@ -137,7 +137,9 @@ runExtraMigrations trce txOutTableType blockNoDiff pcm = do
137
137
case (isConsumeTxOutPreviouslySet, pcmConsumedTxOut, pcmPruneTxOut) of
138
138
-- No Migration Needed
139
139
(False , False , False ) -> do
140
- liftIO $ logInfo trce " runExtraMigrations: No extra migration specified"
140
+ liftIO $ logInfo trce " runExtraMigrations: Running extra migration no_consumed_tx_out"
141
+ insertExtraMigration NoConsumeTxOut
142
+ migrateTxOut trce txOutTableType (Just migrationValues)
141
143
-- Already migrated
142
144
(True , True , False ) -> do
143
145
liftIO $ logInfo trce " runExtraMigrations: Extra migration consumed_tx_out already executed"
@@ -255,7 +257,12 @@ migrateTxOut trce txOutTableType mMvs = do
255
257
when (pcmPruneTxOut (pruneConsumeMigration mvs)) $ do
256
258
liftIO $ logInfo trce " migrateTxOut: adding prune contraint on tx_out table"
257
259
void createPruneConstraintTxOut
258
- migrateNextPageTxOut (Just trce) txOutTableType 0
260
+ if pcmConsumedTxOut (pruneConsumeMigration mvs)
261
+ then do
262
+ migrateNextPageTxOut (Just trce) txOutTableType 0
263
+ else do
264
+ liftIO $ logInfo trce " migrateTxOut: removing column consumed_by_tx from tx_out table"
265
+ void (dropColumnConsumedByTxOut trce)
259
266
260
267
migrateNextPageTxOut :: MonadIO m => Maybe (Trace IO Text ) -> TxOutTableType -> Word64 -> ReaderT SqlBackend m ()
261
268
migrateNextPageTxOut mTrce txOutTableType offst = do
@@ -415,6 +422,29 @@ createPruneConstraintTxOut = do
415
422
exceptHandler e =
416
423
liftIO $ throwIO (DBPruneConsumed $ show e)
417
424
425
+ dropColumnConsumedByTxOut ::
426
+ forall io .
427
+ (MonadBaseControl IO io , MonadIO io ) =>
428
+ Trace IO Text ->
429
+ ReaderT SqlBackend io ()
430
+ dropColumnConsumedByTxOut trace = do
431
+ handle exceptionHandler (rawExecute dropViewsQuery [] )
432
+ liftIO $ logInfo trace " dropColumnConsumedByTxOut: Dropped views"
433
+
434
+ handle exceptionHandler (rawExecute dropColumn [] )
435
+ liftIO $ logInfo trace " dropColumnConsumedByTxOut: Altered tx_out"
436
+ where
437
+ dropColumn = " ALTER TABLE tx_out DROP COLUMN IF EXISTS consumed_by_tx_id;"
438
+
439
+ dropViewsQuery =
440
+ Text. unlines
441
+ [ " DROP VIEW IF EXISTS utxo_byron_view;"
442
+ , " DROP VIEW IF EXISTS utxo_view;"
443
+ ]
444
+
445
+ exceptionHandler :: SqlError -> ReaderT SqlBackend io a
446
+ exceptionHandler = liftIO . throwIO . DBPruneConsumed . show
447
+
418
448
-- Be very mindfull that these queries can fail silently and make tests fail making it hard to know why.
419
449
-- To help mitigate this, logs are printed after each query is ran, so one can know where it stopped.
420
450
updateTxOutAndCreateAddress ::
0 commit comments