diff --git a/catalyst-gateway/event-db/Earthfile b/catalyst-gateway/event-db/Earthfile index 663059199a4..6aaef36cf77 100644 --- a/catalyst-gateway/event-db/Earthfile +++ b/catalyst-gateway/event-db/Earthfile @@ -13,6 +13,8 @@ builder: --sqlfluff_cfg=./../../+repo-config/repo/.sqlfluff COPY ./../../+repo-config-2/repo/.sqlfluff . + COPY setup-db.sql /sql/ + COPY --dir json_schemas . # check if the sqlfiles are properly formatted and pass lint quality checks. # CI target : true @@ -29,20 +31,13 @@ format: DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:fix/postgres-builders+FORMAT --src=$(echo ${PWD}/../../) -# build an event db docker image. +# build - an event db docker image. # CI target : true -# Arguments: -# * tag: docker image `tag`. -# * with_historic_data: add historic data from the `historic_data` dir (default `true`). -# * with_test_data: add test data from the `test_data` dir (default `true`). build: - ARG with_historic_data=true - ARG with_test_data=true - ARG tag="latest" - - FROM +builder --with_historic_data=$with_historic_data --with_test_data=$with_test_data + FROM +builder - DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:fix/postgres-builders+BUILD --tag=$tag --image_name=event-db + DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:fix/postgres-builders+BUILD --image_name=event-db + DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:fix/postgres-builders+DOCS --image_name=event-db # test the event db database schema # CI target : true diff --git a/catalyst-gateway/event-db/diagrams.json b/catalyst-gateway/event-db/diagrams.json new file mode 100644 index 00000000000..3101afbf157 --- /dev/null +++ b/catalyst-gateway/event-db/diagrams.json @@ -0,0 +1,16 @@ +{ + "name": "Catalyst Gateway - Event DB", + "all_schema": { + "comments": true, + "included_tables": [], + "excluded_tables": [ + "refinery_schema_history" + ], + "column_description_wrap": 50, + "table_description_wrap": 120 + }, + "full_schema": { + "title": "Full Schema", + "comments": false + } +} \ No newline at end of file diff --git a/catalyst-gateway/event-db/migrations/V1__config_tables.sql b/catalyst-gateway/event-db/migrations/V1__config_tables.sql index 8d1842dad75..fc22306e2a6 100644 --- a/catalyst-gateway/event-db/migrations/V1__config_tables.sql +++ b/catalyst-gateway/event-db/migrations/V1__config_tables.sql @@ -1,6 +1,8 @@ -- Catalyst Voices Database - Configuration Data -- sqlfluff:dialect:postgres +-- Title : Configuration Data + -- Configuration Tables -- ------------------------------------------------------------------------------------------------- @@ -120,15 +122,15 @@ at the app level to allow for querying groups of data.'; -- * This will be removed in the future. -- Add the Initial Schemas for configuration. -INSERT INTO json_schema_type (id, type, name, schema) -VALUES -( - '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.json')), - '62d614c0-97a7-41ec-a976-91294b8f4384', -- Fix the Schema ID so that it is consistent. - 'config', - 'registration', - (SELECT jsonb FROM PG_READ_FILE('../json_schemas/config/registration.json')) -); +--INSERT INTO json_schema_type (id, type, name, schema) +--VALUES +--( +-- 'd899cd44-3513-487b-ab46-fdca662a724d', -- Fix the Schema ID so that it is consistent. +-- 'config', +-- 'dbsync', +-- (SELECT PG_READ_FILE('../json_schemas/config/dbsync.json'))::JSONB), ( +-- '62d614c0-97a7-41ec-a976-91294b8f4384', -- Fix the Schema ID so that it is consistent. +-- 'config', +-- 'registration', +-- (SELECT PG_READ_FILE('../json_schemas/config/registration.json'))::JSONB +--); diff --git a/catalyst-gateway/event-db/migrations/V2__event_tables.sql b/catalyst-gateway/event-db/migrations/V2__event_tables.sql index d79d03bab22..e8ef96a3b70 100644 --- a/catalyst-gateway/event-db/migrations/V2__event_tables.sql +++ b/catalyst-gateway/event-db/migrations/V2__event_tables.sql @@ -1,6 +1,8 @@ -- Catalyst Voices Database - Event Data -- sqlfluff:dialect:postgres +-- Title : Event Data + -- `id` mapping. -- * `id` is a UUID, in the past it was an auto incrementing value. -- * it is changed to a UUID so that the data can be generated independently and it is more friendly @@ -50,42 +52,42 @@ COMMENT ON COLUMN event_type.data_schema IS -- Run as required after migrations. -- Add Event Schemas to the known schema types. -INSERT INTO json_schema_type_names (id) -VALUES -('event_description'), -- Event Description schemas -('event_data'); -- Event Data Schemas +-- INSERT INTO json_schema_type_names (id) +-- VALUES +-- ('event_description'), -- Event Description schemas +-- ('event_data'); -- Event Data Schemas -- Add the Initial Schemas for events. -INSERT INTO json_schema_type (id, type, name, schema) -VALUES -( - 'd899cd44-3513-487b-ab46-fdca662a724d', -- From the schema file. - 'event_description', - 'multiline_text', - ( - SELECT jsonb - FROM PG_READ_FILE('../json_schemas/event/description/multiline_text.json') - ) -), -( - '9c5df318-fa9a-4310-80fa-490f46d1cc43', -- From the schema file. - 'event_data', - 'catalyst_v1', - ( - SELECT jsonb - FROM PG_READ_FILE('../json_schemas/event/description/catalyst_v1.json') - ) -); +-- INSERT INTO json_schema_type (id, type, name, schema) +-- VALUES +--( +-- 'd899cd44-3513-487b-ab46-fdca662a724d', -- From the schema file. +-- 'event_description', +-- 'multiline_text', +-- ( +-- SELECT jsonb +-- FROM PG_READ_FILE('../json_schemas/event/description/multiline_text.json') +-- ) +--), +--( +-- '9c5df318-fa9a-4310-80fa-490f46d1cc43', -- From the schema file. +-- 'event_data', +-- 'catalyst_v1', +-- ( +-- SELECT jsonb +-- FROM PG_READ_FILE('../json_schemas/event/description/catalyst_v1.json') +-- ) +--); -- Define a Catalyst V1 Event. -INSERT INTO event_type (name, description_schema, data_schema) -VALUES -( - 'Catalyst V1', - 'd899cd44-3513-487b-ab46-fdca662a724d', - '9c5df318-fa9a-4310-80fa-490f46d1cc43' -); +--INSERT INTO event_type (name, description_schema, data_schema) +--VALUES +--( +-- 'Catalyst V1', +-- 'd899cd44-3513-487b-ab46-fdca662a724d', +-- '9c5df318-fa9a-4310-80fa-490f46d1cc43' +--); -- ------------------------------------------------------------------------------------------------- diff --git a/catalyst-gateway/event-db/migrations/V3__objective_tables.sql b/catalyst-gateway/event-db/migrations/V3__objective_tables.sql index 128ab3116bb..f24de876399 100644 --- a/catalyst-gateway/event-db/migrations/V3__objective_tables.sql +++ b/catalyst-gateway/event-db/migrations/V3__objective_tables.sql @@ -1,5 +1,7 @@ -- Catalyst Event Database +-- Title: Objective Tables + -- objective types table - Defines all currently known objectives types. CREATE TABLE objective_category ( @@ -68,12 +70,12 @@ VALUES CREATE TABLE goal ( id SERIAL PRIMARY KEY, - event_id INTEGER NOT NULL, + event_id UUID NOT NULL, idx INTEGER NOT NULL, name VARCHAR NOT NULL, - FOREIGN KEY (event_id) REFERENCES event (row_id) ON DELETE CASCADE + FOREIGN KEY (event_id) REFERENCES event (id) ON DELETE CASCADE ); CREATE UNIQUE INDEX goal_index ON goal (event_id, idx); @@ -94,7 +96,7 @@ CREATE TABLE objective row_id SERIAL PRIMARY KEY, id INTEGER NOT NULL, - event INTEGER NOT NULL, + event UUID NOT NULL, category TEXT NOT NULL, title TEXT NOT NULL, @@ -108,7 +110,7 @@ CREATE TABLE objective extra JSONB, - FOREIGN KEY (event) REFERENCES event (row_id) ON DELETE CASCADE, + FOREIGN KEY (event) REFERENCES event (id) ON DELETE CASCADE, FOREIGN KEY (category) REFERENCES objective_category (name) ON DELETE CASCADE, FOREIGN KEY (rewards_currency) REFERENCES currency (name) ON DELETE CASCADE, FOREIGN KEY (vote_options) REFERENCES vote_options (id) ON DELETE CASCADE diff --git a/catalyst-gateway/event-db/migrations/V4__proposal_tables.sql b/catalyst-gateway/event-db/migrations/V4__proposal_tables.sql index a9674f7c737..d53ee814a88 100644 --- a/catalyst-gateway/event-db/migrations/V4__proposal_tables.sql +++ b/catalyst-gateway/event-db/migrations/V4__proposal_tables.sql @@ -1,5 +1,7 @@ -- Catalyst Event Database +-- Title : Proposals + -- Proposals Table CREATE TABLE proposal @@ -23,10 +25,10 @@ CREATE TABLE proposal proposer_relevant_experience TEXT NOT NULL, bb_proposal_id BYTEA, - FOREIGN KEY (objective) REFERENCES objective (row_id) ON DELETE CASCADE, - FOREIGN KEY (bb_vote_options) REFERENCES vote_options ( - objective - ) ON DELETE CASCADE + FOREIGN KEY (objective) REFERENCES objective (row_id) ON DELETE CASCADE + --FOREIGN KEY (bb_vote_options) REFERENCES vote_options ( + -- objective + --) ON DELETE CASCADE ); CREATE UNIQUE INDEX proposal_index ON proposal (id, objective); @@ -75,9 +77,9 @@ CREATE TABLE reviewer_level ( total_reward_pct <= 100 AND total_reward_pct >= 0 ), - event_id INTEGER NOT NULL, + event_id UUID NOT NULL, - FOREIGN KEY (event_id) REFERENCES event (row_id) ON DELETE CASCADE + FOREIGN KEY (event_id) REFERENCES event (id) ON DELETE CASCADE ); COMMENT ON TABLE reviewer_level IS diff --git a/catalyst-gateway/event-db/migrations/V5__vote_plan.sql b/catalyst-gateway/event-db/migrations/V5__vote_plan.sql index 9502f73f30d..20d1b6120ec 100644 --- a/catalyst-gateway/event-db/migrations/V5__vote_plan.sql +++ b/catalyst-gateway/event-db/migrations/V5__vote_plan.sql @@ -1,5 +1,7 @@ -- Catalyst Event Database +-- Title : Vote Plan + -- Vote Plan Categories CREATE TABLE voteplan_category diff --git a/catalyst-gateway/event-db/migrations/V6__registration.sql b/catalyst-gateway/event-db/migrations/V6__registration.sql index 1af5a4e4c22..76ecab6cc02 100644 --- a/catalyst-gateway/event-db/migrations/V6__registration.sql +++ b/catalyst-gateway/event-db/migrations/V6__registration.sql @@ -1,6 +1,8 @@ -- Catalyst Voices Database - Role Registration Data -- sqlfluff:dialect:postgres +-- Title : Role Registration Data + -- cspell: words utxo stxo -- Configuration Tables @@ -27,7 +29,7 @@ CREATE TABLE cardano_update_state ( CREATE INDEX cardano_update_state_idx ON cardano_update_state (id, network); -COMMENT ON INDEX cardano_update_state_time_idx IS +COMMENT ON INDEX cardano_update_state_idx IS 'Index to allow us to efficiently get find an update state record by its id. This index can be used to find the latest state record for a particular network.'; @@ -137,16 +139,27 @@ CREATE TABLE cardano_utxo ( stake_credential BYTEA NOT NULL, + spent_slot_no BIGINT NULL, + spent_tx_id BIGINT NULL, + PRIMARY KEY (tx_id, index, network), - FOREIGN KEY (slot_no, network) REFERENCES slot_index (slot_no, network) + FOREIGN KEY (slot_no, network) REFERENCES slot_index (slot_no, network), + FOREIGN KEY (spent_slot_no, network) REFERENCES slot_index (slot_no, network) + ); -CREATE INDEX cardano_utxo_stake_credential_idx ON utxo ( +CREATE INDEX cardano_utxo_stake_credential_idx ON cardano_utxo ( stake_credential, slot_no ); COMMENT ON INDEX cardano_utxo_stake_credential_idx IS 'Index to allow us to efficiently lookup a set of UTXOs by stake credential relative to a slot_no.'; +CREATE INDEX cardano_stxo_slot_idx ON cardano_utxo (spent_slot_no, network); + +COMMENT ON INDEX cardano_stxo_slot_idx IS +'Index to allow us to efficiently lookup a set of Spent TX Outputs by slot_no.'; + + COMMENT ON TABLE cardano_utxo IS 'This table holds all UTXOs for any transaction which is tied to a stake address. This data allows us to calculate staked ADA at any particular instant in time.'; @@ -164,51 +177,14 @@ COMMENT ON COLUMN cardano_utxo.slot_no IS 'The slot number the UTXO appeared in.'; COMMENT ON COLUMN cardano_utxo.stake_credential IS 'The stake credential of the address which owns the UTXO.'; - - --- ------------------------------------------------------------------------------------------------- - --- STXO Table -- Spent TX Outputs. --- Populated with this query from db-sync --- SELECT tx_out_id as tx_id, tx_out_index as index, tx_in.id as spent_tx_id, slot_no, time FROM tx_in --- INNER JOIN tx ON tx_in.tx_in_id = tx.id --- INNER JOIN block ON tx.block_id = block.id; --- network needs to be supplied, as dbsync only has a single database per network. -CREATE TABLE cardano_stxo ( - tx_id BIGINT NOT NULL, - index INTEGER NOT NULL, - network TEXT NOT NULL, - - spent_tx_id BIGINT NOT NULL, - spent_slot_no BIGINT NOT NULL, - - PRIMARY KEY (tx_id, index, network), - FOREIGN KEY (tx_id, index, network) REFERENCES utxo (tx_id, index, network), - FOREIGN KEY (spent_slot_no, network) REFERENCES slot_index (slot_no, network) -); - -CREATE INDEX cardano_stxo_slot_idx ON stxo (spent_slot_no, network); - -COMMENT ON INDEX cardano_stxo_slot_idx IS -'Index to allow us to efficiently lookup a set of Spent TX Outputs by slot_no.'; - -COMMENT ON TABLE cardano_stxo IS -'This table holds all Spent TX Outputs. -This data allows us to calculate staked ADA at any particular instant in time.'; - -COMMENT ON COLUMN cardano_stxo.tx_id IS -'The ID of the transaction containing the original UTXO.'; -COMMENT ON COLUMN cardano_stxo.index IS -'The index of the UTXO within the original transaction.'; -COMMENT ON COLUMN cardano_stxo.network IS -'The Cardano network for the original UTXO.'; -COMMENT ON COLUMN cardano_stxo.spent_tx_id IS +COMMENT ON COLUMN cardano_utxo.spent_tx_id IS 'The ID of the transaction which Spent the TX Output.'; -COMMENT ON COLUMN cardano_stxo.spent_slot_no IS +COMMENT ON COLUMN cardano_utxo.spent_slot_no IS 'The slot number the TX Output was spent in. This lets us determine when the TX Output was spent, so we can calculate staked ada at a particular slot.'; + -- ------------------------------------------------------------------------------------------------- -- Rewards Table -- Earned Rewards @@ -232,7 +208,7 @@ CREATE TABLE cardano_reward ( FOREIGN KEY (slot_no, network) REFERENCES slot_index (slot_no, network) ); -CREATE INDEX cardano_rewards_stake_credential_idx ON cardano_rewards ( +CREATE INDEX cardano_rewards_stake_credential_idx ON cardano_reward ( stake_credential, slot_no ); @@ -338,14 +314,7 @@ CREATE INDEX cardano_voter_registration_voting_key_idx ON cardano_voter_registra COMMENT ON INDEX cardano_voter_registration_voting_key_idx IS 'Optimize lookups for "public_voting_key" or "public_voting_key"+"nonce" or "public_voting_key"+"nonce"+"valid".'; - -CREATE INDEX cardano_voter_registration_voting_key_idx ON cardano_voter_registration ( - public_voting_key, nonce, valid -); -COMMENT ON INDEX cardano_voter_registration_voting_key_idx IS -'Optimize lookups for "public_voting_key" or "public_voting_key"+"nonce" or "public_voting_key"+"nonce"+"valid".'; - -COMMENT ON TABLE cardano_voter_registrations IS +COMMENT ON TABLE cardano_voter_registration IS 'All CIP15/36 Voter Registrations that are on-chain. This tables stores all found registrations, even if they are invalid, or have been rolled back.'; diff --git a/catalyst-gateway/event-db/migrations/V7__vote_tables.sql b/catalyst-gateway/event-db/migrations/V7__vote_tables.sql index ce92bbe57ac..8ef0f96e97a 100644 --- a/catalyst-gateway/event-db/migrations/V7__vote_tables.sql +++ b/catalyst-gateway/event-db/migrations/V7__vote_tables.sql @@ -1,4 +1,6 @@ --- Catalyst Event Database - VIT-SS Compatibility +-- Catalyst Event Database - Vote Storage + +-- Title : Vote Storage -- vote storage (replicates on-chain data for easy querying) @@ -7,13 +9,12 @@ CREATE TABLE ballot ( objective INTEGER NOT NULL, proposal INTEGER NULL, - voter INTEGER NOT NULL, + voter BYTEA NOT NULL, fragment_id TEXT NOT NULL, cast_at TIMESTAMP NOT NULL, choice SMALLINT NULL, raw_fragment BYTEA NOT NULL, - FOREIGN KEY (voter) REFERENCES voter (row_id) ON DELETE CASCADE, FOREIGN KEY (objective) REFERENCES objective (row_id) ON DELETE CASCADE, FOREIGN KEY (proposal) REFERENCES proposal (row_id) ON DELETE CASCADE ); @@ -23,7 +24,7 @@ CREATE UNIQUE INDEX ballot_objective_idx ON ballot (objective, fragment_id); COMMENT ON TABLE ballot IS 'All Ballots cast on an event.'; COMMENT ON COLUMN ballot.fragment_id IS 'Unique ID of this Ballot'; -COMMENT ON COLUMN ballot.voter IS 'Reference to the Voter who cast the ballot'; +COMMENT ON COLUMN ballot.voter IS 'Voters Voting Key who cast the ballot'; COMMENT ON COLUMN ballot.objective IS 'Reference to the Objective the ballot was for.'; COMMENT ON COLUMN ballot.proposal IS 'Reference to the Proposal the ballot was for. diff --git a/catalyst-gateway/event-db/migrations/V8__catalyst_automation.sql b/catalyst-gateway/event-db/migrations/V8__catalyst_automation.sql index 2e26ccc4db7..53c42e4fa82 100644 --- a/catalyst-gateway/event-db/migrations/V8__catalyst_automation.sql +++ b/catalyst-gateway/event-db/migrations/V8__catalyst_automation.sql @@ -1,17 +1,19 @@ -- Catalyst Event Database +-- Title : Catalyst Automation + -- Voting Nodes Table - Defines nodes in the network -- This table is looked up by hostname and event CREATE TABLE voting_node ( hostname TEXT NOT NULL, - event INTEGER NOT NULL, + event UUID NOT NULL, pubkey TEXT NOT NULL, seckey TEXT NOT NULL, netkey TEXT NOT NULL, PRIMARY KEY (hostname, event), - FOREIGN KEY (event) REFERENCES event (row_id) ON DELETE CASCADE + FOREIGN KEY (event) REFERENCES event (id) ON DELETE CASCADE ); COMMENT ON TABLE voting_node IS @@ -30,14 +32,14 @@ COMMENT ON COLUMN voting_node.netkey IS 'Encrypted Ed25519 secret key for the no CREATE TABLE tally_committee ( row_id SERIAL PRIMARY KEY, - event INTEGER NOT NULL UNIQUE, + event UUID NOT NULL UNIQUE, committee_pk TEXT NOT NULL, committee_id TEXT NOT NULL, member_crs TEXT, election_key TEXT, - FOREIGN KEY (event) REFERENCES event (row_id) ON DELETE CASCADE + FOREIGN KEY (event) REFERENCES event (id) ON DELETE CASCADE ); COMMENT ON TABLE tally_committee IS 'Table for storing data about the tally committee per voting event.'; diff --git a/catalyst-gateway/event-db/migrations/V9__moderation_stage.sql b/catalyst-gateway/event-db/migrations/V9__moderation_stage.sql index 770c9e0a5b6..954fd9be072 100644 --- a/catalyst-gateway/event-db/migrations/V9__moderation_stage.sql +++ b/catalyst-gateway/event-db/migrations/V9__moderation_stage.sql @@ -1,5 +1,7 @@ -- Catalyst Event Database +-- Title : Moderation Stage Data + -- ModerationAllocation - Defines the relationship between users and proposals_reviews -- to describe the allocation of moderations that needs to be done. diff --git a/catalyst-gateway/event-db/seed/historic_data/README.md b/catalyst-gateway/event-db/old_seed/historic_data/README.md similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/README.md rename to catalyst-gateway/event-db/old_seed/historic_data/README.md diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_0.sql b/catalyst-gateway/event-db/old_seed/historic_data/fund_0.sql similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_0.sql rename to catalyst-gateway/event-db/old_seed/historic_data/fund_0.sql diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_1.sql b/catalyst-gateway/event-db/old_seed/historic_data/fund_1.sql similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_1.sql rename to catalyst-gateway/event-db/old_seed/historic_data/fund_1.sql diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_2/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_2/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_2/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_2/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_2/encrypt_fund2_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_2/encrypt_fund2_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_2/encrypt_fund2_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_2/encrypt_fund2_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_2/fund2_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_2/fund2_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_2/fund2_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_2/fund2_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_2/genesis.yaml b/catalyst-gateway/event-db/old_seed/historic_data/fund_2/genesis.yaml similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_2/genesis.yaml rename to catalyst-gateway/event-db/old_seed/historic_data/fund_2/genesis.yaml diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_2/mk_fund2_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_2/mk_fund2_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_2/mk_fund2_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_2/mk_fund2_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_3/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_3/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_3/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_3/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_3/encrypt_fund3_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_3/encrypt_fund3_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_3/encrypt_fund3_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_3/encrypt_fund3_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_3/fund3_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_3/fund3_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_3/fund3_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_3/fund3_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_3/mk_fund3_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_3/mk_fund3_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_3/mk_fund3_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_3/mk_fund3_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_4/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_4/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_4/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_4/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_4/encrypt_fund4_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_4/encrypt_fund4_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_4/encrypt_fund4_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_4/encrypt_fund4_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_4/fund4_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_4/fund4_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_4/fund4_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_4/fund4_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_4/mk_fund4_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_4/mk_fund4_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_4/mk_fund4_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_4/mk_fund4_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_5/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_5/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_5/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_5/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_5/encrypt_fund5_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_5/encrypt_fund5_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_5/encrypt_fund5_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_5/encrypt_fund5_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_5/fund5_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_5/fund5_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_5/fund5_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_5/fund5_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_5/mk_fund5_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_5/mk_fund5_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_5/mk_fund5_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_5/mk_fund5_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_5/snapshot.json b/catalyst-gateway/event-db/old_seed/historic_data/fund_5/snapshot.json similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_5/snapshot.json rename to catalyst-gateway/event-db/old_seed/historic_data/fund_5/snapshot.json diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_6/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_6/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_6/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_6/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_6/encrypt_fund6_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_6/encrypt_fund6_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_6/encrypt_fund6_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_6/encrypt_fund6_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_6/fund6_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_6/fund6_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_6/fund6_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_6/fund6_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_6/mk_fund6_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_6/mk_fund6_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_6/mk_fund6_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_6/mk_fund6_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_7/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_7/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_7/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_7/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_7/encrypt_fund7_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_7/encrypt_fund7_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_7/encrypt_fund7_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_7/encrypt_fund7_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_7/fund7_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_7/fund7_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_7/fund7_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_7/fund7_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_7/mk_fund7_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_7/mk_fund7_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_7/mk_fund7_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_7/mk_fund7_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_8/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_8/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_8/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_8/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_8/encrypt_fund8_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_8/encrypt_fund8_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_8/encrypt_fund8_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_8/encrypt_fund8_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_8/fund8_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_8/fund8_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_8/fund8_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_8/fund8_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_8/mk_fund8_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_8/mk_fund8_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_8/mk_fund8_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_8/mk_fund8_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_9/block0.bin b/catalyst-gateway/event-db/old_seed/historic_data/fund_9/block0.bin similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_9/block0.bin rename to catalyst-gateway/event-db/old_seed/historic_data/fund_9/block0.bin diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_9/encrypt_fund9_sensitive_data.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_9/encrypt_fund9_sensitive_data.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_9/encrypt_fund9_sensitive_data.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_9/encrypt_fund9_sensitive_data.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_9/fund9_database_encrypted.sqlite3 b/catalyst-gateway/event-db/old_seed/historic_data/fund_9/fund9_database_encrypted.sqlite3 similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_9/fund9_database_encrypted.sqlite3 rename to catalyst-gateway/event-db/old_seed/historic_data/fund_9/fund9_database_encrypted.sqlite3 diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_9/mk_fund9_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_9/mk_fund9_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_9/mk_fund9_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_9/mk_fund9_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/fund_9/mk_fund9_voteplan_sql.py b/catalyst-gateway/event-db/old_seed/historic_data/fund_9/mk_fund9_voteplan_sql.py similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/fund_9/mk_fund9_voteplan_sql.py rename to catalyst-gateway/event-db/old_seed/historic_data/fund_9/mk_fund9_voteplan_sql.py diff --git a/catalyst-gateway/event-db/seed/historic_data/sensitive-data-pub.pem b/catalyst-gateway/event-db/old_seed/historic_data/sensitive-data-pub.pem similarity index 100% rename from catalyst-gateway/event-db/seed/historic_data/sensitive-data-pub.pem rename to catalyst-gateway/event-db/old_seed/historic_data/sensitive-data-pub.pem diff --git a/catalyst-gateway/event-db/seed/stage_data/Readme.md b/catalyst-gateway/event-db/old_seed/stage_data/Readme.md similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/Readme.md rename to catalyst-gateway/event-db/old_seed/stage_data/Readme.md diff --git a/catalyst-gateway/event-db/seed/stage_data/dev/.gitignore b/catalyst-gateway/event-db/old_seed/stage_data/dev/.gitignore similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/dev/.gitignore rename to catalyst-gateway/event-db/old_seed/stage_data/dev/.gitignore diff --git a/catalyst-gateway/event-db/seed/stage_data/dev/00001_testfund_event.sql b/catalyst-gateway/event-db/old_seed/stage_data/dev/00001_testfund_event.sql similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/dev/00001_testfund_event.sql rename to catalyst-gateway/event-db/old_seed/stage_data/dev/00001_testfund_event.sql diff --git a/catalyst-gateway/event-db/seed/stage_data/dev/00002_testfund_ideascale_params.sql b/catalyst-gateway/event-db/old_seed/stage_data/dev/00002_testfund_ideascale_params.sql similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/dev/00002_testfund_ideascale_params.sql rename to catalyst-gateway/event-db/old_seed/stage_data/dev/00002_testfund_ideascale_params.sql diff --git a/catalyst-gateway/event-db/seed/stage_data/local/.gitignore b/catalyst-gateway/event-db/old_seed/stage_data/local/.gitignore similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/local/.gitignore rename to catalyst-gateway/event-db/old_seed/stage_data/local/.gitignore diff --git a/catalyst-gateway/event-db/seed/stage_data/preprod/.gitignore b/catalyst-gateway/event-db/old_seed/stage_data/preprod/.gitignore similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/preprod/.gitignore rename to catalyst-gateway/event-db/old_seed/stage_data/preprod/.gitignore diff --git a/catalyst-gateway/event-db/seed/stage_data/prod/.gitignore b/catalyst-gateway/event-db/old_seed/stage_data/prod/.gitignore similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/prod/.gitignore rename to catalyst-gateway/event-db/old_seed/stage_data/prod/.gitignore diff --git a/catalyst-gateway/event-db/seed/stage_data/testnet/.gitignore b/catalyst-gateway/event-db/old_seed/stage_data/testnet/.gitignore similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/testnet/.gitignore rename to catalyst-gateway/event-db/old_seed/stage_data/testnet/.gitignore diff --git a/catalyst-gateway/event-db/seed/stage_data/testnet/00001_fund10_event.sql b/catalyst-gateway/event-db/old_seed/stage_data/testnet/00001_fund10_event.sql similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/testnet/00001_fund10_event.sql rename to catalyst-gateway/event-db/old_seed/stage_data/testnet/00001_fund10_event.sql diff --git a/catalyst-gateway/event-db/seed/stage_data/testnet/00002_fund10_ideascale_params.sql b/catalyst-gateway/event-db/old_seed/stage_data/testnet/00002_fund10_ideascale_params.sql similarity index 100% rename from catalyst-gateway/event-db/seed/stage_data/testnet/00002_fund10_ideascale_params.sql rename to catalyst-gateway/event-db/old_seed/stage_data/testnet/00002_fund10_ideascale_params.sql diff --git a/catalyst-gateway/event-db/seed/test_data/01_event_table.sql b/catalyst-gateway/event-db/old_seed/test_data/01_event_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/01_event_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/01_event_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/02_snapshot_table.sql b/catalyst-gateway/event-db/old_seed/test_data/02_snapshot_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/02_snapshot_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/02_snapshot_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/03_voter_table.sql b/catalyst-gateway/event-db/old_seed/test_data/03_voter_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/03_voter_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/03_voter_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/04_contribution_table.sql b/catalyst-gateway/event-db/old_seed/test_data/04_contribution_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/04_contribution_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/04_contribution_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/05_goal_table.sql b/catalyst-gateway/event-db/old_seed/test_data/05_goal_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/05_goal_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/05_goal_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/06_objective_table.sql b/catalyst-gateway/event-db/old_seed/test_data/06_objective_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/06_objective_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/06_objective_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/07_voteplan_table.sql b/catalyst-gateway/event-db/old_seed/test_data/07_voteplan_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/07_voteplan_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/07_voteplan_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/08_proposal_table.sql b/catalyst-gateway/event-db/old_seed/test_data/08_proposal_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/08_proposal_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/08_proposal_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/09_proposal_review_table.sql b/catalyst-gateway/event-db/old_seed/test_data/09_proposal_review_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/09_proposal_review_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/09_proposal_review_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/10_review_rating_table.sql b/catalyst-gateway/event-db/old_seed/test_data/10_review_rating_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/10_review_rating_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/10_review_rating_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/11_objective_review_metric_table.sql b/catalyst-gateway/event-db/old_seed/test_data/11_objective_review_metric_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/11_objective_review_metric_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/11_objective_review_metric_table.sql diff --git a/catalyst-gateway/event-db/seed/test_data/12_proposal_voteplan_table.sql b/catalyst-gateway/event-db/old_seed/test_data/12_proposal_voteplan_table.sql similarity index 100% rename from catalyst-gateway/event-db/seed/test_data/12_proposal_voteplan_table.sql rename to catalyst-gateway/event-db/old_seed/test_data/12_proposal_voteplan_table.sql diff --git a/catalyst-gateway/event-db/setup-db.sql b/catalyst-gateway/event-db/setup-db.sql new file mode 100644 index 00000000000..07c4beeb85b --- /dev/null +++ b/catalyst-gateway/event-db/setup-db.sql @@ -0,0 +1,40 @@ +-- Initialize the Project Catalyst Event Database. + +-- cspell: words psql noqa + +-- This script requires a number of variables to be set. +-- They will default if not set externally. +-- These variables can be set on the "psql" command line. +-- Passwords may optionally be set by ENV Vars. +-- This script requires "psql" is run inside a POSIX compliant shell. + +-- VARIABLES: + +-- DISPLAY ALL VARIABLES +\echo VARIABLES: +\echo -> dbName ................. = :dbName +\echo -> dbDescription .......... = :dbDescription +\echo -> dbUser ................. = :dbUser +\echo -> dbUserPw ............... = xxxx +\echo test test + +-- Cleanup if we already ran this before. +DROP DATABASE IF EXISTS :"dbName"; -- noqa: PRS +DROP USER IF EXISTS :"dbUser"; -- noqa: PRS + +-- Create the test user we will use with the local dev database. +CREATE USER :"dbUser" WITH PASSWORD :'dbUserPw'; -- noqa: PRS + +-- Privileges for this user/role. +ALTER DEFAULT PRIVILEGES GRANT EXECUTE ON FUNCTIONS TO public; + +ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO :"dbUser"; -- noqa: PRS + +GRANT EXECUTE ON FUNCTION PG_READ_FILE(TEXT, BIGINT, BIGINT, BOOLEAN) TO :"dbUser"; -- noqa: PRS + +-- Create the database. +CREATE DATABASE :"dbName" WITH OWNER :"dbUser"; -- noqa: PRS + +GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO :"dbUser"; -- noqa: PRS + +COMMENT ON DATABASE :"dbName" IS :'dbDescription'; -- noqa: PRS diff --git a/docs/Earthfile b/docs/Earthfile index 9b340158595..10863f30f1d 100644 --- a/docs/Earthfile +++ b/docs/Earthfile @@ -11,6 +11,10 @@ src: # Now copy into that any artifacts we pull from the builds. COPY --dir ../+repo-docs/repo /docs/includes + # Copy docs we build in the postgres example. + COPY --dir ../catalyst-gateway/event-db+build/docs src/appendix/examples/built_docs/postgresql + + # Build the docs here. docs: FROM +src