from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[1] UP_MIGRATION = PROJECT_ROOT / "migrations" / "0001_asset_mapping.up.sql" DOWN_MIGRATION = PROJECT_ROOT / "migrations" / "0001_asset_mapping.down.sql" def normalized_sql(path: Path) -> str: return " ".join(path.read_text(encoding="utf-8").lower().split()) def test_asset_mapping_up_migration_has_minimal_idempotent_schema() -> None: assert UP_MIGRATION.exists(), "asset_mapping up migration is missing" sql = normalized_sql(UP_MIGRATION) assert "create table if not exists asset_mapping" in sql assert "asset_id uuid primary key" in sql assert "source_ref text not null" in sql assert "object_key text not null" in sql assert "content_type text" in sql assert "created_at timestamptz not null default current_timestamp" in sql assert "status text not null default 'active'" in sql assert "check (status in ('active', 'disabled'))" in sql assert "create unique index if not exists" in sql assert "on asset_mapping (source_ref)" in sql for forbidden_identifier in ( "presigned_url", "access_key", "secret_key", "authorization", "bucket", ): assert forbidden_identifier not in sql def test_asset_mapping_down_migration_is_idempotent_and_scoped() -> None: assert DOWN_MIGRATION.exists(), "asset_mapping down migration is missing" sql = normalized_sql(DOWN_MIGRATION) assert sql == "drop table if exists asset_mapping;"