camper/deploy/add_campsite_carousel_slide...

30 lines
902 B
PL/PgSQL

-- Deploy camper:add_campsite_carousel_slide to pg
-- requires: roles
-- requires: schema_camper
-- requires: campsite
-- requires: campsite_carousel
begin;
set search_path to camper, public;
create or replace function add_campsite_carousel_slide(company_id integer, label text, media_id integer, caption text) returns integer as
$$
insert into campsite_carousel (campsite_id, media_id, caption)
select campsite_id, media_id, coalesce(caption, '')
from campsite
where label = add_campsite_carousel_slide.label
and company_id = add_campsite_carousel_slide.company_id
on conflict (campsite_id, media_id) do update
set caption = excluded.caption
returning campsite_id
;
$$
language sql
;
revoke execute on function add_campsite_carousel_slide(integer, text, integer, text) from public;
grant execute on function add_campsite_carousel_slide(integer, text, integer, text) to admin;
commit;