mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
- Created migration script to drop old tables - Removed old table creation from database.py - Added tests to verify old tables are removed and new tables exist - Migration script can be run standalone with: PYTHONPATH=. python api/migrations/002_drop_old_schema.py
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""Drop old schema tables (trading_sessions, positions, reasoning_logs)."""
|
|
|
|
|
|
def drop_old_schema(db):
|
|
"""
|
|
Drop old schema tables that have been replaced by new schema.
|
|
|
|
Old schema:
|
|
- trading_sessions → replaced by trading_days
|
|
- positions (action-centric) → replaced by trading_days + actions + holdings
|
|
- reasoning_logs → replaced by trading_days.reasoning_full
|
|
|
|
Args:
|
|
db: Database instance
|
|
"""
|
|
|
|
# Drop reasoning_logs (child table first)
|
|
db.connection.execute("DROP TABLE IF EXISTS reasoning_logs")
|
|
|
|
# Drop positions (note: this is the OLD action-centric positions table)
|
|
# The new schema doesn't have a positions table at all
|
|
db.connection.execute("DROP TABLE IF EXISTS positions")
|
|
|
|
# Drop trading_sessions
|
|
db.connection.execute("DROP TABLE IF EXISTS trading_sessions")
|
|
|
|
db.connection.commit()
|
|
|
|
print("✅ Dropped old schema tables: trading_sessions, positions, reasoning_logs")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
"""Run migration standalone."""
|
|
from api.database import Database
|
|
from tools.deployment_config import get_db_path
|
|
|
|
db_path = get_db_path("data/trading.db")
|
|
db = Database(db_path)
|
|
|
|
drop_old_schema(db)
|
|
|
|
print(f"✅ Migration complete: {db_path}")
|