From cfca59a2d49b34d79ffee8d6a903f8c163d7fffb Mon Sep 17 00:00:00 2001 From: Dennis Thiessen Date: Sat, 4 Jul 2026 08:05:32 +0200 Subject: [PATCH] Fix migration chain and clear stored paper exit mode Migration 017 set down_revision to "016_add_signal_context_snapshots", but migration 016's revision id is "016", so `alembic upgrade head` could not resolve the chain and the deploy's auto-alembic step would fail. Point 017 at the real id "016". Add migration 018 to delete any persisted `paper_exit_mode` row. The July 2026 promotion changed the paper-trade exit default to `atr_trailing`, but `get_exit_policy` reads a stored value before the code default, so an environment that had ever saved the old `time` mode would silently keep it and never run the promoted 3x ATR trailing exit. Mirrors migration 015's one-way settings reset. Co-Authored-By: Claude Opus 4.8 --- .../017_add_trade_setup_strategy_rank.py | 4 +- alembic/versions/018_clear_paper_exit_mode.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 alembic/versions/018_clear_paper_exit_mode.py diff --git a/alembic/versions/017_add_trade_setup_strategy_rank.py b/alembic/versions/017_add_trade_setup_strategy_rank.py index 788341f..81f070b 100644 --- a/alembic/versions/017_add_trade_setup_strategy_rank.py +++ b/alembic/versions/017_add_trade_setup_strategy_rank.py @@ -1,7 +1,7 @@ """Add production strategy rank fields to trade setups. Revision ID: 017_add_trade_setup_strategy_rank -Revises: 016_add_signal_context_snapshots +Revises: 016 Create Date: 2026-07-03 20:15:00.000000 """ @@ -12,7 +12,7 @@ import sqlalchemy as sa revision = "017_add_trade_setup_strategy_rank" -down_revision = "016_add_signal_context_snapshots" +down_revision = "016" branch_labels = None depends_on = None diff --git a/alembic/versions/018_clear_paper_exit_mode.py b/alembic/versions/018_clear_paper_exit_mode.py new file mode 100644 index 0000000..5ca3cdd --- /dev/null +++ b/alembic/versions/018_clear_paper_exit_mode.py @@ -0,0 +1,43 @@ +"""Clear the stored paper exit mode so the promoted ATR-trail default applies. + +The July 2026 promotion moved the paper-trade auto-exit default from ``time`` +(30-day hold on the initial stop) to ``atr_trailing`` (initial stop + 3x ATR +trailing stop, max 30 trading days) — the exit the production backtest +validated, now implemented live in ``paper_trade_service``. + +``get_exit_policy`` reads a stored ``paper_exit_mode`` row before falling back +to the code default, so any environment that persisted the old ``time`` value +(e.g. via Admin -> Paper-Trade Exit, or an earlier deploy) would silently keep +the old exit and never run the promoted ATR trail. Following the precedent of +migration 015, the stored row is cleared here so the new code default takes +effect. Admins can re-tune in Admin -> Paper-Trade Exit if desired. Note: this +changes how open paper trades close, so Track Record comparability resets from +this deploy. + +Revision ID: 018_clear_paper_exit_mode +Revises: 017_add_trade_setup_strategy_rank +Create Date: 2026-07-04 00:00:00.000000 +""" + +from __future__ import annotations + +from alembic import op +import sqlalchemy as sa + + +revision = "018_clear_paper_exit_mode" +down_revision = "017_add_trade_setup_strategy_rank" +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.execute( + sa.text("DELETE FROM system_settings WHERE key = 'paper_exit_mode'") + ) + + +def downgrade() -> None: + # One-way data reset: the prior stored value isn't recoverable. The code + # default applies until re-tuned, so there is nothing to restore. + pass