From 30ef38cb0fc4fde4c2e02b05213f86b0636c19fd Mon Sep 17 00:00:00 2001 From: Sleeps Date: Tue, 6 Oct 2026 14:01:36 +0100 Subject: [PATCH] Test caption schema migration --- tests/test_database.py | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test_database.py diff --git a/tests/test_database.py b/tests/test_database.py new file mode 100644 index 0000000..29b8362 --- /dev/null +++ b/tests/test_database.py @@ -0,0 +1,56 @@ +from __future__ import annotations + +import sqlite3 +import tempfile +from pathlib import Path +import unittest + +from scene_search.database import init_db + + +class DatabaseMigrationTests(unittest.TestCase): + def test_existing_frames_table_gains_caption_columns(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "scenes.sqlite3" + con = sqlite3.connect(path) + con.executescript( + """ + CREATE TABLE media ( + id TEXT PRIMARY KEY, + source_path TEXT NOT NULL, + title TEXT NOT NULL, + content_sha256 TEXT NOT NULL, + size_bytes INTEGER NOT NULL, + mtime_ns INTEGER NOT NULL, + interval_ms INTEGER NOT NULL, + model_id TEXT NOT NULL, + embedding_dim INTEGER NOT NULL, + created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP + ); + CREATE TABLE frames ( + id TEXT PRIMARY KEY, + media_id TEXT NOT NULL REFERENCES media(id) ON DELETE CASCADE, + frame_number INTEGER NOT NULL, + timestamp_ms INTEGER NOT NULL, + thumb_path TEXT NOT NULL, + embedding_f16 BLOB NOT NULL, + UNIQUE(media_id, frame_number) + ); + """ + ) + con.close() + + init_db(path) + + con = sqlite3.connect(path) + columns = {row[1] for row in con.execute("PRAGMA table_info(frames)")} + con.close() + + self.assertIn("caption", columns) + self.assertIn("caption_model", columns) + self.assertIn("captioned_at", columns) + + +if __name__ == "__main__": + unittest.main()