Support kind=llm profiles (instruction/schema), optional multi-event posts via #eN URLs, and recover stale running/queued parse jobs after worker crashes. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
from sqlalchemy import inspect, text
|
|
from sqlalchemy.engine import Engine
|
|
|
|
|
|
def migrate_schema(engine: Engine) -> None:
|
|
"""Apply lightweight schema updates for existing deployments."""
|
|
inspector = inspect(engine)
|
|
tables = set(inspector.get_table_names())
|
|
statements: list[str] = []
|
|
|
|
if "parse_jobs" in tables:
|
|
columns = {col["name"] for col in inspector.get_columns("parse_jobs")}
|
|
if "interval_seconds" not in columns:
|
|
statements.append(
|
|
"ALTER TABLE parse_jobs ADD COLUMN interval_seconds INTEGER NOT NULL DEFAULT 3600"
|
|
)
|
|
if "is_active" not in columns:
|
|
statements.append(
|
|
"ALTER TABLE parse_jobs ADD COLUMN is_active BOOLEAN NOT NULL DEFAULT TRUE"
|
|
)
|
|
if "profile_id" not in columns:
|
|
statements.append("ALTER TABLE parse_jobs ADD COLUMN profile_id INTEGER")
|
|
if "channel_id" not in columns:
|
|
statements.append("ALTER TABLE parse_jobs ADD COLUMN channel_id INTEGER")
|
|
|
|
if "parser_profiles" in tables:
|
|
columns = {col["name"] for col in inspector.get_columns("parser_profiles")}
|
|
if "kind" not in columns:
|
|
statements.append(
|
|
"ALTER TABLE parser_profiles ADD COLUMN kind VARCHAR(50) NOT NULL DEFAULT 'heuristic'"
|
|
)
|
|
if "llm_profile" not in columns:
|
|
statements.append("ALTER TABLE parser_profiles ADD COLUMN llm_profile JSON")
|
|
|
|
if not statements:
|
|
return
|
|
|
|
with engine.begin() as conn:
|
|
for stmt in statements:
|
|
conn.execute(text(stmt))
|