From 2a87ed82ecc46b94c4284ad54fd745453d6c79c2 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 5 Jun 2024 23:47:13 +0200 Subject: Supabase: Migrations: Update migrations to add table to public schema and add RLS --- .../migrations/20240525164227_create_private_schema.sql | 1 - supabase/migrations/20240525164247_create_file_table.sql | 7 ------- .../migrations/20240528175243_create_api_keys_table.sql | 4 ---- supabase/migrations/20240605214214_create_file_table.sql | 15 +++++++++++++++ .../migrations/20240605214222_create_api_key_table.sql | 12 ++++++++++++ 5 files changed, 27 insertions(+), 12 deletions(-) delete mode 100644 supabase/migrations/20240525164227_create_private_schema.sql delete mode 100644 supabase/migrations/20240525164247_create_file_table.sql delete mode 100644 supabase/migrations/20240528175243_create_api_keys_table.sql create mode 100644 supabase/migrations/20240605214214_create_file_table.sql create mode 100644 supabase/migrations/20240605214222_create_api_key_table.sql diff --git a/supabase/migrations/20240525164227_create_private_schema.sql b/supabase/migrations/20240525164227_create_private_schema.sql deleted file mode 100644 index 2694800..0000000 --- a/supabase/migrations/20240525164227_create_private_schema.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS private; diff --git a/supabase/migrations/20240525164247_create_file_table.sql b/supabase/migrations/20240525164247_create_file_table.sql deleted file mode 100644 index 738a16e..0000000 --- a/supabase/migrations/20240525164247_create_file_table.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE IF NOT EXISTS private."file" ( - id SERIAL PRIMARY KEY, - user_id UUID NOT NULL, - absolute_path VARCHAR(4096) NOT NULL, - contents TEXT, - timestamp TIMESTAMPTZ NOT NULL -); diff --git a/supabase/migrations/20240528175243_create_api_keys_table.sql b/supabase/migrations/20240528175243_create_api_keys_table.sql deleted file mode 100644 index 5efa946..0000000 --- a/supabase/migrations/20240528175243_create_api_keys_table.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE IF NOT EXISTS private.api_keys ( - id UUID NOT NULL REFERENCES auth.users, - api_key CHAR(44) NOT NULL -); diff --git a/supabase/migrations/20240605214214_create_file_table.sql b/supabase/migrations/20240605214214_create_file_table.sql new file mode 100644 index 0000000..75b462f --- /dev/null +++ b/supabase/migrations/20240605214214_create_file_table.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS public."file" ( + id SERIAL PRIMARY KEY, + user_id UUID NOT NULL, + absolute_path VARCHAR(4096) NOT NULL, + contents TEXT, + timestamp TIMESTAMPTZ NOT NULL +); + +ALTER TABLE public."file" ENABLE ROW LEVEL SECURITY; + +CREATE POLICY "Restrict access to user files to their own files" + ON public."file" + FOR SELECT + TO authenticated + USING (user_id = auth.uid()); diff --git a/supabase/migrations/20240605214222_create_api_key_table.sql b/supabase/migrations/20240605214222_create_api_key_table.sql new file mode 100644 index 0000000..ece2226 --- /dev/null +++ b/supabase/migrations/20240605214222_create_api_key_table.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS public."api_key" ( + user_id UUID NOT NULL REFERENCES auth.users, + api_key CHAR(44) NOT NULL +); + +ALTER TABLE public."api_key" ENABLE ROW LEVEL SECURITY; + +CREATE POLICY "Restrict access to user api keys to their own api keys" + ON public."api_key" + FOR SELECT + TO authenticated + USING (user_id = auth.uid()); -- cgit 1.4.1