686434f5c3
- delete server/services/jellyfin.ts, webhook.ts, mqtt.ts and their tests - strip jellyfin/mqtt imports and startup calls from index.tsx and settings.ts - remove /jellyfin, /mqtt, /mqtt/status, /mqtt/test, /jellyfin/webhook-plugin endpoints from settings router - clean ENV_MAP and isEnvConfigured of jellyfin/mqtt keys - add db/index.ts migrations for series_key, duration_seconds, scan_status, scan_error, last_scanned_at (new columns absent on older dev DBs) - move idx_media_items_series_key out of SCHEMA into migrate() so it runs after the column is added - fix all test fixtures: drop jellyfin_id/series_jellyfin_id column refs, update MediaItem/MediaStream object literals to match current types Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
130 lines
4.3 KiB
TypeScript
130 lines
4.3 KiB
TypeScript
export const SCHEMA = `
|
|
PRAGMA journal_mode = WAL;
|
|
PRAGMA foreign_keys = ON;
|
|
|
|
CREATE TABLE IF NOT EXISTS config (
|
|
key TEXT PRIMARY KEY NOT NULL,
|
|
value TEXT
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS media_items (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
file_path TEXT NOT NULL UNIQUE,
|
|
type TEXT NOT NULL,
|
|
name TEXT NOT NULL,
|
|
series_name TEXT,
|
|
series_key TEXT,
|
|
season_number INTEGER,
|
|
episode_number INTEGER,
|
|
year INTEGER,
|
|
file_size INTEGER,
|
|
container TEXT,
|
|
duration_seconds REAL,
|
|
original_language TEXT,
|
|
orig_lang_source TEXT,
|
|
needs_review INTEGER NOT NULL DEFAULT 1,
|
|
imdb_id TEXT,
|
|
tmdb_id TEXT,
|
|
tvdb_id TEXT,
|
|
scan_status TEXT NOT NULL DEFAULT 'pending',
|
|
scan_error TEXT,
|
|
last_scanned_at TEXT,
|
|
last_executed_at TEXT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS media_streams (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
item_id INTEGER NOT NULL REFERENCES media_items(id) ON DELETE CASCADE,
|
|
stream_index INTEGER NOT NULL,
|
|
type TEXT NOT NULL,
|
|
codec TEXT,
|
|
profile TEXT,
|
|
language TEXT,
|
|
title TEXT,
|
|
is_default INTEGER NOT NULL DEFAULT 0,
|
|
is_forced INTEGER NOT NULL DEFAULT 0,
|
|
is_hearing_impaired INTEGER NOT NULL DEFAULT 0,
|
|
channels INTEGER,
|
|
channel_layout TEXT,
|
|
bit_rate INTEGER,
|
|
sample_rate INTEGER,
|
|
bit_depth INTEGER,
|
|
UNIQUE(item_id, stream_index)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS review_plans (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
item_id INTEGER NOT NULL UNIQUE REFERENCES media_items(id) ON DELETE CASCADE,
|
|
status TEXT NOT NULL DEFAULT 'pending',
|
|
is_noop INTEGER NOT NULL DEFAULT 0,
|
|
auto_class TEXT,
|
|
sorted INTEGER NOT NULL DEFAULT 0,
|
|
apple_compat TEXT,
|
|
job_type TEXT NOT NULL DEFAULT 'copy',
|
|
subs_extracted INTEGER NOT NULL DEFAULT 0,
|
|
notes TEXT,
|
|
reviewed_at TEXT,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS stream_decisions (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
plan_id INTEGER NOT NULL REFERENCES review_plans(id) ON DELETE CASCADE,
|
|
stream_id INTEGER NOT NULL REFERENCES media_streams(id) ON DELETE CASCADE,
|
|
action TEXT NOT NULL,
|
|
target_index INTEGER,
|
|
custom_title TEXT,
|
|
custom_language TEXT,
|
|
transcode_codec TEXT,
|
|
UNIQUE(plan_id, stream_id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS jobs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
item_id INTEGER NOT NULL REFERENCES media_items(id) ON DELETE CASCADE,
|
|
command TEXT NOT NULL,
|
|
job_type TEXT NOT NULL DEFAULT 'copy',
|
|
status TEXT NOT NULL DEFAULT 'pending',
|
|
output TEXT,
|
|
exit_code INTEGER,
|
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
started_at TEXT,
|
|
completed_at TEXT
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_review_plans_status ON review_plans(status);
|
|
CREATE INDEX IF NOT EXISTS idx_review_plans_is_noop ON review_plans(is_noop);
|
|
CREATE INDEX IF NOT EXISTS idx_stream_decisions_plan_id ON stream_decisions(plan_id);
|
|
CREATE INDEX IF NOT EXISTS idx_media_items_series_name ON media_items(series_name);
|
|
CREATE INDEX IF NOT EXISTS idx_media_items_type ON media_items(type);
|
|
CREATE INDEX IF NOT EXISTS idx_media_streams_item_id ON media_streams(item_id);
|
|
CREATE INDEX IF NOT EXISTS idx_media_streams_type ON media_streams(type);
|
|
CREATE INDEX IF NOT EXISTS idx_jobs_status ON jobs(status);
|
|
CREATE INDEX IF NOT EXISTS idx_jobs_item_id ON jobs(item_id);
|
|
`;
|
|
|
|
export const DEFAULT_CONFIG: Record<string, string> = {
|
|
setup_complete: "0",
|
|
movies_root: "/movies",
|
|
tv_root: "/tv",
|
|
radarr_url: "",
|
|
radarr_api_key: "",
|
|
radarr_enabled: "0",
|
|
sonarr_url: "",
|
|
sonarr_api_key: "",
|
|
sonarr_enabled: "0",
|
|
audio_languages: "[]",
|
|
auto_processing: "0",
|
|
auto_process_queue: "0",
|
|
|
|
scan_running: "0",
|
|
job_sleep_seconds: "0",
|
|
scan_schedule_enabled: "0",
|
|
scan_schedule_start: "01:00",
|
|
scan_schedule_end: "07:00",
|
|
process_schedule_enabled: "0",
|
|
process_schedule_start: "01:00",
|
|
process_schedule_end: "07:00",
|
|
};
|