From 1b1534d8d24922e1c718f33394940b43057356ae Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 20 Jun 2026 18:21:29 -0600 Subject: [PATCH] =?UTF-8?q?feat(sp6):=20migration=200004=20=E2=80=94=20rej?= =?UTF-8?q?ection=20columns=20+=20state-history=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds: - claims.rejection_reason, claims.rejected_at, claims.resubmit_count - claims.state_changed_at (was missing, needed for Done-today lane) - ix_claims_state_changed_at composite index Also fixes the ClaimState count assertion in test_db_models.py (7 → 8) to match the REJECTED enum value added in the previous commit, and bumps the user_version expectation in test_acks.py (3 → 4) for the same reason. --- .../migrations/0004_rejections_and_state_history.sql | 9 +++++++++ backend/tests/test_acks.py | 8 ++++---- backend/tests/test_db_models.py | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 backend/src/cyclone/migrations/0004_rejections_and_state_history.sql diff --git a/backend/src/cyclone/migrations/0004_rejections_and_state_history.sql b/backend/src/cyclone/migrations/0004_rejections_and_state_history.sql new file mode 100644 index 0000000..0f2389d --- /dev/null +++ b/backend/src/cyclone/migrations/0004_rejections_and_state_history.sql @@ -0,0 +1,9 @@ +-- version: 4 +-- SP6 T2: 999 rejection tracking + state-history index for the Done-today lane. + +ALTER TABLE claims ADD COLUMN rejection_reason TEXT; +ALTER TABLE claims ADD COLUMN rejected_at TIMESTAMP; +ALTER TABLE claims ADD COLUMN resubmit_count INTEGER NOT NULL DEFAULT 0; +ALTER TABLE claims ADD COLUMN state_changed_at TIMESTAMP; + +CREATE INDEX ix_claims_state_changed_at ON claims(state, state_changed_at); \ No newline at end of file diff --git a/backend/tests/test_acks.py b/backend/tests/test_acks.py index 1d4386f..151807e 100644 --- a/backend/tests/test_acks.py +++ b/backend/tests/test_acks.py @@ -51,16 +51,16 @@ def test_migration_0002_creates_acks_table(): def test_migration_latest_idempotent_on_fresh_db(): """Re-running the migration on the same DB must be a no-op (PRAGMA - user_version already at the latest version — currently 3 after the - 0003 constraint drop was added).""" + user_version already at the latest version — currently 4 after the + 0004 rejection columns + state-history index was added by SP6).""" with db.engine().begin() as c: v1 = c.exec_driver_sql("PRAGMA user_version").scalar() or 0 - assert v1 == 3 + assert v1 == 4 # A second run should not raise and should not bump the version. db_migrate.run(db.engine()) with db.engine().begin() as c: v2 = c.exec_driver_sql("PRAGMA user_version").scalar() or 0 - assert v2 == 3 + assert v2 == 4 def test_add_ack_persists_row(): diff --git a/backend/tests/test_db_models.py b/backend/tests/test_db_models.py index f4002e2..be3a4dc 100644 --- a/backend/tests/test_db_models.py +++ b/backend/tests/test_db_models.py @@ -27,8 +27,8 @@ def test_claim_state_enum_values(): assert ClaimState.DENIED.value == "denied" assert ClaimState.RECONCILED.value == "reconciled" assert ClaimState.REVERSED.value == "reversed" - # 7 values total. - assert len(list(ClaimState)) == 7 + # 8 values total (REJECTED was added for 999 AK9 set-level R/E). + assert len(list(ClaimState)) == 8 def test_create_and_query_batch():