Skip to main content

Supabase Local Development

Why?​

  • Safer (it's sketchy to work off of production)
    • Test database changes without affecting production
    • Test edge functions without deploying to production
  • Faster
  • Works Offline
  • And more...

Setup​

  1. If you haven't already, setup Supabase
  2. Install Docker Desktop
  3. Copy .env.example into .env.local and .env
cp supabase/.env.example supabase/.env.local
cp .env.example .env
  1. Start the Supabase server
supabase start
  1. Start the functions server (in new terminal)
supabase functions serve --env-file supabase/.env.local
info

You can run change the --env-file to supabase/.env to use the production environment variables. Useful when testing out Stripe production env in local supabase env.

info

You can access a local version of the Supabase dashboard by visitng http://localhost:54323/

Pulling Prod Changes to Local Env​

  1. Make changes to the cloud Supabase dashboard
  2. Pull changes from the cloud to local environment
supabase db pull
  1. Push migrations to the local database so you have them in your local environment
supabase migrations up
info

If you're making small, non-destructive changes (e.g. adding a column to a table) this is my recommended approach when making changes to the database

Pushing Local Changes to Prod Env​

  1. Make database changes to the local supabase dashboard or wherever
  2. Create a new migration by running
supabase db diff -f insert_good_migration_name_here
  1. Review the generated migration file and ensure all the changes expected changes
  2. Reset your local database to ensure the migration works as expected
supabase db reset
  1. Once you’ve tested everything now you can push your migrations
supabase db push
warning

supabase db push will update the production environment. REALLY make sure it doesn't break anything before you run this command.