|
| 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