test(postgres): allow Testcontainers to override the migration sqlalchemy.url

alembic/env.py previously always overwrote sqlalchemy.url from
Settings().postgres.dsn, which made it impossible for a test fixture to
point Alembic at a Testcontainers-managed database. Now env.py only
sets it when unset, and a new integration suite runs `alembic upgrade
head` against a real Postgres container per ADR-0016 (no create_all()).
This commit is contained in:
2026-08-18 10:21:56 +03:30
parent d71dd1bd0c
commit 80ed5b1577
4 changed files with 104 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
import pytest
from sqlalchemy import inspect
from sqlalchemy.ext.asyncio import AsyncEngine
pytestmark = [pytest.mark.integration, pytest.mark.postgres, pytest.mark.asyncio]
EXPECTED_TABLES = {
"tenants",
"api_keys",
"source_files",
"ingestion_jobs",
"ingestion_job_events",
"alembic_version",
}
async def test_migrations_create_schema_from_empty_database(postgres_engine: AsyncEngine) -> None:
async with postgres_engine.connect() as connection:
table_names = await connection.run_sync(
lambda sync_conn: inspect(sync_conn).get_table_names()
)
assert EXPECTED_TABLES.issubset(set(table_names))