-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_database.py
More file actions
66 lines (52 loc) · 2.17 KB
/
migrate_database.py
File metadata and controls
66 lines (52 loc) · 2.17 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
"""
Database Schema Migration Script
Adds email verification fields to the users table
"""
import sqlite3
import os
DB_FILE = 'enivaran.db'
def migrate_database():
"""Add email verification columns to users table"""
if not os.path.exists(DB_FILE):
print(f"❌ Database file '{DB_FILE}' not found!")
return
try:
conn = sqlite3.connect(DB_FILE)
cursor = conn.cursor()
print("🔄 Migrating database schema...")
# Check if columns already exist
cursor.execute("PRAGMA table_info(users)")
columns = [column[1] for column in cursor.fetchall()]
# Add email column if it doesn't exist
if 'email' not in columns:
print(" Adding 'email' column...")
cursor.execute('ALTER TABLE users ADD COLUMN email TEXT UNIQUE')
else:
print(" 'email' column already exists")
# Add email_verified column
if 'email_verified' not in columns:
print(" Adding 'email_verified' column...")
cursor.execute('ALTER TABLE users ADD COLUMN email_verified INTEGER DEFAULT 0')
else:
print(" 'email_verified' column already exists")
# Add verification_token column
if 'verification_token' not in columns:
print(" Adding 'verification_token' column...")
cursor.execute('ALTER TABLE users ADD COLUMN verification_token TEXT')
else:
print(" 'verification_token' column already exists")
# Add verification_token_expires column
if 'verification_token_expires' not in columns:
print(" Adding 'verification_token_expires' column...")
cursor.execute('ALTER TABLE users ADD COLUMN verification_token_expires TIMESTAMP')
else:
print(" 'verification_token_expires' column already exists")
conn.commit()
print("\n✅ Database migration completed successfully!")
except sqlite3.Error as e:
print(f"\n❌ Database error: {e}")
finally:
if conn:
conn.close()
if __name__ == '__main__':
migrate_database()