bmc_hub/apply_migration_128.py
Christian 891180f3f0 Refactor opportunities and settings management
- Removed opportunity detail page route from views.py.
- Deleted opportunity_service.py as it is no longer needed.
- Updated router.py to seed new setting for case_type_module_defaults.
- Enhanced settings.html to include standard modules per case type with UI for selection.
- Implemented JavaScript functions to manage case type module defaults.
- Added RelationService for handling case relations with a tree structure.
- Created migration scripts (128 and 129) for new pipeline fields and descriptions.
- Added script to fix relation types in the database.
2026-02-15 11:12:58 +01:00

42 lines
1.1 KiB
Python

import logging
import os
import sys
sys.path.append(os.getcwd())
from app.core.database import execute_query, init_db
from app.core.config import settings
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def run_migration():
migration_file = "migrations/128_sag_pipeline_fields.sql"
logger.info("Applying migration: %s", migration_file)
try:
if "@postgres" in settings.DATABASE_URL:
logger.info("Patching DATABASE_URL for local run")
settings.DATABASE_URL = settings.DATABASE_URL.replace("@postgres", "@localhost").replace(":5432", ":5433")
init_db()
with open(migration_file, "r", encoding="utf-8") as migration:
sql = migration.read()
commands = [cmd.strip() for cmd in sql.split(";") if cmd.strip()]
for command in commands:
logger.info("Executing migration statement...")
execute_query(command, ())
logger.info("✅ Migration 128 applied successfully")
except Exception as exc:
logger.error("❌ Migration 128 failed: %s", exc)
sys.exit(1)
if __name__ == "__main__":
run_migration()