Skip to content

Commit fd17ef9

Browse files
committed
db-sync: Fix DB types for txInvalidBefore/txInvalidHereafter
The schema definition was incorrectly making these two fields Word32 and they need to be Word64. Closes: #430
1 parent 13462b7 commit fd17ef9

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ insertTx tracer env blkId epochNo blockIndex tx = do
166166
, DB.txFee = DB.DbLovelace (fromIntegral . unCoin $ Generic.txFees tx)
167167
, DB.txDeposit = fromIntegral (inSum + withdrawalSum) - fromIntegral (outSum + fees)
168168
, DB.txSize = Generic.txSize tx
169-
, DB.txInvalidBefore = unSlotNo <$> Generic.txInvalidBefore tx
170-
, DB.txInvalidHereafter = unSlotNo <$> Generic.txInvalidHereafter tx
169+
, DB.txInvalidBefore = DbWord64 . unSlotNo <$> Generic.txInvalidBefore tx
170+
, DB.txInvalidHereafter = DbWord64 . unSlotNo <$> Generic.txInvalidHereafter tx
171171
}
172172

173173
-- Insert outputs for a transaction before inputs in case the inputs for this transaction

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ share
104104
deposit Int64 -- Needs to allow negaitve values.
105105
size Word64 sqltype=uinteger
106106

107-
invalidBefore Word64 Maybe sqltype=uinteger
108-
invalidHereafter Word64 Maybe sqltype=uinteger
107+
invalidBefore DbWord64 Maybe sqltype=word64type
108+
invalidHereafter DbWord64 Maybe sqltype=word64type
109109
UniqueTx hash
110+
deriving Show
110111

111112
StakeAddress -- Can be an address of a script hash
112113
hashRaw ByteString sqltype=addr29type

schema/migration-2-0004-20201109.sql renamed to schema/migration-2-0004-20201209.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ DECLARE
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
88
IF next_version = 4 THEN
9-
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "invalid_before" uinteger NULL' ;
10-
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "invalid_hereafter" uinteger NULL' ;
9+
EXECUTE 'ALTER TABLE "schema_version" ALTER COLUMN "id" TYPE INT8' ;
10+
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "invalid_before" word64type NULL' ;
11+
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "invalid_hereafter" word64type NULL' ;
1112
EXECUTE 'CREATe TABLE "ma_tx_mint"("id" SERIAL8 PRIMARY KEY UNIQUE,"policy" hash28type NOT NULL,"name" asset32type NOT NULL,"quantity" int65type NOT NULL,"tx_id" INT8 NOT NULL)' ;
1213
EXECUTE 'ALTER TABLE "ma_tx_mint" ADD CONSTRAINT "unique_ma_tx_mint" UNIQUE("policy","name","tx_id")' ;
13-
EXECUTE 'ALTER TABLE "ma_tx_mint" ADD CONSTRAINT "ma_tx_mint_tx_id_fkey" FOREIGN KEY("tx_id") REFERENCES "tx"("id")' ;
14+
EXECUTE 'ALTER TABLE "ma_tx_mint" ADD CONSTRAINT "ma_tx_mint_tx_id_fkey" FOREIGN KEY("tx_id") REFERENCES "tx"("id") ON DELETE RESTRICT ON UPDATE RESTRICT' ;
1415
EXECUTE 'CREATe TABLE "ma_tx_out"("id" SERIAL8 PRIMARY KEY UNIQUE,"policy" hash28type NOT NULL,"name" asset32type NOT NULL,"quantity" word64type NOT NULL,"tx_out_id" INT8 NOT NULL)' ;
1516
EXECUTE 'ALTER TABLE "ma_tx_out" ADD CONSTRAINT "unique_ma_tx_out" UNIQUE("policy","name","tx_out_id")' ;
16-
EXECUTE 'ALTER TABLE "ma_tx_out" ADD CONSTRAINT "ma_tx_out_tx_out_id_fkey" FOREIGN KEY("tx_out_id") REFERENCES "tx_out"("id")' ;
17+
EXECUTE 'ALTER TABLE "ma_tx_out" ADD CONSTRAINT "ma_tx_out_tx_out_id_fkey" FOREIGN KEY("tx_out_id") REFERENCES "tx_out"("id") ON DELETE RESTRICT ON UPDATE RESTRICT' ;
1718
-- Hand written SQL statements can be added here.
1819
UPDATE schema_version SET stage_two = next_version ;
1920
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;

0 commit comments

Comments
 (0)