M1: ingest_opps.py --year wipes other years (full-replace footgun) #509

Closed
opened 2026-07-08 19:41:25 +00:00 by kert · 1 comment
Owner

dev/scripts/ingest_opps.py --year YYYY processes only that year's dir, then
runs DROP TABLE opps.addendum_b; CREATE TABLE ... AS SELECT * FROM <that year>
— which wipes every other year from the table. The only safe way to keep all
years is a full ingest with no --year.

Fix: make --year a per-year merge — DELETE FROM opps.addendum_b WHERE year = ? then insert the new rows — leaving other years intact. Same for
apc_weight / skin_sub_addendum_b.

Background: docs/superpowers/specs/2026-07-08-duckdb-concurrency-streaming.md (M1 / #B).

`dev/scripts/ingest_opps.py --year YYYY` processes only that year's dir, then runs `DROP TABLE opps.addendum_b; CREATE TABLE ... AS SELECT * FROM <that year>` — which **wipes every other year** from the table. The only safe way to keep all years is a full ingest with no `--year`. **Fix**: make `--year` a per-year merge — `DELETE FROM opps.addendum_b WHERE year = ?` then insert the new rows — leaving other years intact. Same for `apc_weight` / `skin_sub_addendum_b`. Background: `docs/superpowers/specs/2026-07-08-duckdb-concurrency-streaming.md` (M1 / #B).
kert added the infra label 2026-07-08 19:41:25 +00:00
Author
Owner

Fixed in d809a45f92. --year is now a per-year merge: the load step reads back the existing table's other-year rows and unions them with the newly parsed frames before rebuilding (pandas concat also unions columns, so CMS header drift between years stays handled). skin_sub_addendum_b is derived from the merged addendum_b table instead of the run's frames, so it keeps all years too.

Validated against the real store: a --year 2026 run preserved identical per-year row counts for 2014–2025 across apc_weight, addendum_b, and skin_sub_addendum_b while rebuilding 2026.

Fixed in https://git.fhirworx.io/homelab/stack/commit/d809a45f928863ce7bb65a49dc4917e9b62aef7f. `--year` is now a per-year merge: the load step reads back the existing table's other-year rows and unions them with the newly parsed frames before rebuilding (pandas concat also unions columns, so CMS header drift between years stays handled). `skin_sub_addendum_b` is derived from the merged `addendum_b` table instead of the run's frames, so it keeps all years too. Validated against the real store: a `--year 2026` run preserved identical per-year row counts for 2014–2025 across `apc_weight`, `addendum_b`, and `skin_sub_addendum_b` while rebuilding 2026.
kert closed this issue 2026-07-10 20:49:06 +00:00
Sign in to join this conversation.