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.0 KiB
Python
43 lines
1.0 KiB
Python
"""Verify old schema tables are removed."""
|
|
|
|
import pytest
|
|
from api.database import Database
|
|
|
|
|
|
def test_old_tables_do_not_exist():
|
|
"""Verify trading_sessions, old positions, reasoning_logs don't exist."""
|
|
|
|
db = Database(":memory:")
|
|
|
|
# Query sqlite_master for old tables
|
|
cursor = db.connection.execute("""
|
|
SELECT name FROM sqlite_master
|
|
WHERE type='table' AND name IN (
|
|
'trading_sessions', 'reasoning_logs'
|
|
)
|
|
""")
|
|
|
|
tables = cursor.fetchall()
|
|
|
|
assert len(tables) == 0, f"Old tables should not exist, found: {tables}"
|
|
|
|
|
|
def test_new_tables_exist():
|
|
"""Verify new schema tables exist."""
|
|
|
|
db = Database(":memory:")
|
|
|
|
cursor = db.connection.execute("""
|
|
SELECT name FROM sqlite_master
|
|
WHERE type='table' AND name IN (
|
|
'trading_days', 'holdings', 'actions'
|
|
)
|
|
ORDER BY name
|
|
""")
|
|
|
|
tables = [row[0] for row in cursor.fetchall()]
|
|
|
|
assert 'trading_days' in tables
|
|
assert 'holdings' in tables
|
|
assert 'actions' in tables
|