fix(migration): normalize legacy screener archives
This commit is contained in:
@@ -10,6 +10,7 @@ import sqlite3
|
||||
from cryptography.fernet import Fernet
|
||||
|
||||
from backend.features.market.events import apply_event_revisions
|
||||
from backend.features.screener.catalog import strategy_by_id
|
||||
from backend.security.passwords import PasswordHasher
|
||||
from tools.legacy_migration import LegacyMigrator
|
||||
|
||||
@@ -181,6 +182,20 @@ def _legacy_database(path, key: str) -> None:
|
||||
"INSERT INTO screener_runs VALUES (1,'20260729','','策略','{}',?, ?,8,'curated')",
|
||||
(result, now),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO screener_runs VALUES (2,'20260729','','退潮防守观察','{}',?, ?,8,'smart')",
|
||||
(result, now),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO screener_runs VALUES (3,'20260729','','退潮防守观察','{}',?, ?,NULL,'smart')",
|
||||
(result, now),
|
||||
)
|
||||
multi_factor = strategy_by_id("curated-25")
|
||||
assert multi_factor is not None
|
||||
connection.execute(
|
||||
"INSERT INTO screener_runs VALUES (4,'20260729','','多因子综合打分(IC动态加权)',?, ?, ?,NULL,'curated')",
|
||||
(json.dumps(multi_factor["formula"]), result, now),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO screener_strategies VALUES (1,'自定义','','[]','{}',0,?,?,8)",
|
||||
(now, now),
|
||||
@@ -193,6 +208,10 @@ def _legacy_database(path, key: str) -> None:
|
||||
"INSERT INTO strategy_tracks VALUES (1,8,1,'20260729','策略','000001.SZ','000001','平安银行','银行',10.5,?,?)",
|
||||
(now, now),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO strategy_tracks VALUES (2,8,2,'20260729','退潮防守观察','000001.SZ','000001','平安银行','银行',10.5,?,?)",
|
||||
(now, now),
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO data_snapshots VALUES ('popularity_v1','20260729','legacy','{}',?)", (now,)
|
||||
)
|
||||
@@ -386,8 +405,29 @@ def test_legacy_migration_is_idempotent_and_preserves_login(tmp_path) -> None:
|
||||
"birth_time": "08:30",
|
||||
"gender": "male",
|
||||
}
|
||||
assert connection.execute("SELECT count(*) FROM screener_runs").fetchone()[0] == 1
|
||||
assert connection.execute("SELECT count(*) FROM strategy_tracks").fetchone()[0] == 1
|
||||
assert connection.execute("SELECT count(*) FROM screener_runs").fetchone()[0] == 3
|
||||
stage_run = connection.execute(
|
||||
"""SELECT id,owner_user_id,strategy_id,strategy_version FROM screener_runs
|
||||
WHERE mode='stage'"""
|
||||
).fetchone()
|
||||
assert dict(stage_run) == {
|
||||
"id": 3,
|
||||
"owner_user_id": None,
|
||||
"strategy_id": "stage-06",
|
||||
"strategy_version": 1,
|
||||
}
|
||||
renamed = connection.execute(
|
||||
"""SELECT strategy_id,strategy_name FROM screener_runs
|
||||
WHERE strategy_id='curated-25'"""
|
||||
).fetchone()
|
||||
assert dict(renamed) == {
|
||||
"strategy_id": "curated-25",
|
||||
"strategy_name": "动态多因子(基础版)",
|
||||
}
|
||||
assert connection.execute("SELECT count(*) FROM strategy_tracks").fetchone()[0] == 2
|
||||
assert connection.execute(
|
||||
"SELECT run_id FROM strategy_tracks WHERE id=2"
|
||||
).fetchone()[0] == 3
|
||||
assert connection.execute("SELECT daily_llm_limit FROM memberships").fetchone()[0] == 61
|
||||
assert connection.execute("SELECT count(*) FROM seat_aliases").fetchone()[0] == 1
|
||||
assert connection.execute(
|
||||
|
||||
Reference in New Issue
Block a user