""" Database setup script to create tables for the auth system """ import os from dotenv import load_dotenv from flask import Flask from models import db, User def create_app(): """Create Flask app for database operations""" app = Flask(__name__) # Configure Flask app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY') app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Initialize database db.init_app(app) return app def create_tables(): """Create database tables""" print("Creating database tables...") app = create_app() with app.app_context(): try: # Create all tables db.create_all() print("Database tables created successfully!") # Check if tables exist inspector = db.inspect(db.engine) tables = inspector.get_table_names() print(f"Tables created: {tables}") except Exception as e: print(f"Error creating tables: {e}") raise if __name__ == "__main__": # Load environment variables load_dotenv() # Verify database URL db_url = os.environ.get('SQLALCHEMY_DATABASE_URI') if not db_url: print("DATABASE_URL not found in environment variables") exit(1) print(f"Using database: {db_url.split('@')[1] if '@' in db_url else 'local'}") # Create tables create_tables()