[fix]. Harden DB baseline preflight [skip ci]
This commit is contained in:
@@ -8,7 +8,7 @@ from sqlalchemy import create_engine, inspect, text
|
|||||||
from gitea_codex_bot.config import get_settings
|
from gitea_codex_bot.config import get_settings
|
||||||
|
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
engine = create_engine(settings.database_url)
|
engine = create_engine(settings.sqlalchemy_url)
|
||||||
|
|
||||||
with engine.connect() as conn:
|
with engine.connect() as conn:
|
||||||
inspector = inspect(conn)
|
inspector = inspect(conn)
|
||||||
@@ -17,8 +17,14 @@ with engine.connect() as conn:
|
|||||||
has_alembic_version = "alembic_version" in tables
|
has_alembic_version = "alembic_version" in tables
|
||||||
has_review_jobs = "review_jobs" in tables
|
has_review_jobs = "review_jobs" in tables
|
||||||
has_webhook_events = "webhook_events" in tables
|
has_webhook_events = "webhook_events" in tables
|
||||||
|
stamped_revision = None
|
||||||
|
|
||||||
if not has_alembic_version and (has_review_jobs or has_webhook_events):
|
if has_alembic_version:
|
||||||
|
row = conn.execute(text("SELECT version_num FROM alembic_version LIMIT 1")).fetchone()
|
||||||
|
if row and row[0]:
|
||||||
|
stamped_revision = row[0]
|
||||||
|
|
||||||
|
if (not has_alembic_version or not stamped_revision) and (has_review_jobs or has_webhook_events):
|
||||||
revision = "0001_initial"
|
revision = "0001_initial"
|
||||||
if has_review_jobs:
|
if has_review_jobs:
|
||||||
columns = {c["name"] for c in inspector.get_columns("review_jobs")}
|
columns = {c["name"] for c in inspector.get_columns("review_jobs")}
|
||||||
|
|||||||
Reference in New Issue
Block a user