Skip to content

Commit 5624471

Browse files
committed
Add migrations for epoch_state, anchor and off_chain_data
1 parent aad96d0 commit 5624471

5 files changed

+69
-2
lines changed

schema/migration-2-0035-20240308.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ BEGIN
1616
EXECUTE 'ALTER TABLE "committee_registration" DROP COLUMN "hot_key"' ;
1717
EXECUTE 'ALTER TABLE "committee_de_registration" ADD COLUMN "cold_key_id" INT8 NOT NULL' ;
1818
EXECUTE 'ALTER TABLE "committee_de_registration" DROP COLUMN "cold_key"' ;
19-
EXECUTE 'CREATe TABLE "new_committee_info"("id" SERIAL8 PRIMARY KEY UNIQUE,"gov_action_proposal_id" INT8 NOT NULL,"quorum_numerator" INT8 NOT NULL,"quorum_denominator" INT8 NOT NULL)' ;
20-
EXECUTE 'CREATe TABLE "new_committee_member"("id" SERIAL8 PRIMARY KEY UNIQUE,"gov_action_proposal_id" INT8 NOT NULL,"committee_hash_id" INT8 NOT NULL,"expiration_epoch" word31type NOT NULL)' ;
2119
EXECUTE 'ALTER TABLE "voting_procedure" DROP COLUMN "committee_voter"';
2220
EXECUTE 'ALTER TABLE "voting_procedure" ADD COLUMN "committee_voter" INT8 NULL' ;
2321
-- Hand written SQL statements can be added here.

schema/migration-2-0041-20240530.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 = 41 THEN
9+
EXECUTE 'ALTER TABLE "voting_anchor" ADD COLUMN "block_id" INT8 NOT NULL' ;
10+
EXECUTE 'ALTER TABLE "voting_anchor" DROP COLUMN "tx_id"' ;
11+
EXECUTE 'ALTER TABLE "constitution" ALTER COLUMN "gov_action_proposal_id" DROP NOT NULL' ;
12+
EXECUTE 'CREATe TABLE "epoch_state"("id" SERIAL8 PRIMARY KEY UNIQUE,"committee_id" INT8 NULL,"no_confidence_id" INT8 NULL,"constitution_id" INT8 NULL,"epoch_no" word31type NOT NULL)' ;
13+
-- Hand written SQL statements can be added here.
14+
UPDATE schema_version SET stage_two = next_version ;
15+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
16+
END IF ;
17+
END ;
18+
$$ LANGUAGE plpgsql ;
19+
20+
SELECT migrate() ;
21+
22+
DROP FUNCTION migrate() ;

schema/migration-2-0042-20240602.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 = 42 THEN
9+
EXECUTE 'ALTER TABLE "off_chain_vote_data" DROP COLUMN "title"' ;
10+
EXECUTE 'ALTER TABLE "off_chain_vote_data" DROP COLUMN "abstract"' ;
11+
EXECUTE 'ALTER TABLE "off_chain_vote_data" DROP COLUMN "motivation"' ;
12+
EXECUTE 'ALTER TABLE "off_chain_vote_data" DROP COLUMN "rationale"' ;
13+
EXECUTE 'CREATe TABLE "off_chain_vote_gov_action_data"("id" SERIAL8 PRIMARY KEY UNIQUE,"off_chain_vote_data_id" INT8 NOT NULL,"title" VARCHAR NOT NULL,"abstract" VARCHAR NOT NULL,"motivation" VARCHAR NOT NULL,"rationale" VARCHAR NOT NULL)' ;
14+
EXECUTE 'CREATe TABLE "off_chain_vote_drep_data"("id" SERIAL8 PRIMARY KEY UNIQUE,"off_chain_vote_data_id" INT8 NOT NULL,"payment_address" VARCHAR NULL,"given_name" VARCHAR NOT NULL,"objectives" VARCHAR NULL,"motivations" VARCHAR NULL,"qualifications" VARCHAR NULL,"image_url" VARCHAR NULL,"image_hash" VARCHAR NULL)' ;
15+
-- Hand written SQL statements can be added here.
16+
UPDATE schema_version SET stage_two = next_version ;
17+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
18+
END IF ;
19+
END ;
20+
$$ LANGUAGE plpgsql ;
21+
22+
SELECT migrate() ;
23+
24+
DROP FUNCTION migrate() ;

schema/migration-2-0043-20240603.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 = 43 THEN
9+
EXECUTE 'CREATe TABLE "committee"("id" SERIAL8 PRIMARY KEY UNIQUE,"gov_action_proposal_id" INT8 NULL,"quorum_numerator" INT8 NOT NULL,"quorum_denominator" INT8 NOT NULL)' ;
10+
EXECUTE 'CREATe TABLE "committee_member"("id" SERIAL8 PRIMARY KEY UNIQUE,"committee_id" INT8 NOT NULL,"committee_hash_id" INT8 NOT NULL,"expiration_epoch" word31type NOT NULL)' ;
11+
EXECUTE 'ALTER TABLE "committee_member" ADD CONSTRAINT "committee_member_committee_id_fkey" FOREIGN KEY("committee_id") REFERENCES "committee"("id") ON DELETE RESTRICT ON UPDATE RESTRICT' ;
12+
-- Hand written SQL statements can be added here.
13+
UPDATE schema_version SET stage_two = next_version ;
14+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
15+
END IF ;
16+
END ;
17+
$$ LANGUAGE plpgsql ;
18+
19+
SELECT migrate() ;
20+
21+
DROP FUNCTION migrate() ;

schema/migration-3-0004-20240603.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
CREATE INDEX IF NOT EXISTS idx_committee_member_committee_id ON committee_member (committee_id);

0 commit comments

Comments
 (0)