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
Setup
- Install Docker/Docker Desktop
- Install Supabase CLI (not the npm one)
-
npm install -g env-cmd
- ask for .env file and place it into
code\backend\mb-supabase
-
cd code\backend\mb-supabase
-
env-cmd supabase start
- replace the value of
api url
andanon key
shown in the terminal, to the value ofSUPABASE_URL
andSUPABASE_KEY
respectively incode\presentation\mb-client\.env.development
- make sure to replace
127.0.0.1
to your local ip inSUPABASE_URL
incode\presentation\mb-client\.env.development
-
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
some useful commands
# links remote to local
supabase link
# pulls remote migrations
supabase db pull
# fetches data form remote and saves into seed.sql
supabase db dump -f supabase/seed.sql --data-only
# starts supabase with .env environment
env-cmd supabase start
# resets database using migrations + seed
supabase db reset
# generates types for client
supabase gen types typescript --linked > ..\..\presentation\mb-client\src\api\supabase\types.ts