-- The clip studio's library: standalone b-roll and hook clips generated outside -- the full ad pipeline, kept so an expensive clip survives closing the tab. -- -- Run this once in the Supabase SQL editor. Until you do, generation still works -- and returns a playable clip — app/services/clip_studio.py logs a warning and -- skips the record, so only the library list comes back empty. create table if not exists generated_clips ( id uuid primary key default gen_random_uuid(), kind text not null, -- broll | hook prompt text not null, -- the prompt actually sent to the video model spoken text, -- the voiced line (hooks always; b-roll never) duration numeric, -- seconds of the finished clip file_name text not null, -- storage key, for a playable URL niche text, -- Where it came from, so a clip can be traced back to the row it varied. source_table text, -- broll | hooks | null for a free prompt source_id uuid, -- Which variation of a batch this was (1-based), so a set reads in order. variation smallint not null default 1, voice text, -- the cast narrator, for hooks has_audio boolean not null default false, -- Alternative openings written alongside a hook, so one visual can be tested -- against several pieces of copy. Same list on every clip of a batch. alt_lines text[], created_at timestamptz not null default now() ); -- Safe to re-run if you created the table before alt_lines existed. alter table generated_clips add column if not exists alt_lines text[]; -- The library lists newest-first, optionally filtered to one kind. create index if not exists generated_clips_recent_idx on generated_clips (created_at desc); create index if not exists generated_clips_kind_idx on generated_clips (kind, created_at desc); -- The API talks to Supabase with the service-role key, which bypasses RLS. If you -- later expose this table to anon/authenticated clients, enable RLS first: -- alter table generated_clips enable row level security;