-- Deploy numerus:add_payment_account_bank to pg -- requires: roles -- requires: schema_numerus -- requires: payment_account -- requires: payment_account_bank begin; set search_path to numerus, public; create or replace function add_payment_account_bank(company integer, name text, iban iban) returns uuid as $$ declare account_id integer; account_slug uuid; begin insert into payment_account (company_id, payment_account_type, name) select company, 'bank', add_payment_account_bank.name returning payment_account_id, slug into account_id, account_slug; insert into payment_account_bank (payment_account_id, iban) values (account_id, iban) ; return account_slug; end; $$ language plpgsql ; revoke execute on function add_payment_account_bank(integer, text, iban) from public; grant execute on function add_payment_account_bank(integer, text, iban) to invoicer; grant execute on function add_payment_account_bank(integer, text, iban) to admin; commit;