All checks were successful
Build and Publish Container Image / build-and-push (push) Successful in 38s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02b22-9638-76d2-bbff-b7ea1770b118
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
|
|
def migration_config(database_path: Path) -> Config:
|
|
config = Config("alembic.ini")
|
|
config.set_main_option("sqlalchemy.url", f"sqlite:///{database_path}")
|
|
return config
|
|
|
|
|
|
def test_initial_migration_upgrades_and_downgrades(tmp_path: Path) -> None:
|
|
database_path = tmp_path / "migrated.db"
|
|
config = migration_config(database_path)
|
|
|
|
command.upgrade(config, "head")
|
|
|
|
engine = create_engine(f"sqlite:///{database_path}")
|
|
assert set(inspect(engine).get_table_names()) == {
|
|
"alembic_version",
|
|
"entries",
|
|
"operation_receipts",
|
|
"repositories",
|
|
"snapshots",
|
|
}
|
|
assert "source_ref_json" in {
|
|
column["name"] for column in inspect(engine).get_columns("repositories")
|
|
}
|
|
assert "source_provenance_json" in {
|
|
column["name"] for column in inspect(engine).get_columns("snapshots")
|
|
}
|
|
assert {index["name"] for index in inspect(engine).get_indexes("entries")} == {
|
|
"ix_entries_license",
|
|
"ix_entries_repo",
|
|
"ix_entries_snapshot",
|
|
}
|
|
command.check(config)
|
|
|
|
command.downgrade(config, "base")
|
|
|
|
assert set(inspect(engine).get_table_names()) == {"alembic_version"}
|