Skip to content

Commit cd5a5c8

Browse files
Add local development for YJS demo
1 parent 23eb215 commit cd5a5c8

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
VITE_SUPABASE_URL=
1+
VITE_SUPABASE_URL=http://localhost:54321
22
VITE_SUPABASE_ANON_KEY=
3-
VITE_POWERSYNC_URL=
3+
VITE_POWERSYNC_URL=http://localhost:8080
4+
# Only required for development with a local Supabase instance
5+
PS_SUPABASE_JWT_SECRET=

demos/yjs-react-supabase-text-collab/README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,44 @@ pnpm install
1717
pnpm build:packages
1818
```
1919

20+
### Quick Start: Local Development
21+
22+
This demo can be started with local PowerSync and Supabase services.
23+
24+
Follow the [instructions](https://supabase.com/docs/guides/cli/getting-started) for configuring Supabase locally.
25+
26+
Copy the environment variables template file
27+
28+
```bash
29+
cp .env.template .env.local
30+
```
31+
32+
Start the Supabase project
33+
34+
```bash
35+
supabase start
36+
```
37+
38+
Copy the `anon key` and `JWT secret` into the `.env` file.
39+
40+
Run the PowerSync service with
41+
42+
```bash
43+
docker run \
44+
-p 8080:8080 \
45+
-e POWERSYNC_CONFIG_B64=$(base64 -i ./powersync.yaml) \
46+
-e POWERSYNC_SYNC_RULES_B64=$(base64 -i ./sync-rules.yaml) \
47+
--env-file ./.env \
48+
--network supabase_network_yjs-react-supabase-text-collab \
49+
--name my-powersync journeyapps/powersync-service:latest
50+
```
51+
2052
### 2. Create project on Supabase and set up Postgres
2153

2254
This demo app uses Supabase as its Postgres database and backend:
2355

2456
1. [Create a new project on the Supabase dashboard](https://supabase.com/dashboard/projects).
25-
2. Go to the Supabase SQL Editor for your new project and execute the SQL statements in [`database.sql`](database.sql) to create the database schema, database functions, and publication needed for PowerSync.
57+
2. Go to the Supabase SQL Editor for your new project and execute the SQL statements in [`database.sql`](./supabase/migrations/20250618064101_configure_powersync.sql) to create the database schema, database functions, and publication needed for PowerSync.
2658
3. Enable "anonymous sign-ins" for the project [here](https://supabase.com/dashboard/project/_/auth/providers).
2759

2860
### 3. Create new project on PowerSync and connect to Supabase/Postgres
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# yaml-language-server: $schema=https://unpkg.com/@powersync/service-schema@latest/json-schema/powersync-config.json
2+
3+
# This is a local development configuration file for PowerSync.
4+
5+
# Note that this example uses YAML custom tags for environment variable substitution.
6+
# Using `!env [variable name]` will substitute the value of the environment variable named
7+
# [variable name].
8+
#
9+
# Only environment variables with names starting with `PS_` can be substituted.
10+
#
11+
# If using VS Code see the `.vscode/settings.json` definitions which define custom tags.
12+
13+
# Settings for telemetry reporting
14+
# See https://docs.powersync.com/self-hosting/telemetry
15+
telemetry:
16+
# Opt out of reporting anonymized usage metrics to PowerSync telemetry service
17+
disable_telemetry_sharing: false
18+
19+
# Settings for source database replication
20+
replication:
21+
# Specify database connection details
22+
# Note only 1 connection is currently supported
23+
# Multiple connection support is on the roadmap
24+
connections:
25+
- type: postgresql
26+
# The PowerSync server container can access the Postgres DB via the DB's service name.
27+
# In this case the hostname is pg-db
28+
29+
# The connection URI or individual parameters can be specified.
30+
# Individual params take precedence over URI params
31+
uri: postgresql://postgres:postgres@supabase_db_yjs-react-supabase-text-collab:5432/postgres
32+
33+
# SSL settings
34+
sslmode: disable # 'verify-full' (default) or 'verify-ca' or 'disable'
35+
36+
# This is valid if using the `mongo` service defined in `ps-mongo.yaml`
37+
38+
# Connection settings for sync bucket storage
39+
storage:
40+
# This uses Postgres bucket storage for simplicity
41+
type: postgresql
42+
uri: postgresql://postgres:postgres@supabase_db_yjs-react-supabase-text-collab:5432/postgres
43+
# SSL settings
44+
sslmode: disable # 'verify-full' (default) or 'verify-ca' or 'disable'
45+
46+
# The port which the PowerSync API server will listen on
47+
port: 8080
48+
49+
# Client (application end user) authentication settings
50+
client_auth:
51+
supabase: true
52+
supabase_jwt_secret: !env PS_SUPABASE_JWT_SECRET

demos/yjs-react-supabase-text-collab/supabase/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ enable_refresh_token_rotation = true
7979
refresh_token_reuse_interval = 10
8080
# Allow/disallow new user signups to your project.
8181
enable_signup = true
82+
enable_anonymous_sign_ins = true
83+
8284

8385
[auth.email]
8486
# Allow/disallow new user signups via email to your project.

demos/yjs-react-supabase-text-collab/sync-rules.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# yaml-language-server: $schema=https://unpkg.com/@powersync/service-sync-rules@latest/schema/sync_rules.json
2+
13
# Sync-rule docs: https://docs.powersync.com/usage/sync-rules
24
bucket_definitions:
35
documents:

0 commit comments

Comments
 (0)