Add migration execution feature
This commit is contained in:
parent
5c63385495
commit
7c569527fe
@ -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
|
||||
|
||||
7
RELEASE_NOTES_v2.0.1.md
Normal file
7
RELEASE_NOTES_v2.0.1.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Release Notes v2.0.1
|
||||
|
||||
## Changes
|
||||
- Added "DB Migrationer" link to the settings navigation menu.
|
||||
|
||||
---
|
||||
Release Date: 28. januar 2026
|
||||
@ -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}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user