alter table public.submissions add column if not exists revision_type text; do $$ begin if not exists ( select 1 from pg_constraint where conname = 'submissions_revision_type_check' and conrelid = 'public.submissions'::regclass ) then alter table public.submissions add constraint submissions_revision_type_check check (revision_type in ('fourge_error', 'client_revision')); end if; end; $$; alter table public.submissions add column if not exists invoiced boolean not null default false; alter table public.invoice_items add column if not exists submission_id uuid references public.submissions(id) on delete set null;