Skip to content

Commit 8b95488

Browse files
committed
Add migrations and document
1 parent 55c436a commit 8b95488

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

cardano-db-sync/src/Cardano/DbSync/OffChain.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ fetchOffChainVoteData _tracer manager time oVoteWorkQ =
284284
, DB.offChainVoteDataJson = sovaJson sVoteData
285285
, DB.offChainVoteDataVotingAnchorId = oVoteWqReferenceId oVoteWorkQ
286286
, DB.offChainVoteDataWarning = sovaWarning sVoteData
287+
, DB.offChainVoteDataIsValid = Nothing
287288
}
288289
authorsF ocvdId = map (mkAuthor ocvdId) $ Vote.getAuthors offChainData
289290
referencesF ocvdId = map (mkReference ocvdId) $ mListToList $ Vote.references minimalBody
@@ -305,6 +306,7 @@ fetchOffChainVoteData _tracer manager time oVoteWorkQ =
305306
, DB.offChainVoteAuthorWitnessAlgorithm = Vote.witnessAlgorithm $ Vote.witness au
306307
, DB.offChainVoteAuthorPublicKey = Vote.publicKey $ Vote.witness au
307308
, DB.offChainVoteAuthorSignature = Vote.signature $ Vote.witness au
309+
, DB.offChainVoteAuthorWarning = Just "Failed to validate this signature" -- TODO: Conway
308310
}
309311

310312
mkReference ocvdId ref =

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ share
686686
json Text sqltype=jsonb
687687
bytes ByteString sqltype=bytea
688688
warning Text Maybe
689+
isValid Bool Maybe
689690
UniqueOffChainVoteData votingAnchorId hash
690691
deriving Show
691692

@@ -695,6 +696,7 @@ share
695696
witnessAlgorithm Text
696697
publicKey Text
697698
signature Text
699+
warning Text Maybe
698700

699701
OffChainVoteReference
700702
offChainVoteDataId OffChainVoteDataId noreference
@@ -1322,9 +1324,45 @@ schemaDocs =
13221324
\ decribed in CIP-100. New in 13.2-Conway."
13231325
OffChainVoteDataVotingAnchorId # "The VotingAnchor table index this offchain data refers."
13241326
OffChainVoteDataHash # "The hash of the offchain data."
1327+
OffChainVoteDataLanguage # "The langauge described in the context of the metadata. Described in CIP-100. New in 13.3-Conway."
1328+
OffChainVoteDataComment # "The title of the metadata. Described in CIP-108. New in 13.3-Conway."
1329+
OffChainVoteDataAbstract # "The abstract of the metadata. Described in CIP-108. New in 13.3-Conway."
1330+
OffChainVoteDataMotivation # "The motivation of the metadata. Described in CIP-108. New in 13.3-Conway."
1331+
OffChainVoteDataRationale # "The rationale of the metadata. Described in CIP-108. New in 13.3-Conway."
13251332
OffChainVoteDataJson # "The payload as JSON."
13261333
OffChainVoteDataBytes # "The raw bytes of the payload."
13271334
OffChainVoteDataWarning # "A warning that occured while validating the metadata."
1335+
OffChainVoteDataIsValid
1336+
# "False if the data is found invalid. db-sync leaves this field null \
1337+
\since it normally populates off_chain_vote_fetch_error for invalid data. \
1338+
\It can be used manually to mark some metadata invalid by clients."
1339+
1340+
OffChainVoteAuthor --^ do
1341+
"The table with offchain metadata authors, as decribed in CIP-100. New in 13.3-Conway."
1342+
OffChainVoteAuthorOffChainVoteDataId # "The OffChainVoteData table index this offchain data refers."
1343+
OffChainVoteAuthorName # "The name of the author."
1344+
OffChainVoteAuthorWitnessAlgorithm # "The witness algorithm used by the author."
1345+
OffChainVoteAuthorPublicKey # "The public key used by the author."
1346+
OffChainVoteAuthorSignature # "The signature of the author."
1347+
OffChainVoteAuthorWarning # "A warning related to verifying this metadata."
1348+
1349+
OffChainVoteReference --^ do
1350+
"The table with offchain metadata references, as decribed in CIP-100. New in 13.3-Conway."
1351+
OffChainVoteReferenceOffChainVoteDataId # "The OffChainVoteData table index this entry refers."
1352+
OffChainVoteReferenceLabel # "The label of this vote reference."
1353+
OffChainVoteReferenceUri # "The uri of this vote reference."
1354+
OffChainVoteReferenceHashDigest
1355+
# "The hash digest of this vote reference, as described in CIP-108. \
1356+
\This only appears for governance action metadata."
1357+
OffChainVoteReferenceHashAlgorithm
1358+
# "The hash algorithm of this vote reference, as described in CIP-108. \
1359+
\This only appears for governance action metadata."
1360+
1361+
OffChainVoteExternalUpdate --^ do
1362+
"The table with offchain metadata external updates, as decribed in CIP-100. New in 13.3-Conway."
1363+
OffChainVoteExternalUpdateOffChainVoteDataId # "The OffChainVoteData table index this entry refers."
1364+
OffChainVoteExternalUpdateTitle # "The title of this external update."
1365+
OffChainVoteExternalUpdateUri # "The uri of this external update."
13281366

13291367
OffChainVoteFetchError --^ do
13301368
"Errors while fetching or validating offchain Voting Anchor metadata. New in 13.2-Conway."

schema/migration-1-0013-20240318.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Hand written migration to create the custom types with 'DOMAIN' statements.
2+
3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
5+
DECLARE
6+
next_version int;
7+
8+
BEGIN
9+
SELECT stage_one + 1 INTO next_version FROM "schema_version";
10+
IF next_version = 13 THEN
11+
12+
CREATE TYPE anchorType AS ENUM ('gov_action', 'other');
13+
14+
UPDATE "schema_version" SET stage_one = next_version;
15+
RAISE NOTICE 'DB has been migrated to stage_one version %', next_version;
16+
END IF;
17+
END;
18+
19+
$$ LANGUAGE plpgsql;
20+
21+
SELECT migrate();
22+
23+
DROP FUNCTION migrate();

schema/migration-2-0036-20240318.sql

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 = 36 THEN
9+
EXECUTE 'ALTER TABLE "voting_anchor" ADD COLUMN "type" anchorType NOT NULL' ;
10+
EXECUTE 'ALTER TABLE "voting_anchor" DROP CONSTRAINT "unique_voting_anchor"' ;
11+
EXECUTE 'ALTER TABLE "voting_anchor" ADD CONSTRAINT "unique_voting_anchor" UNIQUE("data_hash","url","type")' ;
12+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "language" VARCHAR NOT NULL' ;
13+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "comment" VARCHAR NULL' ;
14+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "title" VARCHAR NULL' ;
15+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "abstract" VARCHAR NULL' ;
16+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "motivation" VARCHAR NULL' ;
17+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "rationale" VARCHAR NULL' ;
18+
EXECUTE 'ALTER TABLE "off_chain_vote_data" ADD COLUMN "is_valid" BOOLEAN NULL' ;
19+
EXECUTE 'CREATe TABLE "off_chain_vote_author"("id" SERIAL8 PRIMARY KEY UNIQUE,"off_chain_vote_data_id" INT8 NOT NULL,"name" VARCHAR NULL,"witness_algorithm" VARCHAR NOT NULL,"public_key" VARCHAR NOT NULL,"signature" VARCHAR NOT NULL,"warning" VARCHAR NULL)' ;
20+
EXECUTE 'CREATe TABLE "off_chain_vote_reference"("id" SERIAL8 PRIMARY KEY UNIQUE,"off_chain_vote_data_id" INT8 NOT NULL,"label" VARCHAR NOT NULL,"uri" VARCHAR NOT NULL,"hash_digest" VARCHAR NULL,"hash_algorithm" VARCHAR NULL)' ;
21+
EXECUTE 'CREATe TABLE "off_chain_vote_external_update"("id" SERIAL8 PRIMARY KEY UNIQUE,"off_chain_vote_data_id" INT8 NOT NULL,"title" VARCHAR NOT NULL,"uri" VARCHAR NOT NULL)' ;
22+
-- Hand written SQL statements can be added here.
23+
UPDATE schema_version SET stage_two = next_version ;
24+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
25+
END IF ;
26+
END ;
27+
$$ LANGUAGE plpgsql ;
28+
29+
SELECT migrate() ;
30+
31+
DROP FUNCTION migrate() ;

0 commit comments

Comments
 (0)