[fix]. Recover legacy DB migration baseline
All checks were successful
ci / test (push) Successful in 32s
ci / publish (push) Successful in 52s

This commit is contained in:
Space-Banane
2026-05-22 23:18:05 +02:00
parent eb00deb323
commit 20ab5be638
2 changed files with 31 additions and 2 deletions

View File

@@ -1,6 +1,36 @@
#!/bin/sh
set -eu
echo "Checking migration baseline..."
python - <<'PY'
from sqlalchemy import create_engine, inspect, text
from gitea_codex_bot.config import get_settings
settings = get_settings()
engine = create_engine(settings.database_url)
with engine.connect() as conn:
inspector = inspect(conn)
tables = set(inspector.get_table_names())
has_alembic_version = "alembic_version" in tables
has_review_jobs = "review_jobs" in tables
has_webhook_events = "webhook_events" in tables
if not has_alembic_version and (has_review_jobs or has_webhook_events):
revision = "0001_initial"
if has_review_jobs:
columns = {c["name"] for c in inspector.get_columns("review_jobs")}
if "trigger_comment_body" in columns:
revision = "0002_trigger_comment_body"
conn.execute(text("CREATE TABLE IF NOT EXISTS alembic_version (version_num VARCHAR(32) NOT NULL, PRIMARY KEY (version_num))"))
conn.execute(text("DELETE FROM alembic_version"))
conn.execute(text("INSERT INTO alembic_version (version_num) VALUES (:revision)"), {"revision": revision})
conn.commit()
print(f"Stamped legacy database at revision {revision}")
PY
echo "Running database migrations..."
alembic upgrade head

View File

@@ -14,7 +14,7 @@ from starlette.exceptions import HTTPException as StarletteHTTPException
from sqlalchemy.orm import Session
from gitea_codex_bot.config import Settings, get_settings
from gitea_codex_bot.db import Base, get_engine, get_session
from gitea_codex_bot.db import get_session
from gitea_codex_bot.services.commands import parse_command
from gitea_codex_bot.services.gitea import GiteaClient
from gitea_codex_bot.services.jobs import cooldown_remaining_seconds, enqueue_job, persist_webhook_event
@@ -123,7 +123,6 @@ async def lifespan(app: FastAPI):
_validate_required_env(settings)
_log_startup_identity(settings)
_log_startup_auth_json_status(settings)
Base.metadata.create_all(bind=get_engine())
stop_event = asyncio.Event()
task = asyncio.create_task(worker_loop(settings, stop_event))