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:
@@ -12,6 +12,24 @@ from pathlib import Path
|
||||
# Add project root to path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
# 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 get_db
|
||||
from app.modules.messaging.models import EmailCategory, EmailTemplate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user