generated from kgod/ai-review-template
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from uuid import uuid4
|
|
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
from sqlalchemy import create_engine, text
|
|
|
|
|
|
def test_alembic_upgrade_creates_core_postgres_schema() -> None:
|
|
schema = f"test_alembic_{uuid4().hex}"
|
|
database_url = os.environ["RESUME_AGENT_TEST_DATABASE_URL"]
|
|
config = Config(str(Path(__file__).resolve().parents[1] / "alembic.ini"))
|
|
config.set_main_option("sqlalchemy.url", database_url)
|
|
config.set_main_option("resume_agent.schema", schema)
|
|
|
|
command.upgrade(config, "head")
|
|
|
|
engine = create_engine(database_url)
|
|
try:
|
|
with engine.connect() as connection:
|
|
tables = connection.execute(
|
|
text(
|
|
"SELECT tablename FROM pg_tables "
|
|
"WHERE schemaname = :schema ORDER BY tablename"
|
|
),
|
|
{"schema": schema},
|
|
).scalars().all()
|
|
assert tables == [
|
|
"alembic_version",
|
|
"blocks",
|
|
"optimization_runs",
|
|
"resume_imports",
|
|
"resumes",
|
|
"sessions",
|
|
"turns",
|
|
]
|
|
finally:
|
|
with engine.begin() as connection:
|
|
connection.execute(text(f'DROP SCHEMA IF EXISTS "{schema}" CASCADE'))
|
|
engine.dispose()
|