Skip to main content

MIGRATION_009

Constant MIGRATION_009 

Source
const MIGRATION_009: &str = r#"
-- People table for caching cast/crew members
CREATE TABLE IF NOT EXISTS people (
    id TEXT PRIMARY KEY,
    server_id TEXT NOT NULL,
    name TEXT NOT NULL,
    overview TEXT,
    primary_image_tag TEXT,
    premiere_date TEXT,      -- Birth date
    end_date TEXT,           -- Death date
    synced_at TEXT DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(server_id, id)
);

-- Item-Person association table (many-to-many)
-- Stores which people appear in which items, along with role info
CREATE TABLE IF NOT EXISTS item_people (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    item_id TEXT NOT NULL,
    person_id TEXT NOT NULL,
    server_id TEXT NOT NULL,
    person_type TEXT NOT NULL,  -- Actor, Director, Writer, Producer, Composer, etc.
    role TEXT,                   -- Character name for actors
    sort_order INTEGER DEFAULT 0,
    synced_at TEXT DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(item_id, person_id, person_type)
);

-- Indexes for efficient queries
CREATE INDEX IF NOT EXISTS idx_people_server ON people(server_id);
CREATE INDEX IF NOT EXISTS idx_people_name ON people(name);
CREATE INDEX IF NOT EXISTS idx_item_people_item ON item_people(item_id);
CREATE INDEX IF NOT EXISTS idx_item_people_person ON item_people(person_id);
CREATE INDEX IF NOT EXISTS idx_item_people_type ON item_people(person_type);
"#;
Expand description

Migration to add people/cast caching support

  • Creates people table for caching actor/director/writer/etc info
  • Creates item_people junction table for many-to-many relationships
  • Adds indexes for efficient queries