-- =====================================================================
-- RENDER SCHEMA — scene snapshot jobs
-- Async "render one frame per scene from After Effects" jobs. A node claims a
-- queued snapshot, runs aerender for the scene's comp at a single frame, uploads
-- the still to object storage, and posts back the image URL. render-svc then
-- writes it onto content.scenes.snapshot_url (same DB, cross-schema) so the
-- studio scene bar + admin show a real thumbnail.
-- =====================================================================

SET search_path TO render, public;

CREATE TABLE IF NOT EXISTS snapshot_jobs (
    id          UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    project_id  UUID NOT NULL,               -- content project (template variant)
    scene_id    UUID NOT NULL,               -- content scene the snapshot belongs to
    scene_key   TEXT NOT NULL,
    comp_name   TEXT NOT NULL DEFAULT '',     -- AE comp to render (scene key / render comp)
    frame       INT  NOT NULL DEFAULT 0,      -- frame to capture
    status      TEXT NOT NULL DEFAULT 'queued', -- queued | running | done | error
    node_id     UUID,
    image_url   TEXT,
    error       TEXT,
    created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_snapshot_jobs_status  ON snapshot_jobs(status, created_at);
CREATE INDEX IF NOT EXISTS idx_snapshot_jobs_project ON snapshot_jobs(project_id, created_at DESC);
