revamping frontend logging system and reorganising documentation
This commit is contained in:
171
alembic/env.py
171
alembic/env.py
@@ -1,4 +1,15 @@
|
||||
# alembic/env.py
|
||||
"""
|
||||
Alembic migration environment configuration.
|
||||
|
||||
This file is responsible for:
|
||||
1. Importing ALL database models so Alembic can detect schema changes
|
||||
2. Configuring the database connection
|
||||
3. Running migrations in online/offline mode
|
||||
|
||||
CRITICAL: Every model in models/database/__init__.py must be imported here!
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from logging.config import fileConfig
|
||||
@@ -12,93 +23,160 @@ 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...")
|
||||
# ============================================================================
|
||||
# IMPORT ALL DATABASE MODELS
|
||||
# ============================================================================
|
||||
# CRITICAL: Every model must be imported here so Alembic can detect tables!
|
||||
# If a model is not imported, Alembic will not create/update its table.
|
||||
#
|
||||
# Models list must match: models/database/__init__.py
|
||||
# ============================================================================
|
||||
|
||||
# Core models
|
||||
print("[ALEMBIC] Importing database models...")
|
||||
print("=" * 70)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# ADMIN MODELS
|
||||
# ----------------------------------------------------------------------------
|
||||
try:
|
||||
from models.database.admin import (
|
||||
AdminAuditLog,
|
||||
AdminNotification,
|
||||
AdminSetting,
|
||||
PlatformAlert,
|
||||
AdminSession
|
||||
)
|
||||
|
||||
print(" ✓ Admin models imported (5 models)")
|
||||
print(" - AdminAuditLog")
|
||||
print(" - AdminNotification")
|
||||
print(" - AdminSetting")
|
||||
print(" - PlatformAlert")
|
||||
print(" - AdminSession")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Admin models failed: {e}")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# USER MODEL
|
||||
# ----------------------------------------------------------------------------
|
||||
try:
|
||||
from models.database.user import User
|
||||
|
||||
print(" ✓ User model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ User model failed: {e}")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# VENDOR MODELS
|
||||
# ----------------------------------------------------------------------------
|
||||
try:
|
||||
from models.database.vendor import Vendor, VendorUser, Role
|
||||
print(" ✓ Vendor models imported (Vendor, VendorUser, Role)")
|
||||
|
||||
print(" ✓ Vendor models imported (3 models)")
|
||||
print(" - Vendor")
|
||||
print(" - VendorUser")
|
||||
print(" - Role")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Vendor models failed: {e}")
|
||||
|
||||
try:
|
||||
from models.database.vendor_domain import VendorDomain
|
||||
|
||||
print(" ✓ VendorDomain model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ VendorDomain model failed: {e}")
|
||||
|
||||
try:
|
||||
from models.database.vendor_theme import VendorTheme
|
||||
|
||||
print(" ✓ VendorTheme model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ VendorTheme model 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}")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# PRODUCT MODELS
|
||||
# ----------------------------------------------------------------------------
|
||||
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.marketplace_product import MarketplaceProduct
|
||||
|
||||
print(" ✓ MarketplaceProduct model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ MarketplaceProduct model failed: {e}")
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# INVENTORY MODEL
|
||||
# ----------------------------------------------------------------------------
|
||||
try:
|
||||
from models.database.inventory import Inventory
|
||||
|
||||
print(" ✓ Inventory model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Inventory model failed: {e}")
|
||||
|
||||
# Marketplace imports
|
||||
# ----------------------------------------------------------------------------
|
||||
# MARKETPLACE IMPORT
|
||||
# ----------------------------------------------------------------------------
|
||||
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
|
||||
# ----------------------------------------------------------------------------
|
||||
# CUSTOMER MODELS
|
||||
# ----------------------------------------------------------------------------
|
||||
try:
|
||||
from models.database.customer import Customer, CustomerAddress
|
||||
print(" ✓ Customer models imported (Customer, CustomerAddress)")
|
||||
|
||||
print(" ✓ Customer models imported (2 models)")
|
||||
print(" - Customer")
|
||||
print(" - CustomerAddress")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Customer models failed: {e}")
|
||||
|
||||
# Order models
|
||||
# ----------------------------------------------------------------------------
|
||||
# ORDER MODELS
|
||||
# ----------------------------------------------------------------------------
|
||||
try:
|
||||
from models.database.order import Order, OrderItem
|
||||
print(" ✓ Order models imported (Order, OrderItem)")
|
||||
|
||||
print(" ✓ Order models imported (2 models)")
|
||||
print(" - Order")
|
||||
print(" - 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)")
|
||||
# ============================================================================
|
||||
# SUMMARY
|
||||
# ============================================================================
|
||||
print("=" * 70)
|
||||
print(f"[ALEMBIC] Model import completed")
|
||||
print(f"[ALEMBIC] Tables detected in metadata:")
|
||||
print("=" * 70)
|
||||
|
||||
# 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)")
|
||||
if Base.metadata.tables:
|
||||
for i, table_name in enumerate(sorted(Base.metadata.tables.keys()), 1):
|
||||
print(f" {i:2d}. {table_name}")
|
||||
print("=" * 70)
|
||||
print(f"[ALEMBIC] Total tables: {len(Base.metadata.tables)}")
|
||||
else:
|
||||
print(" ⚠️ WARNING: No tables found in metadata!")
|
||||
print(" This usually means models are not being imported correctly.")
|
||||
|
||||
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")
|
||||
print("=" * 70)
|
||||
print()
|
||||
|
||||
# ============================================================================
|
||||
# ALEMBIC CONFIGURATION
|
||||
# ============================================================================
|
||||
|
||||
# Alembic Config object
|
||||
config = context.config
|
||||
@@ -109,11 +187,20 @@ config.set_main_option("sqlalchemy.url", settings.database_url)
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# Set target metadata from Base
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode."""
|
||||
"""
|
||||
Run migrations in 'offline' mode.
|
||||
|
||||
This configures the context with just a URL and not an Engine,
|
||||
though an Engine is acceptable here as well. By skipping the Engine
|
||||
creation we don't even need a DBAPI to be available.
|
||||
|
||||
Calls to context.execute() here emit the given string to the script output.
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
@@ -127,7 +214,12 @@ def run_migrations_offline() -> None:
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
"""Run migrations in 'online' mode."""
|
||||
"""
|
||||
Run migrations in 'online' mode.
|
||||
|
||||
In this scenario we need to create an Engine and associate a connection
|
||||
with the context.
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
@@ -135,12 +227,19 @@ def run_migrations_online() -> None:
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=target_metadata
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# MAIN EXECUTION
|
||||
# ============================================================================
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user