-- Test runs of an edited (not yet saved) system prompt on one of the admin's -- charts. Kept apart from analyses: never shown to users, never cached, no -- credits, one attempt. Removed after 30 days by the cleanup job. CREATE TABLE prompt_previews ( id uuid PRIMARY KEY, kind text NOT NULL CHECK (kind IN ('summary', 'natal')), chart_id uuid NOT NULL REFERENCES charts ON DELETE CASCADE, language text NOT NULL, model text NOT NULL, system text NOT NULL CHECK (length(system) BETWEEN 1 AND 50000), status text NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'running', 'done', 'failed')), content jsonb, error text, model_used text, input_tokens integer, output_tokens integer, cost_usd double precision, created_by uuid NOT NULL REFERENCES users ON DELETE CASCADE, created_at timestamptz NOT NULL DEFAULT now(), started_at timestamptz, completed_at timestamptz ); CREATE INDEX prompt_previews_pending_idx ON prompt_previews (created_at) WHERE status = 'pending'; -- Wakes the analysis worker, like a new analysis. CREATE TRIGGER prompt_previews_notify AFTER INSERT ON prompt_previews FOR EACH STATEMENT EXECUTE FUNCTION notify_analyses();