Skip to content

Update Privileges required - Self-hosted / Custom roles Section #204

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions installation/database-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ We have documented steps for some hosting providers:
<Frame>
![](/images/setup-2.png)
</Frame>

### 2. Create a PowerSync database user

Create a PowerSync user on Postgres:

```sql
-- SQL to create powersync user
CREATE ROLE powersync_role WITH BYPASSRLS LOGIN PASSWORD 'myhighlyrandompassword';

-- Allow the role to perform replication tasks
GRANT rds_replication TO powersync_role;

-- Set up permissions for the newly created role
-- Read-only (SELECT) access is required
GRANT SELECT ON ALL TABLES IN SCHEMA public TO powersync_role;
Expand Down Expand Up @@ -168,10 +168,10 @@ We have documented steps for some hosting providers:
```sql
-- Create a publication to replicate tables.
-- PlanetScale does not support ON ALL TABLES so
-- Specify each table you want to sync
-- Specify each table you want to sync
-- The publication must be named "powersync"
CREATE PUBLICATION powersync
FOR TABLE public.lists, public.todos;
FOR TABLE public.lists, public.todos;
```
</Accordion>
</AccordionGroup>
Expand All @@ -195,11 +195,11 @@ For other providers and self-hosted databases:

```sql
-- Check the replication type

SHOW wal_level;

-- Ensure logical replication is enabled

ALTER SYSTEM SET wal_level = logical;
```

Expand Down Expand Up @@ -254,13 +254,13 @@ readAnyDatabase@admin
For self-hosted MongoDB, or for creating custom roles on MongoDB Atlas, PowerSync requires the following privileges/granted actions:

- On the database being replicated: `listCollections`
- On all collections in the database: `changeStream`
- This must apply to the entire database, not individual collections. Specify `collection: ""`
- If replicating from multiple databases, this must apply to the entire cluster. Specify `db: ""`
- On each collection being replicated: `find`
- On the database and any collections being replicated: `find`
- On the database and any collections being replicated: `changeStream`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears contradictory to "not individual collections" below - perhaps we can just make this "on the database being replicated"? Or is there a better way to indicate the difference between "find" (can be on the db-level or individual collections) and "changeStream" (must be on the db-level)?

- This must apply to the entire database, not individual collections. Specify `collection: ""` or by checking the `Apply to any collection` checkbox in the MongoDB Atlas.
- If replicating from multiple databases, this must apply to the entire cluster. Specify `db: ""` or by checking the `Apply to any database` checkbox in MongoDB Atlas.
- On the `_powersync_checkpoints` collection: `createCollection`, `dropCollection`, `find`, `changeStream`, `insert`, `update`, and `remove`
- To allow PowerSync to automatically enable [`changeStreamPreAndPostImages`](#post-images) on
replicated collections, additionally add the `collMod` permission on all replicated collections.
replicated collections, additionally add the `collMod` permission on the database and all collections being replicated.

### Post-Images

Expand Down Expand Up @@ -352,4 +352,4 @@ Next, connect PowerSync to your database:
<Card title="For Self-Hosted PowerSync:" href="/self-hosting/installation/powersync-service-setup#powersync-configuration">
Refer to **PowerSync Service Setup** in the Self-Hosting section.
</Card>
</CardGroup>
</CardGroup>