File size: 835 Bytes
6910834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
database/migrate.py

Runs database/migrations.sql against the configured Postgres (Railway).
Idempotent — uses IF NOT EXISTS / ADD COLUMN IF NOT EXISTS throughout.

Run once after pulling the human-in-the-loop changes:
    python -m database.migrate
"""

from __future__ import annotations

from pathlib import Path

from database.schema import get_conn, get_cursor


SQL_PATH = Path(__file__).parent / "migrations.sql"


def run_migrations() -> None:
    sql = SQL_PATH.read_text()
    print(f"[migrate] applying {SQL_PATH.name} ...")
    with get_conn() as conn:
        with get_cursor(conn) as cur:
            cur.execute(sql)
    print("[migrate] done. Added: query_logs.{session_id,retrieved_docs,"
          "source_titles,source_urls,parent_query_id}, table feedback.")


if __name__ == "__main__":
    run_migrations()