Skip to content

Commit

Permalink
Add ExUnits migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
kderme committed Jul 22, 2021
1 parent 274032f commit 9b0911f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cardano-db-sync/src/Cardano/DbSync/Era/Byron/Genesis.hs
Expand Up @@ -173,6 +173,8 @@ insertTxOuts blkId (address, value) = do
, DB.txInvalidHereafter = Nothing
, DB.txInvalidBefore = Nothing
, DB.txValidContract = True
, DB.txExUnitsNumber = 0
, DB.txExUnitsFees = DB.DbLovelace 0
}
void . DB.insertTxOut $
DB.TxOut
Expand Down
2 changes: 2 additions & 0 deletions cardano-db-sync/src/Cardano/DbSync/Era/Byron/Insert.hs
Expand Up @@ -195,6 +195,8 @@ insertTx tracer blkId tx blockIndex = do
, DB.txInvalidHereafter = Nothing
, DB.txInvalidBefore = Nothing
, DB.txValidContract = True
, DB.txExUnitsNumber = 0
, DB.txExUnitsFees = DB.DbLovelace 0
}

-- Insert outputs for a transaction before inputs in case the inputs for this transaction
Expand Down
2 changes: 2 additions & 0 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs
Expand Up @@ -186,6 +186,8 @@ insertTxOuts blkId (Shelley.TxIn txInId _, txOut) = do
, DB.txInvalidHereafter = Nothing
, DB.txInvalidBefore = Nothing
, DB.txValidContract = True
, DB.txExUnitsNumber = 0
, DB.txExUnitsFees = DB.DbLovelace 0
}
void . DB.insertTxOut $
DB.TxOut
Expand Down
2 changes: 2 additions & 0 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Expand Up @@ -203,6 +203,8 @@ insertTx tracer network lStateSnap blkId epochNo slotNo blockIndex tx = do
, DB.txInvalidBefore = DbWord64 . unSlotNo <$> Generic.txInvalidBefore tx
, DB.txInvalidHereafter = DbWord64 . unSlotNo <$> Generic.txInvalidHereafter tx
, DB.txValidContract = Generic.txValidContract tx
, DB.txExUnitsNumber = fromIntegral $ length $ Generic.txExUnits tx
, DB.txExUnitsFees = DB.DbLovelace (fromIntegral . unCoin $ Generic.txExUnitsFees tx)
}

-- Insert outputs for a transaction before inputs in case the inputs for this transaction
Expand Down
2 changes: 2 additions & 0 deletions cardano-db/src/Cardano/Db/Schema.hs
Expand Up @@ -109,6 +109,8 @@ share

invalidBefore DbWord64 Maybe sqltype=word64type
invalidHereafter DbWord64 Maybe sqltype=word64type
exUnitsNumber Word64 sqltype=uinteger
exUnitsFees DbLovelace sqltype=lovelace

validContract Bool -- False if the contract is invalid, True otherwise.
UniqueTx hash
Expand Down
20 changes: 20 additions & 0 deletions schema/migration-2-0012-20210722.sql
@@ -0,0 +1,20 @@
-- Persistent generated migration.

CREATE FUNCTION migrate() RETURNS void AS $$
DECLARE
next_version int ;
BEGIN
SELECT stage_two + 1 INTO next_version FROM schema_version ;
IF next_version = 12 THEN
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "ex_units_number" uinteger NOT NULL' ;
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "ex_units_fees" lovelace NOT NULL' ;
-- Hand written SQL statements can be added here.
UPDATE schema_version SET stage_two = next_version ;
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
END IF ;
END ;
$$ LANGUAGE plpgsql ;

SELECT migrate() ;

DROP FUNCTION migrate() ;

0 comments on commit 9b0911f

Please sign in to comment.