What if one simple command could keep your local and cloud databases perfectly matched every time?
Why Running migrations locally and remotely in Supabase? - Purpose & Use Cases
Imagine you have a database for your app. You make changes to its structure by hand on your computer, then try to do the same on the cloud server. You have to remember every change and type it again carefully.
This manual way is slow and risky. You might forget a step or make a typo. Your app could break because the local and remote databases don't match. Fixing these mistakes takes a lot of time and stress.
Running migrations locally and remotely means writing your database changes once and applying them automatically everywhere. This keeps your databases in sync without errors or extra work.
ALTER TABLE users ADD COLUMN age INT; -- Then manually run the same on remote
supabase migration up -- Applies pending migrations remotely (local via supabase start)
You can update your database safely and quickly, whether on your computer or in the cloud, without worrying about mistakes.
A developer updates the user profile table to add a new field. They run the migration command once, and both their local setup and the live app's database update perfectly in sync.
Manual database updates are slow and error-prone.
Migrations automate and sync changes locally and remotely.
This saves time and prevents app-breaking mistakes.
Practice
Solution
Step 1: Understand migration purpose locally
Running migrations locally allows you to check if changes work without risk to live data.Step 2: Understand migration purpose remotely
Running migrations remotely updates the live database after testing is successful.Final Answer:
To test changes safely before applying them to the live database -> Option BQuick Check:
Test locally first = Safe migration [OK]
- Running migrations directly on live without testing
- Assuming local migrations update remote automatically
- Thinking migrations delete all data by default
Solution
Step 1: Identify the correct Supabase CLI command
The commandsupabase db resetapplies all migrations to the local database by resetting it.Step 2: Check other options
supabase migration runandsupabase db migrateare invalid;supabase db pushupdates the remote database.Final Answer:
supabase db reset -> Option AQuick Check:
Local migration command = supabase db reset [OK]
- Using remote commands like 'supabase db push' for local
- Using incorrect commands like 'supabase migration run'
- Trying to run migrations without Supabase CLI installed
supabase db push supabase db remote commit supabase db remote apply
Solution
Step 1: Analyze each command
supabase db pushapplies local schema changes to remote;supabase db remote commitgenerates a migration from remote schema differences;supabase db remote applyapplies pending migrations on remote.Step 2: Understand the flow
All commands target the remote database; no local application occurs in this sequence.Final Answer:
Remote migrations are applied without local testing -> Option CQuick Check:
db push + remote commit/apply = remote only [OK]
- Thinking 'supabase db push' applies locally
- Expecting local database changes from remote commands
- Believing commands have invalid syntax
supabase db reset locally but forgot to run supabase db remote apply. What issue will you face?Solution
Step 1: Understand local reset effect
supabase db resetreapplies all migrations to the local database only.Step 2: Understand remote apply necessity
Withoutsupabase db remote apply, the remote database remains unchanged, causing out-of-sync databases.Final Answer:
Local and remote databases will be out of sync -> Option DQuick Check:
Missing remote apply = databases out of sync [OK]
- Assuming remote updates automatically after local reset
- Thinking local reset affects remote database
- Believing migration files get deleted after reset
Solution
Step 1: Understand local vs remote migration commands
supabase db resetaffects local;supabase db remote applyapplies pending migrations to remote only.Step 2: Apply only remote changes
Create/edit migration file for new table, then runsupabase db remote apply; skip local commands likesupabase db reset.Final Answer:
Run supabase db remote apply without running supabase db reset -> Option AQuick Check:
Remote apply only = live DB updated, local unchanged [OK]
- Running local reset or push which updates local DB unnecessarily
- Resetting local DB when not needed
- Assuming remote apply requires local reset first
Ready to prove it?
Pass the test and this pattern moves unknown
