mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-14 22:11:27 +00:00
73 lines
2.8 KiB
Python
73 lines
2.8 KiB
Python
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)
|
|
frame_columns = {row[1] for row in con.execute("PRAGMA table_info(frames)")}
|
|
media_columns = {row[1] for row in con.execute("PRAGMA table_info(media)")}
|
|
indexes = {row[1] for row in con.execute("PRAGMA index_list(media)")}
|
|
con.close()
|
|
|
|
self.assertIn("caption", frame_columns)
|
|
self.assertIn("caption_model", frame_columns)
|
|
self.assertIn("captioned_at", frame_columns)
|
|
self.assertIn("caption_route", frame_columns)
|
|
self.assertIn("caption_route_reason", frame_columns)
|
|
self.assertIn("route_score", frame_columns)
|
|
self.assertIn("route_model", frame_columns)
|
|
self.assertIn("route_policy", frame_columns)
|
|
self.assertIn("routed_at", frame_columns)
|
|
|
|
self.assertIn("source_kind", media_columns)
|
|
self.assertIn("jellyfin_item_id", media_columns)
|
|
self.assertIn("jellyfin_media_source_id", media_columns)
|
|
self.assertIn("jellyfin_library_id", media_columns)
|
|
self.assertIn("jellyfin_tags", media_columns)
|
|
self.assertIn("trickplay_width", media_columns)
|
|
self.assertIn("idx_media_jellyfin_item", indexes)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|