Release v2.0.6
This commit is contained in:
parent
43c7d64a01
commit
c66d652283
@ -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
|
||||
|
||||
8
RELEASE_NOTES_v2.0.6.md
Normal file
8
RELEASE_NOTES_v2.0.6.md
Normal file
@ -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
|
||||
@ -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"}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user