mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-16 23:11:27 +00:00
Test caption schema migration
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user