Files
bodyshop/hasura/migrations/1608741701614_run_sql_migration/up.yaml

12 lines
672 B
YAML

- args:
cascade: true
read_only: false
sql: "CREATE OR REPLACE FUNCTION public.assign_ibh_number()\r\n RETURNS trigger\r\n
LANGUAGE plpgsql\r\nAS $function$\r\n begin\r\n IF NEW.isinhouse
= true and (new.invoice_number is null or new.invoice_number = '') THEN\r\n
\ UPDATE counters\r\n\tSET count = count + 1\r\n\tfrom bodyshops \r\n\twhere
bodyshops.id = (select shopid from jobs where jobs.id = new.jobid)\r\n\tAND
countertype = 'ihbnum'\r\n\tRETURNING concat(prefix,count) into new.invoice_number;\r\n\r\n
\ END IF;\r\n RETURN NEW;\r\n END;\r\n $function$\r\n;"
type: run_sql