From c97a067e0e27b138ae040a6386cec7265394398c Mon Sep 17 00:00:00 2001 From: Dennis Thiessen Date: Thu, 13 Aug 2026 11:31:05 +0200 Subject: [PATCH] fix(risk-monitor): drop an unused import and align migration 033 with its model ruff F401 failed the deploy: `import pytest` in test_event_study.py outlived the pytest.approx assertion it was added for. Compiling the migration for Postgres while checking that turned up a second defect worth fixing while the table is still empty. It created a unique constraint *and* a plain index on effective_date, while the model declares `unique=True, index=True` -- one unique index. Both enforce uniqueness, but the pairing left a redundant second index on the column and a permanent diff for autogenerate to keep trying to reconcile. Now renders byte-for-byte what the model declares, matching RegimeSnapshot.date. Co-Authored-By: Claude Opus 5 --- alembic/versions/033_regime_fundamental_observations.py | 9 ++++++--- tests/unit/test_event_study.py | 2 -- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/alembic/versions/033_regime_fundamental_observations.py b/alembic/versions/033_regime_fundamental_observations.py index 1352add..c2d24f7 100644 --- a/alembic/versions/033_regime_fundamental_observations.py +++ b/alembic/versions/033_regime_fundamental_observations.py @@ -48,14 +48,17 @@ def upgrade() -> None: sa.Column("fetched_at", sa.DateTime(timezone=True), nullable=False), sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), sa.PrimaryKeyConstraint("id"), - sa.UniqueConstraint( - "effective_date", name="uq_regime_fundamental_observations_effective_date" - ), ) + # One unique index, not a unique constraint plus a plain index: the model + # declares `unique=True, index=True`, which SQLAlchemy renders as exactly + # this. The constraint-plus-index pairing worked but left a redundant second + # index on the column and a permanent metadata diff for autogenerate to keep + # trying to reconcile. Matches RegimeSnapshot.date, the sibling table. op.create_index( "ix_regime_fundamental_observations_effective_date", "regime_fundamental_observations", ["effective_date"], + unique=True, ) diff --git a/tests/unit/test_event_study.py b/tests/unit/test_event_study.py index 0393923..dec509e 100644 --- a/tests/unit/test_event_study.py +++ b/tests/unit/test_event_study.py @@ -5,8 +5,6 @@ from __future__ import annotations from copy import deepcopy from datetime import date, timedelta -import pytest - from app.services.breadth_service import _breadth_from_closes, compute_divergence_series from app.services.event_study_service import ( MIN_EVENTS_FOR_CONFIDENCE,