US01-04: Detect and Decide Duplicates (#49)

This commit was merged in pull request #49.
This commit is contained in:
2026-07-15 17:14:24 +02:00
parent c25d45d8f7
commit 691d5a5651
9 changed files with 1137 additions and 4 deletions

View File

@@ -7,6 +7,16 @@ import pytest
from photo_pipeline.db import run_migrations
def _alembic_head() -> str:
from alembic.config import Config as AlembicConfig
from alembic.script import ScriptDirectory
repo = Path(__file__).resolve().parents[2]
cfg = AlembicConfig(str(repo / "alembic.ini"))
cfg.set_main_option("script_location", str(repo / "migrations"))
return ScriptDirectory.from_config(cfg).get_current_head()
# Faithful snapshot of the donor photo_analyzer.py schema (photos + FTS + triggers).
LEGACY_SCHEMA = """
CREATE TABLE photos (
@@ -50,7 +60,7 @@ def test_migrations_from_empty_database(tmp_path):
tables = _tables(db)
assert {"assets", "asset_paths"} <= tables
assert _head_revision(db) == "0001_initial_identity"
assert _head_revision(db) == _alembic_head()
def test_migrations_from_legacy_snapshot_preserve_existing_data(tmp_path):
@@ -75,7 +85,7 @@ def test_migrations_from_legacy_snapshot_preserve_existing_data(tmp_path):
finally:
conn.close()
assert row == ("album/one.jpg", "analyzed", "a red block")
assert _head_revision(db) == "0001_initial_identity"
assert _head_revision(db) == _alembic_head()
def test_migrations_are_idempotent(tmp_path):
@@ -83,7 +93,7 @@ def test_migrations_are_idempotent(tmp_path):
url = f"sqlite:///{db}"
run_migrations(url)
run_migrations(url) # second run is a no-op at head
assert _head_revision(db) == "0001_initial_identity"
assert _head_revision(db) == _alembic_head()
@pytest.mark.parametrize("expected", ["assets", "asset_paths"])