Release v2.0.6
This commit is contained in:
parent
43c7d64a01
commit
c66d652283
@ -8,7 +8,7 @@
|
|||||||
# RELEASE VERSION
|
# RELEASE VERSION
|
||||||
# =====================================================
|
# =====================================================
|
||||||
# Tag fra Gitea (f.eks. v1.0.0, v1.2.3)
|
# Tag fra Gitea (f.eks. v1.0.0, v1.2.3)
|
||||||
RELEASE_VERSION=v2.0.5
|
RELEASE_VERSION=v2.0.6
|
||||||
|
|
||||||
# =====================================================
|
# =====================================================
|
||||||
# GITEA AUTHENTICATION
|
# 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.responses import HTMLResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
from app.core.database import get_db_connection, release_db_connection
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
templates = Jinja2Templates(directory="app")
|
templates = Jinja2Templates(directory="app")
|
||||||
@ -66,38 +64,16 @@ def execute_migration(payload: MigrationExecution):
|
|||||||
raise HTTPException(status_code=404, detail="Migration file not found")
|
raise HTTPException(status_code=404, detail="Migration file not found")
|
||||||
|
|
||||||
# Determine the container runtime (Podman or Docker)
|
# 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()
|
migration_sql = migration_file.read_text()
|
||||||
result = subprocess.run(
|
conn = get_db_connection()
|
||||||
command,
|
try:
|
||||||
input=migration_sql,
|
with conn.cursor() as cursor:
|
||||||
capture_output=True,
|
cursor.execute(migration_sql)
|
||||||
text=True,
|
conn.commit()
|
||||||
env={**os.environ, "PGPASSWORD": settings.POSTGRES_PASSWORD},
|
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:
|
return {"message": "Migration executed successfully"}
|
||||||
raise HTTPException(status_code=500, detail=f"Migration failed: {result.stderr}")
|
|
||||||
|
|
||||||
return {"message": "Migration executed successfully", "output": result.stdout}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user