-- Allow multiple users to own the same or different versions of a movie.
-- New PK: (hash, user) — one row per file-per-user.
CREATE TABLE IF NOT EXISTS movies_new (
    title              TEXT NOT NULL,
    year               INTEGER NOT NULL,
    size               INTEGER NOT NULL,
    hash               TEXT NOT NULL,
    tmdb_id            INTEGER NULL DEFAULT NULL,
    audio_languages    TEXT NULL DEFAULT NULL,
    subtitle_languages TEXT NULL DEFAULT NULL,
    resolution         TEXT NULL DEFAULT NULL,
    dynamic_range      TEXT NULL DEFAULT NULL,
    bitrate            INTEGER NULL DEFAULT NULL,
    user               TEXT NOT NULL DEFAULT '',
    PRIMARY KEY (hash, user)
);
INSERT OR IGNORE INTO movies_new
    SELECT title, year, size, hash, tmdb_id, audio_languages, subtitle_languages,
           resolution, dynamic_range, bitrate, COALESCE(user, '')
    FROM movies;
DROP TABLE movies;
ALTER TABLE movies_new RENAME TO movies;
