Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Stage specific data | NPG-7769 #486

Merged
merged 15 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ lefthook.yml
treefmt.toml

# local earthly Environments
local/
./local/
1 change: 1 addition & 0 deletions containers/event-db-migrations/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ docker:
COPY --dir ../../src/event-db+build/test_data ./test_data
END
COPY ../../src/event-db+build/refinery.toml .
COPY ../../src/event-db+build/stage_data ./stage_data

VOLUME /eventdb/tmp
COPY ./entry.sh .
Expand Down
16 changes: 16 additions & 0 deletions containers/event-db-migrations/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# DB_USER_PASSWORD - The password of the database user
# DB_SKIP_HISTORICAL_DATA - If set, historical data will not be added to the database (optional)
# DB_SKIP_TEST_DATA - If set, test data will not be added to the database (optional)
# DB_SKIP_STAGE_DATA - If set, stage specific data will not be added to the database (optional)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the potential to get confusing. What is the difference between the three data types now? Is any of it mutually exclusive? We might want to be more specific in the comments here, otherwise it's hard to discern when you would use which type of data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea. I think the readme is actually fine as is.

# ADMIN_ROLE_PASSWORD - The password of the cat_admin role for graphql
# ADMIN_USER_PASSWORD - The password of the admin user for graphql
# ANON_ROLE_PASSWORD - The password of the cat_anon role for graphql
Expand All @@ -31,6 +32,7 @@
# SKIP_GRAPHQL_INIT - If set, graphql will not be initialized (optional)
# DEBUG - If set, the script will print debug information (optional)
# DEBUG_SLEEP - If set, the script will sleep for the specified number of seconds (optional)
# STAGE - The stage being run. Currently only controls if stage specific data is applied to the DB (optional)
# ---------------------------------------------------------------
set +x
set -o errexit
Expand Down Expand Up @@ -145,6 +147,20 @@ if [[ -z "${DB_SKIP_HISTORICAL_DATA:-}" ]]; then
done < <(find ./historic_data -name '*.sql' -print0 | sort -z)
fi

# Add stage specific data to the DB when initialized.
if [[ -z "${DB_SKIP_STAGE_DATA:-}" ]]; then
if [[ -n "$STAGE" ]]; then
STAGE_DATA="./stage_data/$STAGE"
else
STAGE_DATA="./stage_data/local"
fi

while IFS= read -r -d '' file; do
echo "Adding stage specific data from $file"
psql -f "$file"
done < <(find "$STAGE_DATA" -name '*.sql' -print0 | sort -z)
fi

# Add test data
if [[ -z "${DB_SKIP_TEST_DATA:-}" ]]; then
while IFS= read -r -d '' file; do
Expand Down
4 changes: 3 additions & 1 deletion src/event-db/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ build:
COPY --dir migrations . # Copy the migrations directory to the working directory
COPY --dir historic_data . # Copy the historic_data directory to the working directory
COPY --dir test_data . # Copy the test_data directory to the working directory
COPY --dir stage_data . # Copy Stage specific data into the working directory.

RUN python3 historic_data/fund_2/mk_fund2_sql.py historic_data/fund_2/fund2_database_encrypted.sqlite3 >> historic_data/fund_2.sql
RUN python3 historic_data/fund_3/mk_fund3_sql.py historic_data/fund_3/fund3_database_encrypted.sqlite3 >> historic_data/fund_3.sql
Expand All @@ -28,9 +29,10 @@ build:
SAVE ARTIFACT migrations # Save the migrations directory as an artifact
SAVE ARTIFACT historic_data # Save the historic_data directory as an artifact
SAVE ARTIFACT test_data # Save the test_data directory as an artifact
SAVE ARTIFACT stage_data # Save the stage_data directory as an artifact

docker-compose:
FROM scratch
FROM scratch
COPY docker-compose.yml .
SAVE ARTIFACT docker-compose.yml

Expand Down
51 changes: 0 additions & 51 deletions src/event-db/historic_data/fund_10.sql

This file was deleted.

16 changes: 14 additions & 2 deletions src/event-db/migrations/V1__config_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Defined Data Formats:
`value`->"created" = <Integer Unix Epoch when Token was created>,
`value`->"expires" = <Integer Unix Epoch when Token will expire>,
`value`->"perms" = {Permissions assigned to this api key}

Community reviewers:
`id` = `email`
`id2` = `encrypted_password`
Expand All @@ -51,7 +51,19 @@ Defined Data Formats:
`value`->"anonymous_id" = `<anonymous_id of the PA>`
`value`->"force_reset" = "<bool used to force reset of password>"
`value`->"active" = "<bool used to activate account>"
...

IdeaScale parameters:
`id` = "ideascale"
`id2` = "params"
`id3` = <String identifying a fund, e.g. "F10">
`value`->"campaign_group_id" = <IdeaScale campaign group id>
`value`->"stage_ids" = <List of IdeaScale stage ids>

Event IdeaScale parameters:
`id` = "event"
`id2` = "ideascale_params"
`id3` = <Event row_id (as a string)>
`value`->"params_id" = <String identifier of the Ideascale parameters in the config table>
';

COMMENT ON COLUMN config.row_id IS
Expand Down
12 changes: 12 additions & 0 deletions src/event-db/stage_data/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Stage Specific Data

Subdirectories in this directory, that are named the same as a deployment stage will have their `.sql` files applied to the database when it is configured.

* `dev` - Development Environment specific data.
* `testnet` - Test-Net Environment specific data.
* `preprod` - Preprod Environment specific data.
* `prod` - Production Environment specific data.
* `local` - Local Testing Environment specific data. Does not get checked in to git, local only.

Each directory can only contain `*.sql` files.
They will be applied in sorted order.
5 changes: 5 additions & 0 deletions src/event-db/stage_data/dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in this directory
*
# Except these files
!.gitignore
!*.sql
54 changes: 54 additions & 0 deletions src/event-db/stage_data/dev/00001_fund10_event.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- F10
INSERT INTO event (
row_id,
name,
description,
registration_snapshot_time,
snapshot_start,
voting_power_threshold,
max_voting_power_pct,
review_rewards,
start_time,
end_time,
insight_sharing_start,
proposal_submission_start,
refine_proposals_start,
finalize_proposals_start,
proposal_assessment_start,
assessment_qa_start,
voting_start,
voting_end,
tallying_end,
block0,
block0_hash,
committee_size,
committee_threshold,
extra,
cast_to
) VALUES (
10,
'Fund 10',
'Catalyst Dev Environment - Fund 10',
'2023-08-18 21:00:00', -- Registration Snapshot Time
'2023-08-23 22:00:00', -- Snapshot Start.
450000000, -- Voting Power Threshold
1, -- Max Voting Power PCT
NULL, -- Review Rewards
'2023-06-16 19:56:00', -- Start Time
'2023-09-18 00:00:00', -- End Time
'2023-06-22 00:00:00', -- Insight Sharing Start
'2023-06-22 00:00:00', -- Proposal Submission Start
'2023-06-22 00:00:00', -- Refine Proposals Start
'2023-07-13 00:00:00', -- Finalize Proposals Start
'2023-07-20 00:00:00', -- Proposal Assessment Start
'2023-08-10 00:00:00', -- Assessment QA Start
'2023-08-31 11:00:00', -- Voting Starts
'2023-09-14 11:00:00', -- Voting Ends
'2023-09-18 11:00:00', -- Tallying Ends
NULL, -- Block 0 Data
NULL, -- Block 0 Hash
1, -- Committee Size
1, -- Committee Threshold
NULL, -- Extra
NULL -- Cast to
);
18 changes: 18 additions & 0 deletions src/event-db/stage_data/dev/00002_fund10_ideascale_params.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Define F10 IdeaScale parameters.
INSERT INTO config (id, id2, id3, value) VALUES (
'ideascale',
'params',
'F10',
'{
"campaign_group_id": 63,
"stage_ids": [4590, 4596, 4602, 4608, 4614, 4620, 4626, 4632, 4638, 4644, 4650, 4656, 4662]
}'
);

-- Use F10 params for event with row_id = 10.
INSERT INTO config (id, id2, id3, value) VALUES (
'event',
'ideascale_params',
'10',
'{"params_id": "F10"}'
);
4 changes: 4 additions & 0 deletions src/event-db/stage_data/local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
5 changes: 5 additions & 0 deletions src/event-db/stage_data/preprod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in this directory
*
# Except these files
!.gitignore
!*.sql
5 changes: 5 additions & 0 deletions src/event-db/stage_data/prod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in this directory
*
# Except these files
!.gitignore
!*.sql
5 changes: 5 additions & 0 deletions src/event-db/stage_data/testnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore everything in this directory
*
# Except these files
!.gitignore
!*.sql
54 changes: 54 additions & 0 deletions src/event-db/stage_data/testnet/00001_fund10_event.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- F10
INSERT INTO event (
row_id,
name,
description,
registration_snapshot_time,
snapshot_start,
voting_power_threshold,
max_voting_power_pct,
review_rewards,
start_time,
end_time,
insight_sharing_start,
proposal_submission_start,
refine_proposals_start,
finalize_proposals_start,
proposal_assessment_start,
assessment_qa_start,
voting_start,
voting_end,
tallying_end,
block0,
block0_hash,
committee_size,
committee_threshold,
extra,
cast_to
) VALUES (
10,
'Fund 10',
'Catalyst Testnet - Fund 10',
'2023-08-18 21:00:00', -- Registration Snapshot Time
'2023-08-23 22:00:00', -- Snapshot Start.
450000000, -- Voting Power Threshold
1, -- Max Voting Power PCT
NULL, -- Review Rewards
'2023-06-16 19:56:00', -- Start Time
'2023-09-18 00:00:00', -- End Time
'2023-06-22 00:00:00', -- Insight Sharing Start
'2023-06-22 00:00:00', -- Proposal Submission Start
'2023-06-22 00:00:00', -- Refine Proposals Start
'2023-07-13 00:00:00', -- Finalize Proposals Start
'2023-07-20 00:00:00', -- Proposal Assessment Start
'2023-08-10 00:00:00', -- Assessment QA Start
'2023-08-31 11:00:00', -- Voting Starts
'2023-09-14 11:00:00', -- Voting Ends
'2023-09-18 11:00:00', -- Tallying Ends
NULL, -- Block 0 Data
NULL, -- Block 0 Hash
1, -- Committee Size
1, -- Committee Threshold
NULL, -- Extra
NULL -- Cast to
);
18 changes: 18 additions & 0 deletions src/event-db/stage_data/testnet/00002_fund10_ideascale_params.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Define F10 IdeaScale parameters.
INSERT INTO config (id, id2, id3, value) VALUES (
'ideascale',
'params',
'F10',
'{
"campaign_group_id": 63,
"stage_ids": [4590, 4596, 4602, 4608, 4614, 4620, 4626, 4632, 4638, 4644, 4650, 4656, 4662]
}'
);

-- Use F10 params for event with row_id = 10.
INSERT INTO config (id, id2, id3, value) VALUES (
'event',
'ideascale_params',
'10',
'{"params_id": "F10"}'
);