diff --git a/.env.prod.example b/.env.prod.example index 57096a2..fdfe240 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.0 +RELEASE_VERSION=v2.0.1 # ===================================================== # GITEA AUTHENTICATION diff --git a/RELEASE_NOTES_v2.0.1.md b/RELEASE_NOTES_v2.0.1.md new file mode 100644 index 0000000..19c7c7e --- /dev/null +++ b/RELEASE_NOTES_v2.0.1.md @@ -0,0 +1,7 @@ +# Release Notes v2.0.1 + +## Changes +- Added "DB Migrationer" link to the settings navigation menu. + +--- +Release Date: 28. januar 2026 \ No newline at end of file diff --git a/VERSION b/VERSION index 359a5b9..10bf840 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0 \ No newline at end of file +2.0.1 \ No newline at end of file diff --git a/app/settings/backend/views.py b/app/settings/backend/views.py index 92be96b..c875255 100644 --- a/app/settings/backend/views.py +++ b/app/settings/backend/views.py @@ -4,9 +4,10 @@ Settings Frontend Views from datetime import datetime from pathlib import Path -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, HTTPException from fastapi.responses import HTMLResponse from fastapi.templating import Jinja2Templates +import subprocess from app.core.config import settings @@ -46,3 +47,25 @@ async def migrations_page(request: Request): "db_name": settings.POSTGRES_DB, "db_container": "bmc-hub-postgres" }) + + +@router.post("/settings/migrations/execute", tags=["Frontend"]) +def execute_migration(file_name: str): + """Execute a migration SQL file""" + migrations_dir = Path(__file__).resolve().parents[3] / "migrations" + migration_file = migrations_dir / file_name + + if not migration_file.exists(): + raise HTTPException(status_code=404, detail="Migration file not found") + + # Determine the container runtime (Podman or Docker) + container_runtime = "podman" if settings.CONTAINER_RUNTIME == "podman" else "docker" + + # Execute the migration file + command = f"{container_runtime} exec bmc-hub-postgres psql -U {settings.POSTGRES_USER} -d {settings.POSTGRES_DB} -f {migration_file}" + result = subprocess.run(command, shell=True, capture_output=True, text=True) + + if result.returncode != 0: + raise HTTPException(status_code=500, detail=f"Migration failed: {result.stderr}") + + return {"message": "Migration executed successfully", "output": result.stdout}