The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
wip: add public users, try count subselect for fk constraint
Duncan Healy57dfb99aa094
diff --git a/examples/todo/db/task_list_schema.sql b/examples/todo/db/task_list_schema.sqlindex f0e88996ca9..49e34224e32 100644--- a/examples/todo/db/task_list_schema.sql+++ b/examples/todo/db/task_list_schema.sql@@ -1,3 +1,18 @@+-- users table exists but not able to reference++-- USER PROFILES+CREATE TYPE public.user_status AS ENUM ('ONLINE', 'OFFLINE');+CREATE TABLE public.users (+ id uuid NOT NULL PRIMARY KEY, -- UUID from auth.users (Supabase)+ username text,+ status user_status DEFAULT 'OFFLINE'::public.user_status+);+ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;+CREATE POLICY "Allow logged-in read access" on public.users FOR SELECT USING ( auth.role() = 'authenticated' );+CREATE POLICY "Allow individual insert access" on public.users FOR INSERT WITH CHECK ( auth.uid() = id );+CREATE POLICY "Allow individual update access" on public.users FOR UPDATE USING ( auth.uid() = id );++-- change to uuid primary keyCREATE TABLE lists (@@ -9,7 +24,7 @@ CREATE TABLE lists (CREATE TABLE userlists (userid uuid REFERENCES public.users NOT NULL,- listid uuid REFERENCE lists NOT NULL+ listid uuid REFERENCES lists NOT NULL);ALTER TABLE userlists ENABLE ROW LEVEL SECURITY;@@ -32,8 +47,9 @@ CREATE POLICY "Allow individual update access" on userlists FOR UPDATE USING ( aCREATE POLICY "Allow logged-in full access" on lists FOR ALL USING ( auth.role() = 'authenticated' );-- user should see other tasks in lists they are a member of--CREATE POLICY "Allow logged-in read access" on tasks FOR SELECT USING ( user_id in (SELECT user_id from userlists where userlists.listid=list_id );+-- todo+-- try using count?+CREATE POLICY "Allow logged-in read access" on tasks FOR SELECT USING ( select count(user_id) from (SELECT user_id from userlists where userlists.listid=list_id ) > 0);-- user can update their tasksCREATE POLICY "Allow individual insert access" on tasks FOR INSERT WITH CHECK ( auth.uid() = user_id );CREATE POLICY "Allow individual update access" on tasks FOR UPDATE USING ( auth.uid() = user_id );\ No newline at end of file