Skip to content

Skip stale-doc validation in ballot question sync#56

Merged
LexaMichaelides merged 1 commit intofeat/ballot-questionsfrom
fix-sync-script-validation
Apr 27, 2026
Merged

Skip stale-doc validation in ballot question sync#56
LexaMichaelides merged 1 commit intofeat/ballot-questionsfrom
fix-sync-script-validation

Conversation

@tripledoublev
Copy link
Copy Markdown
Member

The problem

syncBallotQuestions was failing on dev with a runtypes validation error.

Description of that problem

The script reads each existing Firestore doc and runs it through BallotQuestion.checkWithDefaults before the upsert — so it had to validate data it then overwrites. After commit 79026eb6 narrowed supportCommittee/opposeCommittee from Array(String) to Union(String, Null), any pre-existing dev doc still holding the array shape blew up validation, and the sync exited before writing anything. The script couldn't repair the very state it was designed to repair.

Changes in this PR

The script only consumes four fields off the existing snapshot (testimonyCount, endorseCount, neutralCount, opposeCount) to preserve runtime-owned counters through the upsert. Validating the rest of the doc was incidental. Replaced the BallotQuestion.checkWithDefaults(snap.data()) call with a plain snap.data(). YAML input is still validated on read (line 27).

Test

Reproduced against a local Firestore emulator:

  1. Seeded ballotQuestions/23-34 with the broken array shape (supportCommittee: ["Old Committee A", "Old Committee B"]) and non-zero counters.
  2. Ran yarn firebase-admin --env=local run-script syncBallotQuestions --dir=... against a single YAML.
  3. Sync committed cleanly. Post-state: supportCommittee is now the YAML's string value, opposeCommittee is null, and the four counters were preserved (testimonyCount: 42, endorseCount: 30, etc.).

So one sync run overwrites the stale array shape and self-heals the dev DB without a separate migration.

@LexaMichaelides
Copy link
Copy Markdown
Member

lg, thanks!

@LexaMichaelides LexaMichaelides merged commit faf0759 into feat/ballot-questions Apr 27, 2026
10 of 11 checks passed
@tripledoublev tripledoublev deleted the fix-sync-script-validation branch April 27, 2026 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants