Fix duplicate off-chain vote metadata child rows (#1966)#2137
Open
ArturWieczorek wants to merge 3 commits into
Open
Fix duplicate off-chain vote metadata child rows (#1966)#2137ArturWieczorek wants to merge 3 commits into
ArturWieczorek wants to merge 3 commits into
Conversation
Re-processing the off-chain metadata of an already-stored voting anchor duplicated its child rows (off_chain_vote_drep_data, off_chain_vote_author, off_chain_vote_reference, off_chain_vote_external_update, off_chain_vote_gov_action_data). The parent insert used ON CONFLICT DO UPDATE ... RETURNING id, so a re-fetch returned the existing id, and the children - which have no uniqueness and were plain-inserted - were written again. Make insertion idempotent: insertBulkOffChainVoteDataReturningNew uses ON CONFLICT DO NOTHING RETURNING (voting_anchor_id, hash, id) so only newly inserted parents come back, and the orchestration inserts child rows only for those, matched by natural key. Adds a WithResultBulkColumns result mode for a custom RETURNING column list. Prevents new duplicates; existing rows on synced DBs are unaffected. Adds a regression test (cardano-db test-db) asserting a re-fetch creates no duplicate child rows.
b5ab32b to
256e4fd
Compare
Contributor
Author
|
Regression Tests 💚 Test Report |
Cmdv
requested changes
Jun 16, 2026
Cmdv
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-processing the off-chain metadata of an already-stored voting anchor duplicated its child rows (off_chain_vote_drep_data, off_chain_vote_author, off_chain_vote_reference, off_chain_vote_external_update, off_chain_vote_gov_action_data). The parent insert used ON CONFLICT DO UPDATE ... RETURNING id, so a re-fetch returned the existing id, and the children - which have no uniqueness and were plain-inserted - were written again.
Make insertion idempotent: insertBulkOffChainVoteDataReturningNew uses ON CONFLICT DO NOTHING RETURNING (voting_anchor_id, hash, id) so only newly inserted parents come back, and the orchestration inserts child rows only for those, matched by natural key. Adds a WithResultBulkColumns result mode for a custom RETURNING column list. Prevents new duplicates; existing rows on synced DBs are unaffected.
Adds a regression test (cardano-db test-db) asserting a re-fetch creates no duplicate child rows.
Description
Add your description here, if it fixes a particular issue please provide a link to the issue.
Checklist
fourmoluon version 0.17.0.0 (which can be run withscripts/fourmolize.sh)Migrations
If there is a breaking change, especially a big one, please add a justification here. Please elaborate
more what the migration achieves, what it cannot achieve or why a migration is not possible.