Skip to content

Commit

Permalink
chore(fix-stage-data-sql): Upsert stage data | NPG-0000 (#624)
Browse files Browse the repository at this point in the history
Fix duplicate key errors by changing stage_data SQL statements to upsert
event and config data instead of inserting.

Closes #500.
  • Loading branch information
FelipeRosa authored Nov 15, 2023
1 parent 0d5e3c3 commit 61e1113
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
26 changes: 25 additions & 1 deletion src/event-db/stage_data/dev/00001_fund11_event.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,28 @@ INSERT INTO event (
1, -- Committee Threshold
NULL, -- Extra
NULL -- Cast to
);
) ON CONFLICT (row_id) DO UPDATE
SET name = EXCLUDED.name,
description = EXCLUDED.description,
registration_snapshot_time = EXCLUDED.registration_snapshot_time,
snapshot_start = EXCLUDED.snapshot_start,
voting_power_threshold = EXCLUDED.voting_power_threshold,
max_voting_power_pct = EXCLUDED.max_voting_power_pct,
review_rewards = EXCLUDED.review_rewards,
start_time = EXCLUDED.start_time,
end_time = EXCLUDED.end_time,
insight_sharing_start = EXCLUDED.insight_sharing_start,
proposal_submission_start = EXCLUDED.proposal_submission_start,
refine_proposals_start = EXCLUDED.refine_proposals_start,
finalize_proposals_start = EXCLUDED.finalize_proposals_start,
proposal_assessment_start = EXCLUDED.proposal_assessment_start,
assessment_qa_start = EXCLUDED.assessment_qa_start,
voting_start = EXCLUDED.voting_start,
voting_end = EXCLUDED.voting_end,
tallying_end = EXCLUDED.tallying_end,
block0 = EXCLUDED.block0,
block0_hash = EXCLUDED.block0_hash,
committee_size = EXCLUDED.committee_size,
committee_threshold = EXCLUDED.committee_threshold,
extra = EXCLUDED.extra,
cast_to = EXCLUDED.cast_to;
6 changes: 4 additions & 2 deletions src/event-db/stage_data/dev/00002_fund11_params.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ INSERT INTO config (id, id2, id3, value) VALUES (
"score_field": "Rating"
}
}'
);
) ON CONFLICT (id, id2, id3) DO UPDATE
SET value = EXCLUDED.value;

-- Use F11 params for event with row_id = 11.
INSERT INTO config (id, id2, id3, value) VALUES (
'event',
'ideascale_params',
'11',
'{"params_id": "F11"}'
);
) ON CONFLICT (id, id2, id3) DO UPDATE
SET value = EXCLUDED.value;
26 changes: 25 additions & 1 deletion src/event-db/stage_data/testnet/00001_fund10_event.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,28 @@ INSERT INTO event (
1, -- Committee Threshold
NULL, -- Extra
NULL -- Cast to
);
) ON CONFLICT (row_id) DO UPDATE
SET name = EXCLUDED.name,
description = EXCLUDED.description,
registration_snapshot_time = EXCLUDED.registration_snapshot_time,
snapshot_start = EXCLUDED.snapshot_start,
voting_power_threshold = EXCLUDED.voting_power_threshold,
max_voting_power_pct = EXCLUDED.max_voting_power_pct,
review_rewards = EXCLUDED.review_rewards,
start_time = EXCLUDED.start_time,
end_time = EXCLUDED.end_time,
insight_sharing_start = EXCLUDED.insight_sharing_start,
proposal_submission_start = EXCLUDED.proposal_submission_start,
refine_proposals_start = EXCLUDED.refine_proposals_start,
finalize_proposals_start = EXCLUDED.finalize_proposals_start,
proposal_assessment_start = EXCLUDED.proposal_assessment_start,
assessment_qa_start = EXCLUDED.assessment_qa_start,
voting_start = EXCLUDED.voting_start,
voting_end = EXCLUDED.voting_end,
tallying_end = EXCLUDED.tallying_end,
block0 = EXCLUDED.block0,
block0_hash = EXCLUDED.block0_hash,
committee_size = EXCLUDED.committee_size,
committee_threshold = EXCLUDED.committee_threshold,
extra = EXCLUDED.extra,
cast_to = EXCLUDED.cast_to;
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ INSERT INTO config (id, id2, id3, value) VALUES (
"score_field": "Rating"
}
}'
);
) ON CONFLICT (id, id2, id3) DO UPDATE
SET value = EXCLUDED.value;

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

0 comments on commit 61e1113

Please sign in to comment.