-- Subtitle cache table to avoid filesystem glob on every detail request
CREATE TABLE IF NOT EXISTS media_subtitles (
    id BIGSERIAL PRIMARY KEY,
    media_file_id BIGINT NOT NULL REFERENCES media_files(id) ON DELETE CASCADE,
    file_name TEXT NOT NULL,
    language TEXT NOT NULL,
    language_code TEXT NOT NULL,
    hi BOOLEAN NOT NULL DEFAULT false,
    forced BOOLEAN NOT NULL DEFAULT false,
    source TEXT NOT NULL DEFAULT 'downloaded',
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_media_subtitles_file ON media_subtitles (media_file_id);
