Supabase Declarative Schema (#230)
1. Added declarative schemas to Supabase 2. Added Cursor Ignore to ignore some files from Cursor 3. Added Prettier Ignore to ignore some files from Prettier 4. Formatted files so that PG Schema diff won't return any changes
This commit is contained in:
committed by
GitHub
parent
a149c52b99
commit
81f50777ea
50
apps/web/supabase/schemas/16-storage.sql
Normal file
50
apps/web/supabase/schemas/16-storage.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* -------------------------------------------------------
|
||||
* Section: Storage
|
||||
* We create the schema for the storage
|
||||
* -------------------------------------------------------
|
||||
*/
|
||||
|
||||
-- Account Image
|
||||
insert into
|
||||
storage.buckets (id, name, PUBLIC)
|
||||
values
|
||||
('account_image', 'account_image', true);
|
||||
|
||||
-- Function: get the storage filename as a UUID.
|
||||
-- Useful if you want to name files with UUIDs related to an account
|
||||
create
|
||||
or replace function kit.get_storage_filename_as_uuid (name text) returns uuid
|
||||
set
|
||||
search_path = '' as $$
|
||||
begin
|
||||
return replace(storage.filename(name), concat('.',
|
||||
storage.extension(name)), '')::uuid;
|
||||
|
||||
end;
|
||||
|
||||
$$ language plpgsql;
|
||||
|
||||
grant
|
||||
execute on function kit.get_storage_filename_as_uuid (text) to authenticated,
|
||||
service_role;
|
||||
|
||||
-- RLS policies for storage bucket account_image
|
||||
create policy account_image on storage.objects for all using (
|
||||
bucket_id = 'account_image'
|
||||
and (
|
||||
kit.get_storage_filename_as_uuid(name) = auth.uid()
|
||||
or public.has_role_on_account(kit.get_storage_filename_as_uuid(name))
|
||||
)
|
||||
)
|
||||
with check (
|
||||
bucket_id = 'account_image'
|
||||
and (
|
||||
kit.get_storage_filename_as_uuid(name) = auth.uid()
|
||||
or public.has_permission(
|
||||
auth.uid(),
|
||||
kit.get_storage_filename_as_uuid(name),
|
||||
'settings.manage'
|
||||
)
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user