Phase 3.1: Enhanced Chore Logging and Reporting System
This commit is contained in:
53
backend/migrations/001_add_birthday_field.py
Normal file
53
backend/migrations/001_add_birthday_field.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Database migration: Add birthday field to users table.
|
||||
|
||||
This script safely adds a birthday column to the users table.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from app.core.database import engine, SessionLocal
|
||||
from sqlalchemy import text
|
||||
|
||||
def add_birthday_column():
|
||||
"""Add birthday column to users table."""
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
print("=" * 70)
|
||||
print("MIGRATION: Add Birthday Field to Users")
|
||||
print("=" * 70)
|
||||
print()
|
||||
|
||||
# Check if column already exists
|
||||
result = db.execute(text("PRAGMA table_info(users)"))
|
||||
columns = [row[1] for row in result.fetchall()]
|
||||
|
||||
if 'birthday' in columns:
|
||||
print("✅ Birthday column already exists. No migration needed.")
|
||||
return
|
||||
|
||||
print("📋 Adding birthday column to users table...")
|
||||
|
||||
# Add birthday column (DATE type, nullable)
|
||||
db.execute(text("ALTER TABLE users ADD COLUMN birthday DATE"))
|
||||
db.commit()
|
||||
|
||||
print("✅ Birthday column added successfully!")
|
||||
print()
|
||||
print("Migration complete!")
|
||||
print()
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Migration failed: {e}")
|
||||
db.rollback()
|
||||
raise
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_birthday_column()
|
||||
Reference in New Issue
Block a user