28 lines
765 B
PL/PgSQL
28 lines
765 B
PL/PgSQL
-- Deploy camper:add_media to pg
|
|
-- requires: roles
|
|
-- requires: schema_camper
|
|
-- requires: media
|
|
-- requires: media_type
|
|
|
|
begin;
|
|
|
|
set search_path to camper, public;
|
|
|
|
create or replace function add_media(company integer, filename text, media_type media_type, content bytea) returns integer as
|
|
$$
|
|
insert into media (company_id, original_filename, media_type, content)
|
|
values (company, filename, media_type, content)
|
|
on conflict (company_id, hash) do update
|
|
set original_filename = excluded.original_filename
|
|
, media_type = excluded.media_type
|
|
returning media_id
|
|
;
|
|
$$
|
|
language sql
|
|
;
|
|
|
|
revoke execute on function add_media(integer, text, media_type, bytea) from public;
|
|
grant execute on function add_media(integer, text, media_type, bytea) to admin;
|
|
|
|
commit;
|