#!/usr/bin/env python3 """ Database migration script for Password Reset System Adds PasswordResetRequest and PasswordResetToken tables """ import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from app.extensions import db from app.models import PasswordResetRequest, PasswordResetToken from config import Config def create_password_reset_tables(): """Create password reset tables""" try: # Create tables db.create_all() print("✅ Password reset tables created successfully!") # Verify tables exist from sqlalchemy import inspect inspector = inspect(db.engine) tables = inspector.get_table_names() if 'password_reset_request' in tables: print("✅ PasswordResetRequest table exists") else: print("❌ PasswordResetRequest table missing") if 'password_reset_token' in tables: print("✅ PasswordResetToken table exists") else: print("❌ PasswordResetToken table missing") return True except Exception as e: print(f"❌ Error creating tables: {e}") return False def main(): """Main migration function""" print("🔄 Starting password reset system migration...") # Import app to initialize database from run import app with app.app_context(): success = create_password_reset_tables() if success: print("✅ Migration completed successfully!") print("\nNew features available:") print("- Admin can view password reset requests") print("- Admin can generate secure reset tokens") print("- Email templates for manual sending") print("- Token usage tracking") print("- Request status management") else: print("❌ Migration failed!") sys.exit(1) if __name__ == '__main__': main()