Skip to content

Commit

Permalink
db: Unify SQL types of epoch_stake.epoch_no and epoch.no
Browse files Browse the repository at this point in the history
These need to be the same SQL types for the Hasura code generation.
The fact that they were not the same type was a mistake.

Closes: #811
  • Loading branch information
erikd committed Sep 13, 2021
1 parent acb631f commit d03a88a
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 @@ -311,7 +311,7 @@ share
addrId StakeAddressId OnDeleteCascade
poolId PoolHashId OnDeleteCascade
amount DbLovelace sqltype=lovelace
epochNo Word64
epochNo Word64 sqltype=uinteger
UniqueStake epochNo addrId poolId

Treasury
Expand Down
20 changes: 20 additions & 0 deletions schema/migration-2-0024-20210913.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 = 24 THEN
EXECUTE 'ALTER TABLE "epoch_stake" ALTER COLUMN "epoch_no" TYPE uinteger' ;
EXECUTE 'ALTER TABLE "redeemer" ADD CONSTRAINT "redeemer_datum_id_fkey" FOREIGN KEY("datum_id") REFERENCES "datum"("id") ON DELETE CASCADE ON UPDATE RESTRICT' ;
-- 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 d03a88a

Please sign in to comment.