33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
|
||
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()
|