-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.py
More file actions
27 lines (24 loc) · 883 Bytes
/
Copy pathmigrate.py
File metadata and controls
27 lines (24 loc) · 883 Bytes
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
"""
Migration script to add phone column to User table if it doesn't exist
Run this after updating models.py
"""
from flask import Flask
from application.database import db
from application.models import User
from sqlalchemy import inspect
def migrate_add_phone():
"""Add phone column to User table if it doesn't exist."""
inspector = inspect(db.engine)
columns = [c['name'] for c in inspector.get_columns('user')]
if 'phone' not in columns:
print("Adding 'phone' column to User table...")
with db.engine.connect() as conn:
conn.execute("ALTER TABLE user ADD COLUMN phone VARCHAR(15)")
conn.commit()
print("✓ Phone column added successfully!")
else:
print("✓ Phone column already exists")
if __name__ == '__main__':
from app import app
with app.app_context():
migrate_add_phone()