plan+spec: add migration 0014 to relax PKs; renumber plan Task 1.3 -> 1.4
The implementer caught that claims.id is a single-column PK, which prevents the same CLM01 from existing in multiple batches. That makes the spec's pre-flight 409 workflow unreachable and resubmits impossible. Migration 0014 relaxes the PKs to composite (batch_id, id) on both claims and remittances, and updates all FKs that referenced the old single-column PK. Task 1.3 in the plan is now the migration; the previous Task 1.3 (helper tightening) is renumbered to Task 1.4 and will run after 0014 lands.
This commit is contained in:
@@ -25,13 +25,21 @@ The root cause of the 409s is a schema bug — see
|
||||
Migration 0013 drops the `UNIQUE(batch_id, patient_control_number)` inline
|
||||
constraint that 0003 was supposed to drop. After 0013 lands, **multi-claim
|
||||
837P files where many CLM segments share a subscriber's `member_id` will
|
||||
ingest cleanly for the first time** — but true cross-batch CLM01
|
||||
collisions can still fire, and the user needs the new workflow to handle
|
||||
them.
|
||||
ingest cleanly for the first time**.
|
||||
|
||||
But 0013 alone is not enough. The current schema has `claims.id` and
|
||||
`remittances.id` as single-column PRIMARY KEYs, which means the same
|
||||
CLM01 cannot exist in two different batches. That makes "cross-batch
|
||||
CLM01 collisions" impossible to express in the data — but it also makes
|
||||
resubmits impossible, and it makes the 409-with-collision-summary workflow
|
||||
this SP describes unreachable. **Migration 0014 (added as Task 1.3 to the
|
||||
plan) relaxes the PKs to composite `(batch_id, id)`.** After 0014 lands,
|
||||
real resubmits are representable, the pre-flight 409 path actually fires,
|
||||
and the workflow defined below is exercisable end-to-end against real data.
|
||||
|
||||
This SP defines the workflow for both classes of collision:
|
||||
1. Multi-claim files with shared `member_id` (no longer a 409 after 0013).
|
||||
2. Files where one or more CLM01s exist in a prior batch (still a 409).
|
||||
2. Files where one or more CLM01s exist in a prior batch (a 409 after 0014; this SP defines the UX for it).
|
||||
|
||||
---
|
||||
|
||||
@@ -671,6 +679,11 @@ After it runs:
|
||||
- Multi-claim 837P files with shared `member_id` ingest cleanly for
|
||||
the first time.
|
||||
|
||||
Migration 0014 (added as Task 1.3 in the plan) further relaxes the schema:
|
||||
it changes the PKs on `claims` and `remittances` from single-column
|
||||
(`id`) to composite (`batch_id`, `id`). This is what allows resubmits and
|
||||
makes the workflow in §3 reachable.
|
||||
|
||||
No new tables. No new columns. The DELETE endpoint relies on existing
|
||||
`ON DELETE CASCADE` FKs.
|
||||
|
||||
@@ -681,13 +694,14 @@ No new tables. No new columns. The DELETE endpoint relies on existing
|
||||
| File | Change |
|
||||
|---|---|
|
||||
| `backend/src/cyclone/migrations/0013_drop_claims_unique_constraint.sql` | new (DONE on `claims-unique-fix`) |
|
||||
| `backend/src/cyclone/migrations/0014_relax_claims_remits_pk.sql` | new: composite PK `(batch_id, id)` on `claims` and `remittances`; updates FKs |
|
||||
| `backend/src/cyclone/store.py` | new `find_existing_batch_for_claim` / `find_existing_batch_for_remit` (DONE) + new `delete_batch` method |
|
||||
| `backend/src/cyclone/dedup.py` | new file: pre-flight `preflight_837` / `preflight_835` + `CollisionReport` dataclass |
|
||||
| `backend/src/cyclone/api.py` | 837/835 endpoints: pre-flight check, force param, new 409 body, race handler, new DELETE endpoint |
|
||||
| `src/lib/api.ts` | `ApiError` adds `collisions` + `parseResult`; `parse837`/`parse835` accept `force`; new `deleteBatch` |
|
||||
| `src/pages/Upload.tsx` | new `UploadError` state, error panel JSX, force-insert handler, delete-prior handler |
|
||||
| `src/pages/Upload.test.tsx` | new tests (4 cases from §11) |
|
||||
| `backend/tests/test_db_migrate.py` | 0013 idempotency + UNIQUE-dropped tests (DONE) |
|
||||
| `backend/tests/test_db_migrate.py` | 0013 idempotency + UNIQUE-dropped tests (DONE); 0014 composite-PK + FK-cascade tests |
|
||||
| `backend/tests/test_store.py` | `find_existing_batch_for_claim`/`remit` tests (DONE) |
|
||||
| `backend/tests/test_dedup.py` | new tests for `preflight_837` / `preflight_835` (§11) |
|
||||
| `backend/tests/test_api_parse_persists.py` | new tests: pre-flight 409, force-insert, within-file 409, race 409, DELETE endpoint (§11) |
|
||||
|
||||
Reference in New Issue
Block a user