fix: grandfather pre-cutover stop episodes

This commit is contained in:
2026-07-17 20:28:42 +02:00
parent d858475ddb
commit d13c54e3c7
5 changed files with 179 additions and 16 deletions
@@ -30,6 +30,22 @@ def upgrade() -> None:
nullable=True,
),
)
# The policy starts at this deployment. Historical NULL values mean the
# scanner never recorded reset observations, not that those old episodes
# are still active. Mark both transitions complete so only stops created
# after the migration can open a re-entry lock.
op.execute(
sa.text(
"""
UPDATE paper_trades
SET reentry_gate_failed_at = closed_at,
reentry_gate_requalified_at = closed_at
WHERE status = 'closed'
AND close_reason = 'stop'
AND closed_at IS NOT NULL
"""
)
)
def downgrade() -> None: