Skip to content

Commit

Permalink
feat(gateway): Gateway DB defined up to event tables. WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenj committed Nov 21, 2023
1 parent 00b46fd commit 5bafe1c
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 149 deletions.
1 change: 1 addition & 0 deletions .config/dictionaries/project.dic
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ rustc
saibatizoku
seckey
slotno
sqlfluff
stevenj
tacho
thiserror
Expand Down
2 changes: 2 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[sqlfluff]

# cspell: words templater cpus ctes capitalisation organisation

# Supported dialects https://docs.sqlfluff.com/en/stable/dialects.html
# Or run 'sqlfluff dialects'
# We do not set a global SQL Dialect, so that we can support multiple
Expand Down
18 changes: 18 additions & 0 deletions catalyst-gateway/event-db/json_schemas/.cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"enabled": true,
"language": "en,en-US",
"overrides": [
{
"filename": "**/*.json",
"allowCompoundWords": true,
"words": [
"sshuser",
"cexplorer",
"Cardano",
"jormungandr"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$comment": "Custom URI schema: catalyst_schema://<uuid>/<group>/<name>",
"$id": "catalyst_schema://d899cd44-3513-487b-ab46-fdca662a724d/config/dbsync",
"title": "DBSync Connection",
"type": "object",
"properties": {
// Optional SSH tunnel needed to communicate to the DBSync Postgres database.
"ssh": {
"$comment": "Optional SSH tunnel needed to communicate to the DBSync Postgres database.",
"type": "object",
"properties": {
"sshHost": {
Expand Down Expand Up @@ -41,8 +43,8 @@
"sshUser"
]
},
// DBSync connection
"conn": {
"$comment": "DBSync connection",
"type": "object",
"properties": {
"host": {
Expand Down Expand Up @@ -83,7 +85,7 @@
],
"description": "The Cardano network to connect to.",
"default": "mainnet"
},
}
},
"required": [
"password"
Expand Down
165 changes: 165 additions & 0 deletions catalyst-gateway/event-db/json_schemas/event/data/catalyst_v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$comment": "Custom URI schema: catalyst_schema://<uuid>/<group>/<name>",
"$id": "catalyst_schema://9c5df318-fa9a-4310-80fa-490f46d1cc43/event_data/catalyst_v1",
"title": "Catalyst V1 Event",
"description": "Traditional Project Catalyst Event Configuration",
"type": "object",
"properties": {
"timeline": {
"$comment": "allows additionalProperties so the schema can be extended in a backwards compatible way in the future",
"type": "object",
"description": "The timeline of the various stages of the event.",
"additionalProperties": true,
"properties": {
"registration_deadline": {
"description": "The deadline for registrations.\nThe Time (UTC) Registrations are taken from the Cardano blockchain.\nRegistrations after this date are not valid for voting on the event.\nNULL = Not yet defined or Not Applicable.'When the Voting power snapshot is set for.",
"type": "string",
"format": "date-time"
},
"snapshot_stable": {
"description": "The Time (UTC) Registrations taken from Cardano blockchain are considered stable.\nThis is not the Time of the Registration Snapshot.\nThis is the time after which the registration snapshot will be stable.\nNULL = Not yet defined or Not Applicable.",
"type": "string",
"format": "date-time"
},
"insight_sharing_start": {
"description": "TODO.\nNULL = Not yet defined.",
"type": "string",
"format": "date-time"
},
"proposal_submission_start": {
"description": "The Time (UTC) proposals can start to be submitted for the event.\nNULL = Not yet defined, or Not applicable.",
"type": "string",
"format": "date-time"
},
"refine_proposals_start": {
"description": "TODO.\nNULL = Not yet defined.",
"type": "string",
"format": "date-time"
},
"finalize_proposals_start": {
"description": "The Time (UTC) when all proposals must be finalized by.\nNULL = Not yet defined, or Not applicable.",
"type": "string",
"format": "date-time"
},
"proposal_assessment_start": {
"description": "The Time (UTC) when PA Assessors can start assessing proposals.\nNULL = Not yet defined, or Not applicable.",
"type": "string",
"format": "date-time"
},
"assessment_qa_start": {
"description": "The Time (UTC) when vPA Assessors can start assessing assessments.\nNULL = Not yet defined, or Not applicable.",
"type": "string",
"format": "date-time"
},
"voting_start": {
"description": "The earliest time that registered wallets with sufficient voting power can place votes in the event.\nNULL = Not yet defined.\nTypically this is aligned with Backing Start of the event.",
"type": "string",
"format": "date-time"
},
"voting_end": {
"description": "The latest time that registered wallets with sufficient voting power can place votes in the event.\nNULL = Not yet defined.\nTypically aligned with backing End of the Event.",
"type": "string",
"format": "date-time"
},
"tallying_end": {
"description": "The latest time that tallying the event can complete by.\nNULL = Not yet defined.",
"type": "string",
"format": "date-time"
}
}
},
"registration": {
"$comment": "Allows additionalProperties so the schema can be extended in a backwards compatible way in the future.",
"type": "object",
"description": "The options which control the individual selection power of each participant in the event.",
"additionalProperties": true,
"properties": {
"stake_participation_threshold": {
"description": "The Minimum number of Lovelace needed to be staked at the time of snapshot, to be eligible to participate.\nNULL = Not yet defined.",
"type": "number",
"minimum": 0
},
"max_stake_percent": {
"description": "The Maximum Percentage of all registered staked ADA which can be used to participate in the event.",
"type": "number",
"minimum": 0,
"maximum": 100,
"default": 100
},
"network": {
"description": "The Cardano network the event allows registrations from. Can be one or more networks.",
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"mainnet",
"preprod",
"testnet"
]
},
"default": [
"mainnet"
]
}
}
},
"rewards": {
"$comment": "Allows additionalProperties so the schema can be extended in a backwards compatible way in the future.",
"type": "object",
"description": "The options which control the reward distribution of the event.",
"additionalProperties": true,
"properties": {
"review": {
"description": "The total reward pool (in lovelace) to pay for community reviewers for their valid reviews of the proposals assigned to this event.",
"type": "integer",
"format": "int64",
"minimum": 0
}
}
},
"tally": {
"$comment": "Allows additionalProperties so the schema can be extended in a backwards compatible way in the future.",
"type": "object",
"description": "The options which control the results tally of the event.",
"additionalProperties": true,
"properties": {
"committee_size": {
"description": "The Size of the Tally committee.\n0 = No Committee, and all votes are therefore public.",
"type": "integer",
"format": "",
"minimum": 0,
"default": 0
},
"committee_threshold": {
"description": "The Minimum Size of the Tally committee to perform the Tally.\nMust be <= `committee_size`.\n0 is equivalent to ALL Committee members are required.",
"type": "integer",
"minimum": 0,
"default": 0
}
}
},
"jormungandr": {
"$comment": "Allows additionalProperties so the schema can be extended in a backwards compatible way in the future.",
"type": "object",
"description": "The Events Jormungandr configuration.",
"additionalProperties": true,
"properties": {
"block0": {
"description": "The BASE64 encoded copy of Block 0 used to start the Blockchain.\nIf not defined then the Blockchain is not yet configured.",
"type": "string",
"contentEncoding": "base64",
"contentMediaType": "application/octet-stream"
},
"block0_hash": {
"description": "The BASE64 encoded hash of Block 0 used to start the Blockchain.\nIf not defined then the Blockchain is not yet configured.",
"type": "string",
"contentEncoding": "base64",
"contentMediaType": "application/octet-stream"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$comment": "Custom URI schema: catalyst_schema://<uuid>/<group>/<name>",
"$id": "catalyst_schema://d8f79cbc-9777-4fee-bbbe-397ce412a75c/event_description/multiline_text",
"title": "Simple Catalyst Event Description",
"description": "A simple multi-line description used for a Catalyst type event.",
"type": "string",
"contentEncoding": "utf-8",
"contentMediaType": "text/plain",
"format": "multiline"
}
23 changes: 15 additions & 8 deletions catalyst-gateway/event-db/migrations/V1__config_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ CREATE TABLE json_schema_type_names (
id TEXT PRIMARY KEY
);

COMMENT ON TABLE json_schema_type_names IS 'All known Json Schema Types.';
COMMENT ON TABLE json_schema_type_names IS 'All known Json Schema Type Names.';

-- Known Schema Types are inserted when the Table which uses that type is created.
-- Known Schema Type Names are inserted when the Table which uses that type is created.


-- -------------------------------------------------------------------------------------------------
Expand All @@ -35,7 +35,7 @@ COMMENT ON TABLE json_schema_type_names IS 'All known Json Schema Types.';
-- Json Schemas used to validate the contents of JSONB fields in this database.
-- Catalyst Event Database
CREATE TABLE json_schema_type (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
id UUID PRIMARY KEY,
type TEXT NOT NULL,
name TEXT NOT NULL,
schema JSONB NOT NULL,
Expand All @@ -50,13 +50,20 @@ COMMENT ON TABLE json_schema_type IS
'Library of defined json schemas used to validate JSONB field contents.';

COMMENT ON COLUMN json_schema_type.id IS
'Synthetic Unique ID for each json_schema_type (UUIDv4).';
'Synthetic Unique ID for each json_schema_type (UUIDv4).
Must match $id URI inside the schema.';
COMMENT ON COLUMN json_schema_type.type IS
'The type of the json schema type.
eg. "Event Description"';
eg. "event"
Must match $id URI inside the schema.';
COMMENT ON COLUMN json_schema_type.name IS
'The name of the json schema type.
eg. "Catalyst V1"';
eg. "catalyst_v1"
Must match $id URI inside the schema.';

-- Known Schema Types are inserted when the Table which uses that type is created.
-- Or can be added by migrations as the database evolves.
-- They could also be added outside of the schema setup by inserting directly into the database.

-- -------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -113,8 +120,8 @@ VALUES
INSERT INTO json_schema_type (id, type, name, schema)
VALUES
(
'd899cd44-3513-487b-ab46-fdca662a724d',
'd899cd44-3513-487b-ab46-fdca662a724d', -- Fix the Schema ID so that it is consistent.
'config',
'dbsync',
(SELECT jsonb FROM pg_read_file('../json_schemas/config/dbsync_connection.json'))
(SELECT jsonb FROM pg_read_file('../json_schemas/config/dbsync.json'))
);
Loading

0 comments on commit 5bafe1c

Please sign in to comment.