Files
FabledCurator/tests/test_migration_0002.py
T
bvandeusen 9eb1614fbf feat(fc2a): schema migration 0002 — tag kinds + fandom hierarchy + import lifecycle
Adds Tag.kind enum (artist/character/fandom/general/series/archive/post/meta/rating),
Tag.fandom_id FK with CHECK constraint (only valid for kind='character'), and a
kind-aware uniqueness index so the same name can exist across kinds and the same
character name can exist in different fandoms.

Adds ImportBatch + ImportTask state-machine tables for scan tracking, plus a
single-row ImportSettings table (CHECK id=1) holding the importer's filter knobs.

Adds image_record.integrity_status column (defaults to 'unknown'); FC-2e
populates this via the integrity verifier.

Drops the unused tag.namespace column from FC-1 — superseded by kind.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 12:03:41 -04:00

57 lines
1.4 KiB
Python

"""Smoke test for migration 0002: confirms model classes import and the
tag-kind uniqueness rule shape is correct.
"""
from backend.app.models import (
Base,
ImportBatch,
ImportSettings,
ImportTask,
Tag,
TagKind,
)
def test_new_tables_registered():
expected = {"import_batch", "import_task", "import_settings"}
assert expected.issubset(Base.metadata.tables.keys())
def test_tag_has_kind_and_fandom_id():
cols = {c.name for c in Tag.__table__.columns}
assert "kind" in cols
assert "fandom_id" in cols
assert "namespace" not in cols
def test_tag_kind_enum_values():
expected = {
"artist",
"character",
"fandom",
"general",
"series",
"archive",
"post",
"meta",
"rating",
}
assert {k.value for k in TagKind} == expected
def test_image_record_has_integrity_status():
from backend.app.models import ImageRecord
cols = {c.name for c in ImageRecord.__table__.columns}
assert "integrity_status" in cols
def test_import_task_has_state_columns():
cols = {c.name for c in ImportTask.__table__.columns}
for required in ("batch_id", "source_path", "task_type", "status", "result_image_id"):
assert required in cols
def test_import_settings_singleton_constraint():
constraints = {c.name for c in ImportSettings.__table__.constraints}
assert "ck_import_settings_singleton" in constraints