-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_profile_fields.py
More file actions
32 lines (28 loc) · 1.16 KB
/
migrate_profile_fields.py
File metadata and controls
32 lines (28 loc) · 1.16 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
from app import app, db
from models import User
def upgrade():
with app.app_context():
# Add new columns if they don't exist
with db.engine.connect() as conn:
# SQLite doesn't support IF NOT EXISTS for ADD COLUMN, so we'll use a try-except
columns_to_add = [
'name VARCHAR(100)',
'age_group VARCHAR(20)',
'sex VARCHAR(20)',
'industry VARCHAR(100)',
'organization VARCHAR(200)'
]
for column in columns_to_add:
try:
column_name = column.split()[0]
conn.execute(db.text(f'ALTER TABLE user ADD COLUMN {column}'))
print(f"Added column: {column_name}")
except Exception as e:
if "duplicate column" in str(e).lower():
print(f"Column {column_name} already exists")
else:
print(f"Error adding column {column_name}: {e}")
conn.commit()
print("Database schema update completed!")
if __name__ == '__main__':
upgrade()