|
| 1 | +# Supabase Setup |
| 2 | + |
| 3 | +We use a local Postgres instance **or** Supabase as the local database (managed via Prisma) and Supabase for storage (media uploads). In production, we deploy to Supabase Postgres. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Docker running locally |
| 8 | + - Docker desktop is easiest to setup and run: https://www.docker.com/products/docker-desktop/ |
| 9 | + - Features a nice GUI, works on all platforms |
| 10 | + - For WSL users: install on Windows and enable WSL integration in Docker desktop settings |
| 11 | + - Alternatively, you can install any Docker engine: https://docs.docker.com/engine/install/ |
| 12 | + |
| 13 | +## Local Development |
| 14 | + |
| 15 | +### 1. Start Supabase |
| 16 | + |
| 17 | +```bash |
| 18 | +npx supabase start |
| 19 | +``` |
| 20 | + |
| 21 | +If Docker is running, Supabase will begin creating a local instance of the necessary services. On success, it should output something like: |
| 22 | + |
| 23 | +``` |
| 24 | +╭─────────────────────────────────────────────────╮ |
| 25 | +│ 🌐 APIs │ |
| 26 | +├─────────────┬───────────────────────────────────┤ |
| 27 | +│ Project URL │ http://127.0.0.1:54321 │ |
| 28 | +│ REST │ http://127.0.0.1:54321/rest/v1 │ |
| 29 | +│ GraphQL │ http://127.0.0.1:54321/graphql/v1 │ |
| 30 | +╰─────────────┴───────────────────────────────────╯ |
| 31 | +
|
| 32 | +╭───────────────────────────────────────────────────────────────╮ |
| 33 | +│ ⛁ Database │ |
| 34 | +├─────┬─────────────────────────────────────────────────────────┤ |
| 35 | +│ URL │ postgresql://postgres:postgres@127.0.0.1:54322/postgres │ |
| 36 | +╰─────┴─────────────────────────────────────────────────────────╯ |
| 37 | +
|
| 38 | +╭──────────────────────────────────────────────────────────────╮ |
| 39 | +│ 🔑 Authentication Keys │ |
| 40 | +├─────────────┬────────────────────────────────────────────────┤ |
| 41 | +│ Publishable │ sb_publishable_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX │ |
| 42 | +│ Secret │ sb_secret_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX │ |
| 43 | +╰─────────────┴────────────────────────────────────────────────╯ |
| 44 | +``` |
| 45 | + |
| 46 | +These credentials are also accessible again via `npx supabase status` if you need to reference them later. |
| 47 | + |
| 48 | +### 2. Configure environment variables |
| 49 | + |
| 50 | +In your `.env` copy the "Project URL" to `SUPABASE_URL`, and the "Secret" to `SUPABASE_SERVICE_ROLE_KEY`. |
| 51 | + |
| 52 | +For `DATABASE_URL`, you may use a locally managed instance, or use the Database "URL". Append `?schema=public` to ensure Prisma uses the public schema. |
| 53 | + |
| 54 | +```env |
| 55 | +DATABASE_URL="postgresql://postgres:postgres@127.0.0.1:54322/postgres?schema=public" |
| 56 | +SUPABASE_URL="http://127.0.0.1:54321" |
| 57 | +SUPABASE_SERVICE_ROLE_KEY="sb_secret_XXXXXXXXX" |
| 58 | +``` |
| 59 | + |
| 60 | +### 3. Run Prisma migrations |
| 61 | + |
| 62 | +```bash |
| 63 | +npx prisma migrate dev |
| 64 | +``` |
| 65 | + |
| 66 | +This will apply the Prisma schema to your local database. You can also use `npx prisma studio` to view and manage your database records in a nice UI. |
| 67 | + |
| 68 | +## Resetting the database |
| 69 | +If you want to reset your database (e.g. to clear all data), you can run: |
| 70 | + |
| 71 | +```bash |
| 72 | +npx prisma migrate reset |
| 73 | +``` |
| 74 | + |
| 75 | +## Stopping Supabase |
| 76 | + |
| 77 | +```bash |
| 78 | +npx supabase stop |
| 79 | +``` |
| 80 | + |
| 81 | +## Configuration |
| 82 | + |
| 83 | +The config lives in `supabase/config.toml`. |
| 84 | + |
| 85 | +- DB: Enabled — used by both application and storage |
| 86 | +- Storage: Enabled with a public `media` bucket |
| 87 | +- Auth/API: Enabled because storage depends on them |
| 88 | +- Everything else: Disabled |
| 89 | + |
0 commit comments