66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
"""Migration tests for canonical Document metadata."""
|
|
|
|
from pathlib import Path
|
|
|
|
from alembic import command
|
|
from alembic.config import Config
|
|
from sqlalchemy import create_engine, inspect
|
|
|
|
|
|
def test_document_migration_matches_metadata(tmp_path: Path) -> None:
|
|
project_root = Path(__file__).resolve().parents[2]
|
|
database_path = tmp_path / "migration.sqlite3"
|
|
database_url = f"sqlite+pysqlite:///{database_path}"
|
|
config = Config(project_root / "alembic.ini")
|
|
config.attributes["database_url"] = database_url
|
|
|
|
command.upgrade(config, "head")
|
|
command.check(config)
|
|
|
|
inspector = inspect(create_engine(database_url))
|
|
assert {"documents", "chunks", "chunk_index_states", "index_profiles"}.issubset(
|
|
inspector.get_table_names()
|
|
)
|
|
assert {column["name"] for column in inspector.get_columns("documents")} == {
|
|
"id",
|
|
"filename",
|
|
"media_type",
|
|
"size_bytes",
|
|
"storage_key",
|
|
"parsed_storage_key",
|
|
"status",
|
|
"error_message",
|
|
"created_at",
|
|
"updated_at",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("chunks")} == {
|
|
"chunk_id",
|
|
"document_id",
|
|
"filename",
|
|
"page",
|
|
"page_end",
|
|
"section",
|
|
"section_path",
|
|
"chunk_index",
|
|
"content",
|
|
"token_count",
|
|
"strategy_version",
|
|
"created_at",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("chunk_index_states")} == {
|
|
"chunk_id",
|
|
"index_profile_id",
|
|
"embedding_model",
|
|
"vector_dimension",
|
|
"indexed_at",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("index_profiles")} == {
|
|
"profile_id",
|
|
"chunk_strategy_version",
|
|
"embedding_model",
|
|
"vector_dimension",
|
|
"status",
|
|
"created_at",
|
|
"activated_at",
|
|
}
|