Skip to content

Commit

Permalink
Merge pull request #701 from input-output-hk/erikd/PoolMetadataRef-un…
Browse files Browse the repository at this point in the history
…ique

schema: Fix the uniqueness constraint on PoolMetadataRef
  • Loading branch information
erikd committed Jul 20, 2021
2 parents 2110565 + 012fa2d commit 88e26c8
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
Expand Up @@ -195,7 +195,7 @@ share
url Text
hash ByteString sqltype=hash32type
registeredTxId TxId OnDeleteCascade -- Only used for rollback.
UniquePoolMetadataRef poolId hash
UniquePoolMetadataRef poolId url hash

PoolUpdate
hashId PoolHashId OnDeleteCascade
Expand Down
20 changes: 20 additions & 0 deletions schema/migration-2-0011-20210719.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 = 11 THEN
EXECUTE 'ALTER TABLE "pool_metadata_ref" DROP CONSTRAINT "unique_pool_metadata_ref"' ;
EXECUTE 'ALTER TABLE "pool_metadata_ref" ADD CONSTRAINT "unique_pool_metadata_ref" UNIQUE("pool_id","url","hash")' ;
-- 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 88e26c8

Please sign in to comment.