Skip to content

fix(sync): D1 holds only status='ok' rows - #145

Merged
remcovanmook merged 1 commit into
mainfrom
fix/d1-only-ok-rows
Oct 10, 2026
Merged

remcovanmook merged 1 commit into
mainfrom
fix/d1-only-ok-rows

Conversation

@remcovanmook

Copy link
Copy Markdown
Owner

Follow-up to #144. That commit was pushed after #144 merged, so it comes in its own PR.

The API never serves a non-ok row, so there's no reason to store one. Storing them only created leaks like the 22 pending campuses that #144 found.

Changes

  • sync/rows.js isListed(row): a row belongs in D1 only if its status is ok. A missing status field still counts as listed, as before.
  • Sync: any other status (deleted, pending, …) is a removal: an existing row is deleted, and a new row is never inserted. A pending row approved later comes back through ?since= as ok.
  • Health check: its re-fetch of missing or outdated rows uses the same rule.
  • Migration 013_only_ok_rows.sql: DELETE … WHERE status != 'ok' on every table. Today that clears the 22 pending campuses; every other table holds only ok rows already.

#144's status = 'ok' predicates in expansion and search stay as a cheap backstop.

Testing

  • New SQLite sync test: an existing row that turns pending is deleted; a new pending row is never inserted; row_count stays exact (5 + 1 new − 1 removed).
  • Migration checked on a scratch database: the pending row is removed and the ok row kept.
  • Workers 1472/1472, typecheck clean, pre-push hook passed.

🤖 Generated with Claude Code

The mirror serves only what upstream lists, so storing anything else only
creates leaks like the pending-campus one. The sync (and the health
check's refetch) now treats any status other than 'ok' as a removal: an
existing row is deleted, a new one is never inserted. A pending row that
is approved later comes back via ?since= as 'ok'. Migration 013 deletes
the non-ok rows earlier syncs stored (22 pending campuses).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@remcovanmook
remcovanmook merged commit 4b99f7b into main Oct 10, 2026
10 checks passed
@remcovanmook
remcovanmook deleted the fix/d1-only-ok-rows branch October 10, 2026 11:16
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