Skip to main content

Local Supabase Server

Why?

When working on a feature branch, we can't change the schema of staging/dev db as others testing or working on other branches might face conflicts. To avoid this issue, when working on a feature branch which requires changing schema of the db, local db server MUST BE USED. Once the feature branch is merged, staging/dev db should be migrated accordingly.

Explained in detail here

Server Architecture diagram

Setup

  1. Install Docker/Docker Desktop
  2. Install Supabase CLI (not the npm one)
  3. npm install -g env-cmd
  4. ask for .env file and place it into code\backend\mb-supabase
  5. cd code\backend\mb-supabase
  6. env-cmd supabase start
  7. replace the value of api url and anon key shown in the terminal, to the value of SUPABASE_URL and SUPABASE_KEY respectively in code\presentation\mb-client\.env.development
  8. make sure to replace 127.0.0.1 to your local ip in SUPABASE_URL in code\presentation\mb-client\.env.development
  9. mb-client should now connect to local db instead of staging db

How to change Schema

  • Follow this guide to create migration for your db
  • dont forget to update the seed too using supabase db dump -f supabase/seed.sql --data-only --local

test migrations before commiting

  1. once you are on a happy state, where everything is working fine (wrt to the feature you are building)
  2. take snapshot of your db, just to be safe
  3. supabase db reset
  4. apply migrations
  5. check if db is on the same state as it was when you were happy

create seed.sql

  1. Seed is used to keep mock data, seed should only be used for local/staging server
  2. seed is automatically used while setting up
  3. old seed doesn't work with newer migrations, so whenever you migrate, generate a new seed, so that setup doesn't break for others
  4. seeds SHOULD NOT CONTAIN ANY PERSONALY IDENTIFIABLE DATA like email/phone number/tokens, so if seed.sql contains it, manually remove it after generating the seed file

some useful commands