39 lines
1.1 KiB
Python
39 lines
1.1 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",
|
||
|
|
"repositories",
|
||
|
|
"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"}
|