-
Notifications
You must be signed in to change notification settings - Fork 70
docs: add database.sql and sync-rules.yaml to react-supabase-todolist demo #921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JexanJoel
wants to merge
3
commits into
powersync-ja:main
Choose a base branch
from
JexanJoel:fix/react-supabase-todolist-setup-files
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8279e5f
docs: add database.sql and sync-rules.yaml to react-supabase-todolist…
JexanJoel df12eb4
address review: add powersync_role, rename to sync-streams.yaml, upda…
JexanJoel efdc7b2
address review: add powersync_role password note, update sync-streams…
JexanJoel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| -- Create the lists table | ||
| CREATE TABLE IF NOT EXISTS public.lists ( | ||
| id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, | ||
| created_at timestamp with time zone NOT NULL DEFAULT now(), | ||
| name text NOT NULL, | ||
| owner_id uuid NOT NULL REFERENCES auth.users (id) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| -- Create the todos table | ||
| CREATE TABLE IF NOT EXISTS public.todos ( | ||
| id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, | ||
| created_at timestamp with time zone NOT NULL DEFAULT now(), | ||
| completed_at timestamp with time zone, | ||
| description text NOT NULL, | ||
| completed boolean NOT NULL DEFAULT false, | ||
| list_id uuid NOT NULL REFERENCES public.lists (id) ON DELETE CASCADE, | ||
| created_by uuid REFERENCES auth.users (id), | ||
| completed_by uuid REFERENCES auth.users (id) | ||
| ); | ||
|
|
||
| -- Enable Row Level Security | ||
| ALTER TABLE public.lists ENABLE ROW LEVEL SECURITY; | ||
| ALTER TABLE public.todos ENABLE ROW LEVEL SECURITY; | ||
|
|
||
| -- RLS policies for lists: users can only access their own lists | ||
| CREATE POLICY "Users can view their own lists" ON public.lists | ||
| FOR SELECT USING (auth.uid() = owner_id); | ||
|
|
||
| CREATE POLICY "Users can insert their own lists" ON public.lists | ||
| FOR INSERT WITH CHECK (auth.uid() = owner_id); | ||
|
|
||
| CREATE POLICY "Users can update their own lists" ON public.lists | ||
| FOR UPDATE USING (auth.uid() = owner_id); | ||
|
|
||
| CREATE POLICY "Users can delete their own lists" ON public.lists | ||
| FOR DELETE USING (auth.uid() = owner_id); | ||
|
|
||
| -- RLS policies for todos: users can only access todos in their own lists | ||
| CREATE POLICY "Users can view todos in their lists" ON public.todos | ||
| FOR SELECT USING ( | ||
| list_id IN (SELECT id FROM public.lists WHERE owner_id = auth.uid()) | ||
| ); | ||
|
|
||
| CREATE POLICY "Users can insert todos in their lists" ON public.todos | ||
| FOR INSERT WITH CHECK ( | ||
| list_id IN (SELECT id FROM public.lists WHERE owner_id = auth.uid()) | ||
| ); | ||
|
|
||
| CREATE POLICY "Users can update todos in their lists" ON public.todos | ||
| FOR UPDATE USING ( | ||
| list_id IN (SELECT id FROM public.lists WHERE owner_id = auth.uid()) | ||
| ); | ||
|
|
||
| CREATE POLICY "Users can delete todos in their lists" ON public.todos | ||
| FOR DELETE USING ( | ||
| list_id IN (SELECT id FROM public.lists WHERE owner_id = auth.uid()) | ||
| ); | ||
|
|
||
| -- Create PowerSync role for replication access | ||
| -- Note: After creating this role, set a secure password in the Supabase dashboard | ||
| -- or run: ALTER ROLE powersync_role WITH PASSWORD 'your-secure-password'; | ||
| CREATE ROLE powersync_role REPLICATION LOGIN; | ||
| GRANT SELECT ON public.lists TO powersync_role; | ||
| GRANT SELECT ON public.todos TO powersync_role; | ||
|
|
||
| -- Create PowerSync publication | ||
| -- Note: FOR ALL TABLES is simplest for dev. In production, specify tables explicitly. | ||
| CREATE PUBLICATION powersync FOR TABLE public.lists, public.todos; | ||
|
simolus3 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| config: | ||
| edition: 3 | ||
|
|
||
| streams: | ||
| user_data: | ||
| auto_subscribe: true | ||
| queries: | ||
| # Scoped to the authenticated user | ||
| - SELECT * FROM lists WHERE owner_id = auth.user_id() | ||
| - SELECT todos.* FROM todos INNER JOIN lists ON todos.list_id = lists.id WHERE lists.owner_id = auth.user_id() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should also add a note to set a password then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment with instructions to set a password for the role.