Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/app/api/routes_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ def _store_and_respond(db: Session, ctype: str, resource: str, origin_as: str |
except OperationalError as exc:
db.rollback()
if "no column named created_by_user_id" in str(exc).lower():
raise HTTPException(status_code=503, detail="Database schema is not up to date. Please run migrations: docker compose exec backend alembic upgrade head") from exc
from app.core.system_status import MIGRATION_OPERATOR_GUIDANCE
raise HTTPException(status_code=503, detail=MIGRATION_OPERATOR_GUIDANCE) from exc
raise
29 changes: 19 additions & 10 deletions backend/app/core/system_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ def get_database_status(engine: Engine | None) -> dict:
return payload


MIGRATION_OPERATOR_GUIDANCE = """Database schema is not up to date.

RouteForge detected that required database migrations have not been applied yet.

Please run:

docker compose exec backend alembic current
docker compose exec backend alembic heads
docker compose exec backend alembic upgrade head

If you are using the production compose file, run:

docker compose -f docker-compose.prod.yml exec backend alembic current
docker compose -f docker-compose.prod.yml exec backend alembic heads
docker compose -f docker-compose.prod.yml exec backend alembic upgrade head

Then restart RouteForge if needed."""

def _security_warnings() -> list[str]:
warnings: list[str] = []
if settings.secret_key == "change-me":
Expand All @@ -139,17 +157,8 @@ def build_system_status(engine: Engine | None) -> dict:
operational_warnings: list[str] = []
if database.get("migration_status") != "up_to_date":
operational_warnings.append(
"Database schema is behind the application version. Run database migrations before using checks."
MIGRATION_OPERATOR_GUIDANCE
)
if database.get("migration_status") == "behind":
operational_warnings.extend(
[
"Run: alembic current",
"Run: alembic heads",
"Run: alembic upgrade head",
]
)

return {
"status": "ok",
"name": settings.app_name,
Expand Down
Loading