-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_db.py
More file actions
52 lines (39 loc) · 1.58 KB
/
migrate_db.py
File metadata and controls
52 lines (39 loc) · 1.58 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
#!/usr/bin/env python
"""Database migration script to add workout_type column."""
import sqlite3
import sys
from pathlib import Path
def migrate_database(db_path="strava_supercompensation.db"):
"""Add workout_type column to activities table."""
if not Path(db_path).exists():
print(f"Database {db_path} not found!")
return False
try:
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Check if column already exists
cursor.execute("PRAGMA table_info(activities)")
columns = [column[1] for column in cursor.fetchall()]
if 'workout_type' in columns:
print("Column 'workout_type' already exists in activities table.")
return True
# Add the new column
print("Adding 'workout_type' column to activities table...")
cursor.execute("ALTER TABLE activities ADD COLUMN workout_type INTEGER")
conn.commit()
print("✅ Migration successful! Column 'workout_type' has been added.")
# Show table structure
cursor.execute("PRAGMA table_info(activities)")
print("\nUpdated activities table structure:")
for column in cursor.fetchall():
print(f" - {column[1]}: {column[2]}")
conn.close()
return True
except Exception as e:
print(f"❌ Migration failed: {e}")
return False
if __name__ == "__main__":
# Allow custom database path as argument
db_path = sys.argv[1] if len(sys.argv) > 1 else "strava_supercompensation.db"
success = migrate_database(db_path)
sys.exit(0 if success else 1)