Skip to content

Instantly share code, notes, and snippets.

@cazzer
Created December 6, 2018 21:30
Show Gist options
  • Save cazzer/a69d59c2db0d51fec70c9db379f36911 to your computer and use it in GitHub Desktop.
Save cazzer/a69d59c2db0d51fec70c9db379f36911 to your computer and use it in GitHub Desktop.
create role application_user;
grant all on all table in schema public to application_user;
create policy thing_owner
on things
as permissive
for all
to application_user
using (
exists(
select thing_id
from permissions
where (
permissions.user_id = current_setting('user_id')::uuid
and permissions.item_id = items.id
)
)
)
with check (
exists(
select item_id
from permissions
where (
permissions.user_id = current_setting('user_id')::uuid
and permissions.item_id = items.id
)
)
);
create policy new_thing
on things
as permissive
for insert
to application_user
with check (true);
alter table things enable row level security;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment