- Remove |safe from |tojson in HTML attributes (x-data) - quotes must become " for browsers to parse correctly - Update LANG-002 and LANG-003 architecture rules to document correct |tojson usage patterns: - HTML attributes: |tojson (no |safe) - Script blocks: |tojson|safe - Fix validator to warn when |tojson|safe is used in x-data (breaks HTML attribute parsing) - Improve code quality across services, APIs, and tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
122 lines
3.8 KiB
Python
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 models.database.admin 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()
|