1 · Insert trigger
Every draft is stored as pending
A BEFORE INSERT trigger on slip_proposals forces the status to proposed and clears the decision fields.
It runs for every caller, including the service role the assistants use. A draft that asks to arrive approved is stored as pending anyway.
create or replace function slip_proposals_force_pending()
returns trigger
language plpgsql
set search_path = pg_temp
as $$
begin
new.status := 'proposed';
new.decided_by := null;
new.decided_at := null;
return new;
end;
$$;
create trigger slip_proposals_force_pending_trg
before insert on slip_proposals
for each row
execute function slip_proposals_force_pending();