camper/deploy/media_path.sql

24 lines
522 B
PL/PgSQL

-- Deploy camper:media_path to pg
-- requires: roles
-- requires: schema_camper
-- requires: media
begin;
set search_path to camper, public;
create or replace function path(media) returns text as
$$
select '/media/' || encode($1.content_hash, 'hex') || '/' || $1.original_filename;
$$
language sql
stable
;
revoke execute on function path(media) from public;
grant execute on function path(media) to guest;
grant execute on function path(media) to employee;
grant execute on function path(media) to admin;
commit;