Files
orion/scripts/init_log_settings.py
Samir Boulahtit d7a0ff8818 refactor: complete module-driven architecture migration
This commit completes the migration to a fully module-driven architecture:

## Models Migration
- Moved all domain models from models/database/ to their respective modules:
  - tenancy: User, Admin, Vendor, Company, Platform, VendorDomain, etc.
  - cms: MediaFile, VendorTheme
  - messaging: Email, VendorEmailSettings, VendorEmailTemplate
  - core: AdminMenuConfig
- models/database/ now only contains Base and TimestampMixin (infrastructure)

## Schemas Migration
- Moved all domain schemas from models/schema/ to their respective modules:
  - tenancy: company, vendor, admin, team, vendor_domain
  - cms: media, image, vendor_theme
  - messaging: email
- models/schema/ now only contains base.py and auth.py (infrastructure)

## Routes Migration
- Moved admin routes from app/api/v1/admin/ to modules:
  - menu_config.py -> core module
  - modules.py -> tenancy module
  - module_config.py -> tenancy module
- app/api/v1/admin/ now only aggregates auto-discovered module routes

## Menu System
- Implemented module-driven menu system with MenuDiscoveryService
- Extended FrontendType enum: PLATFORM, ADMIN, VENDOR, STOREFRONT
- Added MenuItemDefinition and MenuSectionDefinition dataclasses
- Each module now defines its own menu items in definition.py
- MenuService integrates with MenuDiscoveryService for template rendering

## Documentation
- Updated docs/architecture/models-structure.md
- Updated docs/architecture/menu-management.md
- Updated architecture validation rules for new exceptions

## Architecture Validation
- Updated MOD-019 rule to allow base.py in models/schema/
- Created core module exceptions.py and schemas/ directory
- All validation errors resolved (only warnings remain)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 21:02:56 +01:00

122 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""
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
from app.core.database import SessionLocal
from app.modules.tenancy.models import AdminSetting
def init_log_settings():
"""Create default log settings if they don't exist."""
db = SessionLocal()
try:
settings_to_create = [
{
"key": "log_level",
"value": "INFO",
"value_type": "string",
"category": "logging",
"description": "Application log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
"is_public": False,
"is_encrypted": False,
},
{
"key": "log_file_max_size_mb",
"value": "10",
"value_type": "integer",
"category": "logging",
"description": "Maximum log file size in MB before rotation",
"is_public": False,
"is_encrypted": False,
},
{
"key": "log_file_backup_count",
"value": "5",
"value_type": "integer",
"category": "logging",
"description": "Number of rotated log files to keep",
"is_public": False,
"is_encrypted": False,
},
{
"key": "db_log_retention_days",
"value": "30",
"value_type": "integer",
"category": "logging",
"description": "Number of days to retain logs in database",
"is_public": False,
"is_encrypted": False,
},
{
"key": "file_logging_enabled",
"value": "true",
"value_type": "boolean",
"category": "logging",
"description": "Enable file-based logging",
"is_public": False,
"is_encrypted": False,
},
{
"key": "db_logging_enabled",
"value": "true",
"value_type": "boolean",
"category": "logging",
"description": "Enable database logging for critical events",
"is_public": False,
"is_encrypted": False,
},
]
created_count = 0
updated_count = 0
for setting_data in settings_to_create:
existing = (
db.query(AdminSetting)
.filter(AdminSetting.key == setting_data["key"])
.first()
)
if existing:
print(
f"✓ Setting '{setting_data['key']}' already exists (value: {existing.value})"
)
updated_count += 1
else:
setting = AdminSetting(**setting_data)
db.add(setting)
created_count += 1
print(
f"✓ Created setting '{setting_data['key']}' = {setting_data['value']}"
)
db.commit()
print("\n" + "=" * 70)
print("LOG SETTINGS INITIALIZATION COMPLETE")
print("=" * 70)
print(f" Created: {created_count} settings")
print(f" Existing: {updated_count} settings")
print(f" Total: {len(settings_to_create)} settings")
print("=" * 70)
except Exception as e:
db.rollback()
print(f"Error initializing log settings: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
print("=" * 70)
print("INITIALIZING LOG SETTINGS")
print("=" * 70)
init_log_settings()