-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_adaptive_models.py
More file actions
68 lines (51 loc) · 2.06 KB
/
migrate_adaptive_models.py
File metadata and controls
68 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
"""Database migration script to add adaptive model and performance tracking tables."""
import sys
from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Add parent directory to path
sys.path.append(str(Path(__file__).parent))
from strava_supercompensation.db.models import Base, PerformanceOutcome, AdaptiveModelParameters
from strava_supercompensation.config import config
def migrate_database(db_url=None):
"""Add new tables for adaptive model and performance tracking."""
if db_url is None:
db_url = config.DATABASE_URL
print(f"Migrating database: {db_url}")
try:
# Create engine
engine = create_engine(db_url)
# Create new tables (won't affect existing tables)
print("Creating new tables for adaptive model and performance tracking...")
Base.metadata.create_all(
engine,
tables=[
PerformanceOutcome.__table__,
AdaptiveModelParameters.__table__,
]
)
print("✅ Migration successful! New tables have been added:")
print(" - performance_outcomes: Track training outcomes for model adaptation")
print(" - adaptive_model_parameters: Store personalized model parameters")
# Verify tables were created
Session = sessionmaker(bind=engine)
session = Session()
# Check if we can query the new tables
try:
session.query(PerformanceOutcome).first()
session.query(AdaptiveModelParameters).first()
print("\n✅ Tables verified successfully!")
except Exception as e:
print(f"\n⚠️ Table verification failed: {e}")
finally:
session.close()
return True
except Exception as e:
print(f"❌ Migration failed: {e}")
return False
if __name__ == "__main__":
# Allow custom database URL as argument
db_url = sys.argv[1] if len(sys.argv) > 1 else None
success = migrate_database(db_url)
sys.exit(0 if success else 1)