-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_notification_migration.py
More file actions
65 lines (51 loc) · 1.97 KB
/
run_notification_migration.py
File metadata and controls
65 lines (51 loc) · 1.97 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
#!/usr/bin/env python3
"""
Database Migration Script for Notification System
Run this script to create notification-related tables in the database
"""
import sqlite3
import os
from pathlib import Path
def run_migration():
"""Run the notification system database migration"""
# Get database path
db_path = os.getenv("DATABASE_URL", "app.db")
if db_path.startswith("sqlite:///"):
db_path = db_path.replace("sqlite:///", "")
# Ensure database directory exists
db_dir = Path(db_path).parent
db_dir.mkdir(parents=True, exist_ok=True)
print(f"📊 Running notification migration on database: {db_path}")
try:
# Connect to database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Read migration file
migration_file = Path(__file__).parent / "notification_migration.sql"
if not migration_file.exists():
print(f"❌ Migration file not found: {migration_file}")
return False
with open(migration_file, 'r') as f:
migration_sql = f.read()
# Execute migration
cursor.executescript(migration_sql)
conn.commit()
print("✅ Notification migration completed successfully!")
print("📋 Created tables:")
print(" - notifications")
print(" - notification_templates")
print(" - notification_preferences")
print("📋 Created indexes for performance optimization")
print("📋 Inserted default notification templates")
# Verify tables were created
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'notification%';")
tables = cursor.fetchall()
print(f"📋 Verification: Found {len(tables)} notification tables")
conn.close()
return True
except Exception as e:
print(f"❌ Migration failed: {e}")
return False
if __name__ == "__main__":
success = run_migration()
exit(0 if success else 1)