-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_multiple_choice_column.py
More file actions
76 lines (61 loc) · 2.04 KB
/
add_multiple_choice_column.py
File metadata and controls
76 lines (61 loc) · 2.04 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
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""
Add multiple_choice column to polls table
"""
import sqlite3
import sys
from decouple import config
from pathlib import Path
def add_multiple_choice_column():
"""Add multiple_choice column to polls table"""
db_path = config("DB_PATH", default="./db/polly.db")
if not Path(db_path).exists():
print(f"❌ Database file {db_path} not found!")
return False
conn = None
try:
# Connect to database
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
# Check if column already exists
cursor.execute("PRAGMA table_info(polls)")
columns = [column[1] for column in cursor.fetchall()]
if 'multiple_choice' in columns:
print("✅ multiple_choice column already exists")
return True
# Add the column
print("📝 Adding multiple_choice column to polls table...")
cursor.execute("""
ALTER TABLE polls
ADD COLUMN multiple_choice BOOLEAN DEFAULT FALSE
""")
# Commit changes
conn.commit()
print("✅ Successfully added multiple_choice column")
# Verify the column was added
cursor.execute("PRAGMA table_info(polls)")
columns = [column[1] for column in cursor.fetchall()]
if 'multiple_choice' in columns:
print("✅ Column addition verified")
return True
else:
print("❌ Column addition verification failed")
return False
except sqlite3.Error as e:
print(f"❌ Database error: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error: {e}")
return False
finally:
if conn is not None:
conn.close()
if __name__ == "__main__":
print("🔄 Adding multiple_choice column to polls table...")
success = add_multiple_choice_column()
if success:
print("🎉 Migration completed successfully!")
sys.exit(0)
else:
print("💥 Migration failed!")
sys.exit(1)