From c66d652283da398a2ade66b9fcd9686e1978f85f Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 28 Jan 2026 10:52:36 +0100 Subject: [PATCH] Release v2.0.6 --- .env.prod.example | 2 +- RELEASE_NOTES_v2.0.6.md | 8 ++++++ VERSION | 2 +- app/settings/backend/views.py | 48 +++++++++-------------------------- 4 files changed, 22 insertions(+), 38 deletions(-) create mode 100644 RELEASE_NOTES_v2.0.6.md diff --git a/.env.prod.example b/.env.prod.example index 3965d45..4de5d29 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -8,7 +8,7 @@ # RELEASE VERSION # ===================================================== # Tag fra Gitea (f.eks. v1.0.0, v1.2.3) -RELEASE_VERSION=v2.0.5 +RELEASE_VERSION=v2.0.6 # ===================================================== # GITEA AUTHENTICATION diff --git a/RELEASE_NOTES_v2.0.6.md b/RELEASE_NOTES_v2.0.6.md new file mode 100644 index 0000000..77cd0a1 --- /dev/null +++ b/RELEASE_NOTES_v2.0.6.md @@ -0,0 +1,8 @@ +# Release Notes v2.0.6 + +## Fixes +- `/settings/migrations/execute` now runs the SQL files directly through the already-configured PostgreSQL connection pool instead of shelling out to Docker/Podman, so it works anywhere the API can reach the database. +- Cleaned up the migration endpoint to roll back on failure, reuse the pool, and return a clear success message. + +--- +Release Date: 28. januar 2026 \ No newline at end of file diff --git a/VERSION b/VERSION index b9d2bdf..703cec9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.5 \ No newline at end of file +2.0.6 \ No newline at end of file diff --git a/app/settings/backend/views.py b/app/settings/backend/views.py index 89e8bc4..0d3e31b 100644 --- a/app/settings/backend/views.py +++ b/app/settings/backend/views.py @@ -8,11 +8,9 @@ from fastapi import APIRouter, Request, HTTPException from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates from pydantic import BaseModel -import os -import shutil -import subprocess from app.core.config import settings +from app.core.database import get_db_connection, release_db_connection router = APIRouter() templates = Jinja2Templates(directory="app") @@ -66,38 +64,16 @@ def execute_migration(payload: MigrationExecution): raise HTTPException(status_code=404, detail="Migration file not found") # Determine the container runtime (Podman or Docker) - runtime_preference = (settings.CONTAINER_RUNTIME or "").strip().lower() - available_runtimes = [cmd for cmd in ("podman", "docker") if shutil.which(cmd)] - if not available_runtimes: - raise HTTPException(status_code=500, detail="No container runtime (docker/podman) found in PATH") - - if runtime_preference and runtime_preference in available_runtimes: - runtime = runtime_preference - else: - runtime = available_runtimes[0] - - command = [ - runtime, - "exec", - "-i", - "bmc-hub-postgres", - "psql", - "-U", - settings.POSTGRES_USER, - "-d", - settings.POSTGRES_DB, - ] - migration_sql = migration_file.read_text() - result = subprocess.run( - command, - input=migration_sql, - capture_output=True, - text=True, - env={**os.environ, "PGPASSWORD": settings.POSTGRES_PASSWORD}, - ) + conn = get_db_connection() + try: + with conn.cursor() as cursor: + cursor.execute(migration_sql) + conn.commit() + except Exception as exc: + conn.rollback() + raise HTTPException(status_code=500, detail=f"Migration failed: {exc}") + finally: + release_db_connection(conn) - if result.returncode != 0: - raise HTTPException(status_code=500, detail=f"Migration failed: {result.stderr}") - - return {"message": "Migration executed successfully", "output": result.stdout} + return {"message": "Migration executed successfully"}