| |
| """Create the gateway_answers table in Postgres (separate from eval_cases).""" |
|
|
| from __future__ import annotations |
|
|
| import os |
| import sys |
| from pathlib import Path |
|
|
| REPO_ROOT = Path(__file__).resolve().parent.parent |
| _env_file = REPO_ROOT / ".env" |
| if _env_file.exists(): |
| for raw_line in _env_file.read_text().splitlines(): |
| line = raw_line.strip() |
| if not line or line.startswith("#") or "=" not in line: |
| continue |
| key, value = line.split("=", 1) |
| os.environ.setdefault(key.strip(), value.strip()) |
|
|
| import psycopg |
|
|
| DSN = os.getenv( |
| "AKS_DATABASE_URL", |
| "postgresql+psycopg://mobcoderid-296@localhost/ai_knowledge_spine", |
| ).replace("postgresql+psycopg://", "postgresql://", 1) |
|
|
| CREATE_SQL = (REPO_ROOT / "schemas" / "gateway_answers.sql").read_text() |
|
|
|
|
| def main() -> int: |
| with psycopg.connect(DSN) as conn: |
| with conn.cursor() as cur: |
| for statement in CREATE_SQL.split(";"): |
| stmt = statement.strip() |
| if stmt: |
| cur.execute(stmt) |
| conn.commit() |
| print("OK: gateway_answers table ready.") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|