-- ============================================================
-- Migration: Add revision billing tracking
-- Run in Supabase → SQL Editor → Run
-- ============================================================

-- Add revision_type and invoiced to submissions
alter table public.submissions
  add column revision_type text check (revision_type in ('fourge_error', 'client_revision'));

alter table public.submissions
  add column invoiced boolean not null default false;

-- Add submission_id to invoice_items (links a line item to a specific revision)
alter table public.invoice_items
  add column submission_id uuid references public.submissions(id) on delete set null;
