Test caption schema migration

This commit is contained in:
Sleeps
2026-10-06 14:01:36 +01:00
parent d2bdbbd01c
commit 30ef38cb0f
+56
View File
@@ -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()