Skip to content

Commit

Permalink
Merge pull request #667 from input-output-hk/erikd/issue-664
Browse files Browse the repository at this point in the history
db: Fix uniqueness constraint on CollateralTxIn table
  • Loading branch information
erikd authored Jun 23, 2021
2 parents 3bc3fc7 + a4425d3 commit 3cd1117
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cardano-db/src/Cardano/Db/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ share
txInId TxId OnDeleteCascade -- The transaction where this is used as an input.
txOutId TxId OnDeleteCascade -- The transaction where this was created as an output.
txOutIndex Word16 sqltype=txindex
UniqueColTxin txOutId txOutIndex
UniqueColTxin txInId

-- A table containing metadata about the chain. There will probably only ever be one
-- row in this table.
Expand Down
20 changes: 20 additions & 0 deletions schema/migration-2-0008-20210623.sql
Original file line number Diff line number Diff line change
@@ -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 = 8 THEN
EXECUTE 'ALTER TABLE "collateral_tx_in" DROP CONSTRAINT "unique_col_txin"' ;
EXECUTE 'ALTER TABLE "collateral_tx_in" ADD CONSTRAINT "unique_col_txin" UNIQUE("tx_in_id")' ;
-- 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 3cd1117

Please sign in to comment.