rebuild(migration): validate local legacy cutover
This commit is contained in:
@@ -92,7 +92,9 @@ def _legacy_database(path, key: str) -> None:
|
||||
"INSERT INTO users VALUES (8,'leefer',?,?,?,?,'admin','auto','active','永久',?,NULL)",
|
||||
(encoded_salt, encoded_hash, now, now, now),
|
||||
)
|
||||
profile = fernet.encrypt(b'{"gender":"male"}').decode()
|
||||
profile = fernet.encrypt(
|
||||
b'{"birth_datetime":"1990-03-08T08:30:00","gender":"male"}'
|
||||
).decode()
|
||||
connection.execute("INSERT INTO user_birth_profiles VALUES (8,?,?)", (profile, now))
|
||||
connection.execute(
|
||||
"INSERT INTO llm_usage VALUES (1,8,'mentor','model','','success',3,?,'','','',0,0)",
|
||||
@@ -109,12 +111,37 @@ def _legacy_database(path, key: str) -> None:
|
||||
)
|
||||
dashboard = json.dumps(
|
||||
{
|
||||
"meta": {
|
||||
"requested_date": "2026-07-30",
|
||||
"trade_date": "2026-07-29",
|
||||
"previous_trade_date": "2026-07-28",
|
||||
},
|
||||
"overview": {
|
||||
"up_count": 1,
|
||||
"down_count": 0,
|
||||
"flat_count": 0,
|
||||
"limit_up_count": 1,
|
||||
"limit_down_count": 0,
|
||||
"broken_count": 0,
|
||||
"amount_billion": 12.5,
|
||||
"seal_rate": 100,
|
||||
"sentiment_score": 64,
|
||||
"sentiment_label": "情绪偏强",
|
||||
"sentiment_phase": "修复",
|
||||
"sentiment_direction": "升温",
|
||||
"sentiment_components": {
|
||||
"breadth": {"label": "市场宽度", "score": 100, "weight": 20}
|
||||
},
|
||||
"sentiment_engine_version": 2,
|
||||
},
|
||||
"limits": [
|
||||
{
|
||||
"ts_code": "000001.SZ",
|
||||
"code": "000001",
|
||||
"name": "Ping An Bank",
|
||||
"reason": "legacy",
|
||||
"amount_billion": 1.25,
|
||||
"seal_amount_million": 20,
|
||||
}
|
||||
],
|
||||
"broken": [],
|
||||
@@ -122,7 +149,7 @@ def _legacy_database(path, key: str) -> None:
|
||||
}
|
||||
)
|
||||
connection.execute(
|
||||
"INSERT INTO dashboard_snapshots VALUES ('20260729','tushare',?,1,?)",
|
||||
"INSERT INTO dashboard_snapshots VALUES ('20260730','tushare',?,1,?)",
|
||||
(dashboard, now),
|
||||
)
|
||||
connection.execute(
|
||||
@@ -347,6 +374,18 @@ def test_legacy_migration_is_idempotent_and_preserves_login(tmp_path) -> None:
|
||||
password = connection.execute("SELECT password_hash FROM users WHERE id=8").fetchone()[0]
|
||||
assert PasswordHasher().verify("Password123", password)
|
||||
assert connection.execute("SELECT count(*) FROM watchlist_entries").fetchone()[0] == 1
|
||||
profile_payload = json.loads(
|
||||
Fernet(key.encode()).decrypt(
|
||||
connection.execute(
|
||||
"SELECT encrypted_payload FROM birth_profiles WHERE user_id=8"
|
||||
).fetchone()[0].encode()
|
||||
)
|
||||
)
|
||||
assert profile_payload == {
|
||||
"birth_date": "1990-03-08",
|
||||
"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 daily_llm_limit FROM memberships").fetchone()[0] == 61
|
||||
@@ -363,6 +402,14 @@ def test_legacy_migration_is_idempotent_and_preserves_login(tmp_path) -> None:
|
||||
).fetchone()[0]
|
||||
)
|
||||
assert summary["limits"][0]["identifier"] == "000001.SZ"
|
||||
assert summary["trade_date"] == "2026-07-29"
|
||||
assert summary["overview"]["limit_up"] == 1
|
||||
assert summary["overview"]["amount"] == 1_250_000_000
|
||||
assert summary["limits"][0]["amount"] == 125_000_000
|
||||
assert summary["limits"][0]["seal_amount"] == 20_000_000
|
||||
assert summary["sentiment"]["score"] == 64
|
||||
assert summary["sentiment"]["phase"] == "修复"
|
||||
assert summary["sentiment"]["components"][0]["key"] == "breadth"
|
||||
all_revisions = tuple(
|
||||
connection.execute(
|
||||
"""SELECT * FROM market_event_revisions WHERE trade_date='2026-07-29'
|
||||
|
||||
Reference in New Issue
Block a user