Skip to content

Commit 9801165

Browse files
committed
Tidy schema files
1 parent d798db3 commit 9801165

17 files changed

+70
-185
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,13 @@ share
564564
CommitteeRegistration
565565
txId TxId noreference
566566
certIndex Word16
567-
coldKey ByteString sqltype=bytea
568-
hotKey ByteString sqltype=bytea
567+
coldKey ByteString sqltype=hash28type
568+
hotKey ByteString sqltype=hash28type
569569

570570
CommitteeDeRegistration
571571
txId TxId noreference
572572
certIndex Word16
573-
coldKey ByteString sqltype=bytea
573+
coldKey ByteString sqltype=hash28type
574574
votingAnchorId VotingAnchorId Maybe noreference
575575

576576
DrepRegistration

schema/migration-2-0030-20231017.sql renamed to schema/migration-2-0026-20231017.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DECLARE
55
next_version int ;
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8-
IF next_version = 30 THEN
8+
IF next_version = 26 THEN
99
EXECUTE 'ALTER TABLE "pool_offline_data" RENAME TO "off_chain_pool_data"' ;
1010
EXECUTE 'ALTER SEQUENCE "pool_offline_data_id_seq" RENAME TO "off_chain_pool_data_id_seq"' ;
1111
EXECUTE 'ALTER TABLE "off_chain_pool_data" RENAME CONSTRAINT "unique_pool_offline_data" TO "unique_off_chain_pool_data"' ;

schema/migration-2-0026-20230713.sql renamed to schema/migration-2-0027-20230713.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DECLARE
55
next_version int ;
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8-
IF next_version = 26 THEN
8+
IF next_version = 27 THEN
99
EXECUTE 'CREATe TABLE "epoch_stake_progress"("id" SERIAL8 PRIMARY KEY UNIQUE,"epoch_no" word31type NOT NULL,"completed" BOOLEAN NOT NULL)' ;
1010
EXECUTE 'ALTER TABLE "epoch_stake_progress" ADD CONSTRAINT "unique_epoch_stake_progress" UNIQUE("epoch_no")' ;
1111
EXECUTE 'CREATe TABLE "extra_migrations"("id" SERIAL8 PRIMARY KEY UNIQUE,"token" VARCHAR NOT NULL,"description" VARCHAR NULL)' ;

schema/migration-2-0027-20230815.sql

Lines changed: 0 additions & 35 deletions
This file was deleted.

schema/migration-2-0031-20231102.sql renamed to schema/migration-2-0028-20240117.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ DECLARE
55
next_version int ;
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8-
IF next_version = 31 THEN
9-
EXECUTE 'ALTER TABLE "committee_de_registration" ADD COLUMN "voting_anchor_id" INT8 NULL' ;
8+
IF next_version = 28 THEN
9+
EXECUTE 'CREATe TABLE instant_reward AS TABLE reward WITH NO DATA';
10+
EXECUTE 'INSERT INTO instant_reward (SELECT * FROM reward WHERE pool_id IS NULL)';
1011
-- Hand written SQL statements can be added here.
1112
UPDATE schema_version SET stage_two = next_version ;
1213
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;

schema/migration-2-0029-20231009.sql

Lines changed: 0 additions & 21 deletions
This file was deleted.

schema/migration-2-0038-20240117.sql renamed to schema/migration-2-0029-20240117.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DECLARE
55
next_version int ;
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8-
IF next_version = 38 THEN
8+
IF next_version = 29 THEN
99
EXECUTE 'ALTER TABLE "instant_reward" ALTER COLUMN "id" SET NOT NULL' ;
1010
EXECUTE 'ALTER TABLE "instant_reward" DROP COLUMN id';
1111
EXECUTE 'ALTER TABLE "instant_reward" ALTER COLUMN "addr_id" SET NOT NULL' ;

schema/migration-2-0035-20240108.sql renamed to schema/migration-2-0030-20240108.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DECLARE
55
next_version int ;
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8-
IF next_version = 35 THEN
8+
IF next_version = 30 THEN
99
EXECUTE 'alter domain addr29type drop constraint addr29type_check' ;
1010
EXECUTE 'alter domain asset32type drop constraint asset32type_check' ;
1111
EXECUTE 'alter domain hash28type drop constraint hash28type_check' ;

schema/migration-2-0036-20240117.sql renamed to schema/migration-2-0031-20240117.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ DECLARE
55
next_version int ;
66
BEGIN
77
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8-
IF next_version = 36 THEN
8+
IF next_version = 31 THEN
99
EXECUTE 'ALTER TABLE "tx_out" DROP COLUMN "address_raw"' ;
1010

1111
EXECUTE 'ALTER TABLE "collateral_tx_out" DROP COLUMN "address_raw"' ;

schema/migration-2-0032-20230815.sql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Persistent generated migration.
2+
3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
DECLARE
5+
next_version int ;
6+
BEGIN
7+
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8+
IF next_version = 32 THEN
9+
EXECUTE 'ALTER TABLE "reverse_index" ALTER COLUMN "min_ids" SET NOT NULL' ;
10+
EXECUTE 'ALTER TABLE "param_proposal" ALTER COLUMN "epoch_no" DROP NOT NULL' ;
11+
EXECUTE 'ALTER TABLE "param_proposal" ALTER COLUMN "key" DROP NOT NULL' ;
12+
EXECUTE 'CREATe TABLE "drep_hash"("id" SERIAL8 PRIMARY KEY UNIQUE,"raw" hash28type NULL,"view" VARCHAR NOT NULL,"has_script" BOOLEAN NOT NULL)' ;
13+
EXECUTE 'ALTER TABLE "drep_hash" ADD CONSTRAINT "unique_drep_hash" UNIQUE("raw")' ;
14+
EXECUTE 'CREATe TABLE "delegation_vote"("id" SERIAL8 PRIMARY KEY UNIQUE,"addr_id" INT8 NOT NULL,"cert_index" INT4 NOT NULL,"drep_hash_id" INT8 NOT NULL,"tx_id" INT8 NOT NULL,"redeemer_id" INT8 NULL)' ;
15+
EXECUTE 'CREATe TABLE "committee_registration"("id" SERIAL8 PRIMARY KEY UNIQUE,"tx_id" INT8 NOT NULL,"cert_index" INT4 NOT NULL,"cold_key" hash28type NOT NULL,"hot_key" hash28type NOT NULL)' ;
16+
EXECUTE 'CREATe TABLE "committee_de_registration"("id" SERIAL8 PRIMARY KEY UNIQUE,"tx_id" INT8 NOT NULL,"cert_index" INT4 NOT NULL,"cold_key" hash28type NOT NULL)' ;
17+
EXECUTE 'ALTER TABLE "committee_de_registration" ADD COLUMN "voting_anchor_id" INT8 NULL' ;
18+
EXECUTE 'CREATe TABLE "drep_registration"("id" SERIAL8 PRIMARY KEY UNIQUE,"tx_id" INT8 NOT NULL,"cert_index" INT4 NOT NULL,"deposit" INT8 NULL,"drep_hash_id" INT8 NOT NULL)' ;
19+
EXECUTE 'ALTER TABLE "drep_registration" ADD COLUMN "voting_anchor_id" INT8 NULL' ;
20+
EXECUTE 'CREATe TABLE "voting_anchor"("id" SERIAL8 PRIMARY KEY UNIQUE,"tx_id" INT8 NOT NULL,"url" varchar NOT NULL,"data_hash" BYTEA NOT NULL)' ;
21+
EXECUTE 'ALTER TABLE "voting_anchor" ADD CONSTRAINT "unique_voting_anchor" UNIQUE("data_hash","url")' ;
22+
EXECUTE 'CREATe TABLE "gov_action_proposal"("id" SERIAL8 PRIMARY KEY UNIQUE,"tx_id" INT8 NOT NULL,"index" INT8 NOT NULL,"prev_gov_action_proposal" INT8 NULL,"deposit" lovelace NOT NULL,"return_address" INT8 NOT NULL,"expiration" word31type NULL,"voting_anchor_id" INT8 NULL,"type" govactiontype NOT NULL,"description" VARCHAR NOT NULL,"param_proposal" INT8 NULL,"ratified_epoch" word31type NULL,"enacted_epoch" word31type NULL,"dropped_epoch" word31type NULL,"expired_epoch" word31type NULL)' ;
23+
EXECUTE 'CREATe TABLE "treasury_withdrawal"("id" SERIAL8 PRIMARY KEY UNIQUE,"gov_action_proposal_id" INT8 NOT NULL,"stake_address_id" INT8 NOT NULL,"amount" lovelace NOT NULL)' ;
24+
EXECUTE 'CREATe TABLE "new_committee"("id" SERIAL8 PRIMARY KEY UNIQUE,"gov_action_proposal_id" INT8 NOT NULL,"quorum" DOUBLE PRECISION NOT NULL,"members" VARCHAR NOT NULL)' ;
25+
EXECUTE 'ALTER TABLE "new_committee" ADD COLUMN "deleted_members" VARCHAR NOT NULL' ;
26+
EXECUTE 'ALTER TABLE "new_committee" ADD COLUMN "added_members" VARCHAR NOT NULL' ;
27+
EXECUTE 'ALTER TABLE "new_committee" DROP COLUMN "members"' ;
28+
EXECUTE 'ALTER TABLE "new_committee" ADD COLUMN "quorum_nominator" INT8 NOT NULL' ;
29+
EXECUTE 'ALTER TABLE "new_committee" ADD COLUMN "quorum_denominator" INT8 NOT NULL' ;
30+
EXECUTE 'ALTER TABLE "new_committee" DROP COLUMN "quorum"' ;
31+
EXECUTE 'CREATe TABLE "voting_procedure"("id" SERIAL8 PRIMARY KEY UNIQUE,"tx_id" INT8 NOT NULL,"index" INT4 NOT NULL,"gov_action_proposal_id" INT8 NOT NULL,"voter_role" voterrole NOT NULL,"committee_voter" BYTEA NULL,"drep_voter" INT8 NULL,"pool_voter" INT8 NULL,"vote" vote NOT NULL,"voting_anchor_id" INT8 NULL)' ;
32+
EXECUTE 'CREATe TABLE "drep_distr"("id" SERIAL8 PRIMARY KEY UNIQUE,"hash_id" INT8 NOT NULL,"amount" INT8 NOT NULL,"epoch_no" word31type NOT NULL)' ;
33+
EXECUTE 'ALTER TABLE "drep_distr" ADD COLUMN "active_until" word31type NULL' ;
34+
EXECUTE 'ALTER TABLE "drep_distr" ADD CONSTRAINT "unique_drep_distr" UNIQUE("hash_id","epoch_no")' ;
35+
EXECUTE 'CREATe TABLE "off_chain_vote_data"("id" SERIAL8 PRIMARY KEY UNIQUE,"voting_anchor_id" INT8 NOT NULL,"hash" BYTEA NOT NULL,"json" jsonb NOT NULL,"bytes" bytea NOT NULL)' ;
36+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD CONSTRAINT "unique_off_chain_vote_data" UNIQUE("voting_anchor_id","hash")' ;
37+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "warning" VARCHAR NULL' ;
38+
EXECUTE 'CREATe TABLE "off_chain_vote_fetch_error"("id" SERIAL8 PRIMARY KEY UNIQUE,"voting_anchor_id" INT8 NOT NULL,"fetch_error" VARCHAR NOT NULL,"fetch_time" timestamp NOT NULL,"retry_count" word31type NOT NULL)' ;
39+
EXECUTE 'ALTER TABLE "off_chain_vote_fetch_error" ADD CONSTRAINT "unique_off_chain_vote_fetch_error" UNIQUE("voting_anchor_id","retry_count")' ;
40+
EXECUTE 'CREATe TABLE "constitution"("id" SERIAL8 PRIMARY KEY UNIQUE,"gov_action_proposal_id" INT8 NOT NULL,"voting_anchor_id" INT8 NOT NULL,"script_hash" hash28type NULL)' ;
41+
-- Hand written SQL statements can be added here.
42+
UPDATE schema_version SET stage_two = next_version ;
43+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
44+
END IF ;
45+
END ;
46+
$$ LANGUAGE plpgsql ;
47+
48+
SELECT migrate() ;
49+
50+
DROP FUNCTION migrate() ;

0 commit comments

Comments
 (0)