auto_trade_sys/update_db_schema.py
薇薇安 449ad01ede a
2026-02-03 09:49:25 +08:00

33 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import sys
# Add backend directory to path
sys.path.append(os.path.join(os.path.dirname(__file__), 'backend'))
from database.connection import db
def run_migration():
print("Running migration to add realized_pnl and commission columns...")
sqls = [
"ALTER TABLE trades ADD COLUMN realized_pnl DECIMAL(20, 8) DEFAULT NULL COMMENT '币安实际结算盈亏(包含资金费率等)'",
"ALTER TABLE trades ADD COLUMN commission DECIMAL(20, 8) DEFAULT NULL COMMENT '交易手续费USDT计价'",
"ALTER TABLE trades ADD COLUMN commission_asset VARCHAR(10) DEFAULT NULL COMMENT '手续费币种BNB/USDT'"
]
for sql in sqls:
try:
print(f"Executing: {sql}")
db.execute_update(sql)
print("Success.")
except Exception as e:
print(f"Error executing SQL: {e}")
# Ignore duplicate column errors if IF NOT EXISTS fails for some reason
pass
print("Migration completed.")
if __name__ == "__main__":
run_migration()