123 lines
3.5 KiB
Python
123 lines
3.5 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, text
|
|
|
|
|
|
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
|
|
|
|
# The production OceanBase database is shared. A foreign table must survive
|
|
# migration and remain outside Alembic's autogenerate/drift ownership.
|
|
with create_engine(database_url).begin() as connection:
|
|
connection.execute(text("CREATE TABLE unrelated_provider_table (id INTEGER PRIMARY KEY)"))
|
|
|
|
command.upgrade(config, "head")
|
|
command.check(config)
|
|
|
|
inspector = inspect(create_engine(database_url))
|
|
assert {
|
|
"documents",
|
|
"chunks",
|
|
"chunk_index_states",
|
|
"index_profiles",
|
|
"ingestion_jobs",
|
|
"ingestion_attempts",
|
|
"ingestion_batches",
|
|
"ingestion_batch_items",
|
|
}.issubset(inspector.get_table_names())
|
|
assert "unrelated_provider_table" in 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",
|
|
"active_marker",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("ingestion_jobs")} == {
|
|
"id",
|
|
"document_id",
|
|
"status",
|
|
"stage",
|
|
"attempt_count",
|
|
"max_attempts",
|
|
"error_message",
|
|
"next_run_at",
|
|
"lease_expires_at",
|
|
"created_at",
|
|
"updated_at",
|
|
"completed_at",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("ingestion_attempts")} == {
|
|
"id",
|
|
"job_id",
|
|
"attempt_number",
|
|
"status",
|
|
"stage",
|
|
"retryable",
|
|
"error_message",
|
|
"active_marker",
|
|
"started_at",
|
|
"finished_at",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("ingestion_batches")} == {
|
|
"id",
|
|
"total_files",
|
|
"created_at",
|
|
}
|
|
assert {column["name"] for column in inspector.get_columns("ingestion_batch_items")} == {
|
|
"id",
|
|
"batch_id",
|
|
"item_index",
|
|
"filename",
|
|
"acceptance_status",
|
|
"document_id",
|
|
"job_id",
|
|
"error_message",
|
|
"created_at",
|
|
"updated_at",
|
|
}
|