# alembic/env.py import os import sys from logging.config import fileConfig from sqlalchemy import engine_from_config, pool from alembic import context # Add your project directory to the Python path sys.path.append(os.path.dirname(os.path.dirname(__file__))) from app.core.config import settings from models.database.base import Base # === IMPORTANT: Import all your DATABASE models here === # Only import SQLAlchemy models, not Pydantic API models print("[ALEMBIC] Importing database models...") # Core models try: from models.database.user import User print(" ✓ User model imported") except ImportError as e: print(f" ✗ User model failed: {e}") try: from models.database.vendor import Vendor, VendorUser, Role print(" ✓ Vendor models imported (Vendor, VendorUser, Role)") except ImportError as e: print(f" ✗ Vendor models failed: {e}") # Product models try: from models.database.marketplace_product import MarketplaceProduct print(" ✓ MarketplaceProduct model imported") except ImportError as e: print(f" ✗ MarketplaceProduct model failed: {e}") try: from models.database.product import Product print(" ✓ Product model imported") except ImportError as e: print(f" ✗ Product model failed: {e}") # Inventory try: from models.database.inventory import Inventory print(" ✓ Inventory model imported") except ImportError as e: print(f" ✗ Inventory model failed: {e}") # Marketplace imports try: from models.database.marketplace_import_job import MarketplaceImportJob print(" ✓ MarketplaceImportJob model imported") except ImportError as e: print(f" ✗ MarketplaceImportJob model failed: {e}") # Customer models (MISSING IN YOUR FILE) try: from models.database.customer import Customer, CustomerAddress print(" ✓ Customer models imported (Customer, CustomerAddress)") except ImportError as e: print(f" ✗ Customer models failed: {e}") # Order models (MISSING IN YOUR FILE) try: from models.database.order import Order, OrderItem print(" ✓ Order models imported (Order, OrderItem)") except ImportError as e: print(f" ✗ Order models failed: {e}") # Payment models (if you have them) try: from models.database.payment import Payment print(" ✓ Payment model imported") except ImportError as e: print(f" - Payment model not found (optional)") # Shipping models (if you have them) try: from models.database.shipping import ShippingAddress print(" ✓ Shipping model imported") except ImportError as e: print(f" - Shipping model not found (optional)") print(f"\n[ALEMBIC] Model import completed.") print(f"[ALEMBIC] Tables found: {list(Base.metadata.tables.keys())}") print(f"[ALEMBIC] Total tables to create: {len(Base.metadata.tables)}\n") # Alembic Config object config = context.config # Override sqlalchemy.url with our settings config.set_main_option("sqlalchemy.url", settings.database_url) if config.config_file_name is not None: fileConfig(config.config_file_name) target_metadata = Base.metadata def run_migrations_offline() -> None: """Run migrations in 'offline' mode.""" url = config.get_main_option("sqlalchemy.url") context.configure( url=url, target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, ) with context.begin_transaction(): context.run_migrations() def run_migrations_online() -> None: """Run migrations in 'online' mode.""" connectable = engine_from_config( config.get_section(config.config_ini_section, {}), prefix="sqlalchemy.", poolclass=pool.NullPool, ) with connectable.connect() as connection: context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations() if context.is_offline_mode(): run_migrations_offline() else: run_migrations_online()