Fix PostgreSQL schema init: commit DDL before ALTER migrations.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-01 08:15:31 +08:00
parent 008f042fcc
commit 2347276bf4
2 changed files with 4 additions and 0 deletions
+3
View File
@@ -325,6 +325,7 @@ def init_db():
trigger_price REAL, stop_loss REAL, take_profit REAL,
result TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
conn.commit()
migrations = [
"ALTER TABLE key_monitors ADD COLUMN symbol_name TEXT",
"ALTER TABLE key_monitors ADD COLUMN upper_triggered INTEGER DEFAULT 0",
@@ -376,6 +377,7 @@ def init_db():
if not is_schema_migration_error(exc):
raise
rollback_if_postgres(conn)
conn.commit()
c.execute('''CREATE TABLE IF NOT EXISTS review_records
(id INTEGER PRIMARY KEY AUTOINCREMENT,
open_time TEXT, close_time TEXT,
@@ -422,6 +424,7 @@ def init_db():
(key TEXT PRIMARY KEY,
data_json TEXT NOT NULL,
updated_at TEXT NOT NULL)''')
conn.commit()
for sql in (
"ALTER TABLE fee_rates ADD COLUMN source TEXT DEFAULT 'local'",
):