Simplify account_risk_state DDL for PostgreSQL compatibility.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-01 08:31:17 +08:00
parent cd636ff1c3
commit 08d55411aa
+7 -8
View File
@@ -101,7 +101,7 @@ _SCHEMA_READY = False
ACCOUNT_RISK_STATE_SQL = """
CREATE TABLE IF NOT EXISTS account_risk_state (
id INTEGER NOT NULL PRIMARY KEY CHECK (id = 1),
id INTEGER PRIMARY KEY,
trading_day TEXT,
manual_close_count INTEGER DEFAULT 0,
cooloff_until_ms INTEGER,
@@ -112,12 +112,6 @@ CREATE TABLE IF NOT EXISTS account_risk_state (
)
"""
SEED_ACCOUNT_RISK_SQL = """
INSERT INTO account_risk_state (id, trading_day, manual_close_count, daily_frozen)
VALUES (1, '', 0, 0)
ON CONFLICT(id) DO NOTHING
"""
def _account_risk_table_exists(conn) -> bool:
try:
@@ -152,7 +146,12 @@ def ensure_account_risk_schema(conn) -> None:
return
_SCHEMA_READY = False
conn.execute(ACCOUNT_RISK_STATE_SQL)
conn.execute(SEED_ACCOUNT_RISK_SQL)
conn.commit()
if not conn.execute("SELECT 1 FROM account_risk_state WHERE id=1").fetchone():
conn.execute(
"INSERT INTO account_risk_state (id, trading_day, manual_close_count, daily_frozen) "
"VALUES (1, '', 0, 0)"
)
conn.commit()
_SCHEMA_READY = True