Skip to content

Commit fc14237

Browse files
committed
[wip] docs: add quickstarts for postgres and supabase
1 parent e25bfc9 commit fc14237

File tree

2 files changed

+224
-0
lines changed

2 files changed

+224
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# CloudSync Quick Start: Self-Hosted PostgreSQL
2+
3+
This guide helps you enable CloudSync on a **self-hosted PostgreSQL database**. CloudSync adds offline-first synchronization capabilities to your PostgreSQL database.
4+
5+
## Step 1: Deploy PostgreSQL with CloudSync
6+
7+
Use the pre-built PostgreSQL Docker image that includes the CloudSync extension. This image is available for:
8+
- PostgreSQL 15
9+
- PostgreSQL 17
10+
11+
Example using Docker Compose:
12+
13+
```yaml
14+
services:
15+
db:
16+
image: <cloudsync-postgres-image>
17+
container_name: cloudsync-postgres
18+
environment:
19+
POSTGRES_USER: postgres
20+
POSTGRES_PASSWORD: your-secure-password
21+
POSTGRES_DB: postgres
22+
ports:
23+
- "5432:5432"
24+
volumes:
25+
- pg_data:/var/lib/postgresql/data
26+
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
27+
28+
volumes:
29+
pg_data:
30+
```
31+
32+
Create `init.sql`:
33+
```sql
34+
CREATE EXTENSION IF NOT EXISTS cloudsync;
35+
```
36+
37+
Run:
38+
```bash
39+
docker compose up -d
40+
```
41+
42+
---
43+
44+
## Step 2: Register Your Database in the CloudSync Dashboard
45+
46+
### 2.1 Create a Workspace
47+
48+
1. Log in to the CloudSync dashboard
49+
2. Click **New Workspace**
50+
3. Choose provider: **PostgreSQL**
51+
4. Enter a workspace name
52+
5. Click **Create**
53+
54+
### 2.2 Create a CloudSync Project
55+
56+
1. In the workspace, click **New CloudSync Project**
57+
2. **Project name:** Give it a descriptive name
58+
3. **Connection string:** Enter your PostgreSQL connection:
59+
```
60+
postgresql://user:password@host:5432/database
61+
```
62+
5. Click **Create**
63+
64+
---
65+
66+
## Step 3: Set Up Authentication
67+
68+
### Quick Test with API Key (Recommended for Testing)
69+
70+
The fastest way to test CloudSync without per-user access control — no JWT setup needed.
71+
72+
1. Get your PostgreSQL database credentials (username and password)
73+
2. In your client code (SQLite), authenticate with:
74+
```sql
75+
SELECT cloudsync_network_init('<database-id>');
76+
SELECT cloudsync_network_set_apikey('<username>:<password>');
77+
SELECT cloudsync_network_sync();
78+
```
79+
80+
The API key is simply your PostgreSQL credentials in `username:password` format. No JWT configuration needed.
81+
82+
### Using JWT Tokens (For RLS and Production)
83+
84+
If you need role-based access control (RLS) or production security:
85+
86+
1. **Prepare your JWT authentication:**
87+
- **For HS256 (shared secret):** Use your existing secret, or generate one: `openssl rand -base64 32`
88+
- **For RS256 (asymmetric/JWKS):** Have your auth system's issuer URL and JWKS endpoint ready
89+
2. **Update CloudSync dashboard configuration:**
90+
- Go to your project's **Configuration** tab
91+
- Click **Edit connection settings**
92+
- **For HS256 (shared secret):** Enter your JWT secret
93+
- **For RS256 (asymmetric):** Enter your JWT allowed issuers URL
94+
- Click **Save**
95+
3. **Get JWT tokens** — choose one:
96+
- **Testing only:** [jwt.io](https://jwt.io/) — paste your JWT secret, generate a test token
97+
- **Existing auth system:** Use tokens from your current auth provider
98+
4. **In your client code:**
99+
```sql
100+
SELECT cloudsync_network_init('<database-id>');
101+
SELECT cloudsync_network_set_token('<jwt-token>');
102+
SELECT cloudsync_network_sync();
103+
```
104+
105+
---
106+
107+
## Step 4: Enable CloudSync on Tables
108+
109+
1. In the CloudSync dashboard, go to the **Sync Tables** tab
110+
2. **Select tables** you want to sync (checkbox each table)
111+
3. Click **Deploy Changes**
112+
113+
CloudSync is now active on your selected tables.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# CloudSync Quick Start: Self-Hosted Supabase
2+
3+
This guide helps you enable CloudSync on a **fresh or existing** self-hosted Supabase instance. CloudSync adds offline-first synchronization capabilities to your PostgreSQL database.
4+
5+
## Step 1: Use the Custom PostgreSQL Image with CloudSync
6+
7+
When deploying or updating your Supabase instance, use our custom PostgreSQL image that includes the CloudSync extension instead of the standard Supabase Postgres image.
8+
9+
### For New Deployments
10+
11+
Follow [Supabase's Installing Supabase](https://supabase.com/docs/guides/self-hosting/docker#installing-supabase) guide to set up the initial files and `.env` configuration. Then, instead of using the default Supabase Postgres image, update your `docker-compose.yml`:
12+
13+
```yaml
14+
db:
15+
# PostgreSQL 15
16+
image: <cloudsync-image-15>
17+
# instead of: public.ecr.aws/supabase/postgres:15.8.1.085
18+
19+
# OR PostgreSQL 17
20+
image: <cloudsync-image-17>
21+
# instead of: public.ecr.aws/supabase/postgres:17.6.1.071
22+
```
23+
24+
Then run:
25+
26+
```bash
27+
docker compose pull
28+
docker compose up -d
29+
```
30+
31+
### For Existing Deployments
32+
33+
Follow [Supabase's Updating](https://supabase.com/docs/guides/self-hosting/docker#updating) guide. When updating the Postgres image, replace the default image with the CloudSync-enabled image (will be provided):
34+
35+
```bash
36+
# Update docker-compose.yml with the new CloudSync image
37+
docker compose pull
38+
docker compose down && docker compose up -d
39+
```
40+
41+
---
42+
43+
## Step 2: Register Your Database in the CloudSync Dashboard
44+
45+
### 2.1 Create a Workspace
46+
47+
1. Log in to the CloudSync dashboard
48+
2. Click **New Workspace**
49+
3. Choose provider: **Supabase (Self-hosted)**
50+
4. Enter a workspace name
51+
5. Click **Create**
52+
53+
### 2.2 Create a CloudSync Project
54+
55+
1. In the workspace, click **New CloudSync Project**
56+
2. **Project name:** Give it a descriptive name (e.g., `my-app-sync`)
57+
3. **Connection string:** Enter your PostgreSQL connection:
58+
```
59+
postgresql://user:password@host:5432/database
60+
```
61+
5. Click **Create**
62+
63+
---
64+
65+
## Step 3: Set Up Authentication
66+
67+
### Quick Test with API Key (Recommended for Testing)
68+
69+
The fastest way to test CloudSync without per-user access control — no JWT setup needed.
70+
71+
1. Get your PostgreSQL database credentials (username and password)
72+
2. In your client code (SQLite), authenticate with:
73+
```sql
74+
SELECT cloudsync_network_init('<database-id>');
75+
SELECT cloudsync_network_set_apikey('<username>:<password>');
76+
SELECT cloudsync_network_sync();
77+
```
78+
79+
The API key is simply your PostgreSQL credentials in `username:password` format. No JWT configuration needed.
80+
81+
### Using JWT Tokens (For RLS and Production)
82+
83+
If you need role-based access control (RLS) or production security:
84+
85+
1. **Choose your JWT authentication method:**
86+
- **Default (HS256 - Shared Secret):** Supabase auto-generates `JWT_SECRET` in `.env`
87+
- **GoTrue/JWKS (RS256 - Asymmetric):** Use Supabase's GoTrue service with JWKS endpoint
88+
2. **Configure JWT in the CloudSync dashboard:**
89+
- Go to **Configuration** tab → **Edit connection settings**
90+
- **For HS256:** Enter your **JWT secret** (from `.env`)
91+
- **For RS256/JWKS:** Enter your **JWT allowed issuers** URL
92+
- Click **Save**
93+
3. **Generate JWT tokens:**
94+
- Use [Supabase's built-in authentication](https://supabase.com/docs/guides/auth/jwts) to generate tokens
95+
4. **In your client code:**
96+
```sql
97+
SELECT cloudsync_network_init('<database-id>');
98+
SELECT cloudsync_network_set_token('<jwt-token>');
99+
SELECT cloudsync_network_sync();
100+
```
101+
102+
---
103+
104+
## Step 4: Enable CloudSync on Tables
105+
106+
1. In the CloudSync dashboard, go to the **Tables** tab
107+
2. **Select tables** you want to sync (checkbox each table)
108+
4. Click **Deploy Changes**
109+
110+
CloudSync is now active on your selected tables.
111+

0 commit comments

Comments
 (0)