fix: add runtime schema guard for skipped count
This commit is contained in:
13
app/db.py
13
app/db.py
@@ -1,6 +1,6 @@
|
||||
from collections.abc import Generator
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, inspect, text
|
||||
from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker
|
||||
|
||||
from app.config import get_settings
|
||||
@@ -25,6 +25,17 @@ def init_db() -> None:
|
||||
import app.models # noqa: F401
|
||||
|
||||
Base.metadata.create_all(bind=engine)
|
||||
_ensure_runtime_schema()
|
||||
|
||||
|
||||
def _ensure_runtime_schema() -> None:
|
||||
inspector = inspect(engine)
|
||||
if "crawl_runs" not in inspector.get_table_names():
|
||||
return
|
||||
crawl_run_columns = {column["name"] for column in inspector.get_columns("crawl_runs")}
|
||||
if "skipped_count" not in crawl_run_columns:
|
||||
with engine.begin() as connection:
|
||||
connection.execute(text("ALTER TABLE crawl_runs ADD COLUMN skipped_count INTEGER NOT NULL DEFAULT 0"))
|
||||
|
||||
|
||||
def get_db() -> Generator[Session, None, None]:
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
APP_VERSION = "0.6.0"
|
||||
FRONTEND_VERSION = "0.6.0"
|
||||
BACKEND_VERSION = "0.6.0"
|
||||
APP_VERSION = "0.6.1"
|
||||
FRONTEND_VERSION = "0.6.1"
|
||||
BACKEND_VERSION = "0.6.1"
|
||||
|
||||
Reference in New Issue
Block a user