fix(scripts): fix model registration and missing platform_id in init scripts
All init scripts (init_log_settings, create_default_content_pages, create_platform_pages, seed_email_templates) failed because they didn't register all SQLAlchemy model classes, causing mapper resolution errors for cross-module relationships (Platform→ContentPage, Platform→SubscriptionTier). Fixes: - Add full model registration loop to all 5 init scripts - Add platform_id (OMS) to content page creation (NOT NULL constraint) - Add missing db.commit() to create_platform_pages.py (pages were never persisted) - Add cms.models to init_production.py registration list Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,8 +5,24 @@ Initialize default log settings in database.
|
||||
Run this script to create default logging configuration settings.
|
||||
"""
|
||||
|
||||
# Import all models to avoid SQLAlchemy relationship issues
|
||||
import models # noqa: F401
|
||||
# Register all models with SQLAlchemy so string-based relationships resolve
|
||||
for _mod in [
|
||||
"app.modules.billing.models",
|
||||
"app.modules.inventory.models",
|
||||
"app.modules.cart.models",
|
||||
"app.modules.messaging.models",
|
||||
"app.modules.loyalty.models",
|
||||
"app.modules.catalog.models",
|
||||
"app.modules.customers.models",
|
||||
"app.modules.orders.models",
|
||||
"app.modules.marketplace.models",
|
||||
"app.modules.cms.models",
|
||||
]:
|
||||
try:
|
||||
__import__(_mod)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.modules.tenancy.models import AdminSetting
|
||||
|
||||
|
||||
Reference in New Issue
Block a user