mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
feat: drop old schema tables (trading_sessions, positions, reasoning_logs)
- 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
This commit is contained in:
42
api/migrations/002_drop_old_schema.py
Normal file
42
api/migrations/002_drop_old_schema.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""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}")
|
||||
Reference in New Issue
Block a user