elmeg-demo/backend/migrations/add_email_verification.py
fullsizemalt f1d8a14f75 feat: Add email verification and password reset (Phase 1)
- Add email_verified, verification_token, reset_token fields to User model
- Create email_service.py with SendGrid integration
- Add auth endpoints: verify-email, resend-verification, forgot-password, reset-password
- Create frontend pages: /verify-email, /forgot-password, /reset-password
- Add forgot password link to login page
- Add PLATFORM_ENHANCEMENT_SPEC.md specification
2025-12-21 13:28:54 -08:00

34 lines
1.1 KiB
Python

"""
Migration to add email verification and password reset columns to user table.
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlmodel import Session, create_engine, text
from database import DATABASE_URL
def add_email_verification_columns():
engine = create_engine(DATABASE_URL)
columns = [
('email_verified', 'BOOLEAN DEFAULT FALSE'),
('verification_token', 'VARCHAR'),
('verification_token_expires', 'TIMESTAMP'),
('reset_token', 'VARCHAR'),
('reset_token_expires', 'TIMESTAMP'),
]
with Session(engine) as session:
for col_name, col_type in columns:
try:
session.exec(text(f"""
ALTER TABLE "user" ADD COLUMN IF NOT EXISTS {col_name} {col_type}
"""))
session.commit()
print(f"✅ Added {col_name} to user")
except Exception as e:
print(f"⚠️ {col_name}: {e}")
if __name__ == "__main__":
add_email_verification_columns()