Bird
Raised Fist0
Supabasecloud~10 mins

Running migrations locally and remotely in Supabase - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Running migrations locally and remotely
Start Migration Process
↓
Choose Environment
↓
Local
↓
Run Migration
↓
Check Logs
↓
Success?
No→Fix Issues
Yes↓
End Migration
This flow shows choosing to run migrations either locally or remotely, executing them, checking logs, and handling success or errors.
Execution Sample
Supabase
supabase migration run --local
supabase migration run
supabase migration list
Commands to run migrations locally, then remotely, and check migration status.
Process Table
StepActionEnvironmentResultNext Step
1Start migration processN/AReady to choose environmentChoose environment
2Choose environmentLocalSelected local environmentRun migration locally
3Run migration commandLocalMigration applied successfullyCheck logs
4Check logsLocalNo errors foundSuccess?
5Success?LocalYesEnd migration
6Choose environmentRemoteSelected remote environmentRun migration remotely
7Run migration commandRemoteMigration applied successfullyCheck logs
8Check logsRemoteNo errors foundSuccess?
9Success?RemoteYesEnd migration
10End migrationN/AMigration process completeProcess finished
💡 Migration process ends after successful migration on chosen environment.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 5After Step 6After Step 7After Step 9Final
EnvironmentNoneLocalLocalLocalRemoteRemoteRemoteNone
Migration StatusNot startedNot startedSuccessSuccessNot startedSuccessSuccessComplete
LogsEmptyEmptyNo errorsNo errorsEmptyNo errorsNo errorsReviewed
Key Moments - 3 Insights
Why do we check logs after running migrations?
Checking logs confirms if migrations applied correctly or if errors occurred, as shown in steps 4 and 8 in the execution table.
What happens if migration fails on remote environment?
If migration fails, logs will show errors and the process will move to fixing issues before retrying, which is implied after step 8 if success is No.
Can we run migrations locally and remotely in one command?
No, migrations must be run separately for local and remote environments, as shown by separate steps 3 and 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the migration status after step 3?
ASuccess
BNot started
CFailed
DIn progress
💡 Hint
Check the 'Migration Status' column after step 3 in the variable_tracker.
At which step does the process confirm migration success on the remote environment?
AStep 7
BStep 9
CStep 8
DStep 10
💡 Hint
Look at the 'Success?' action for the remote environment in the execution_table.
If logs showed errors after running migration locally, what would be the next step?
AEnd migration
BRun migration remotely
CFix issues
DCheck migration status
💡 Hint
Refer to the flow where 'Success?' is No leading to 'Fix Issues'.
Concept Snapshot
Running migrations means applying database changes.
Choose environment: local or remote.
Run migration command for chosen environment.
Check logs to confirm success or find errors.
Fix issues if migration fails, then retry.
Repeat for each environment as needed.
Full Transcript
This visual execution shows how to run database migrations using Supabase locally and remotely. First, you start the migration process and choose whether to run it locally or remotely. Then you run the migration command for that environment. After running, you check the logs to see if the migration succeeded or if there were errors. If successful, the process ends. If there are errors, you fix them before retrying. This process is repeated separately for local and remote environments to keep databases in sync.

Practice

(1/5)
1. What is the main reason to run database migrations locally before running them remotely?
easy
A. To update the live database directly without testing
B. To test changes safely before applying them to the live database
C. To delete all existing data before migration
D. To backup the remote database automatically

Solution

  1. Step 1: Understand migration purpose locally

    Running migrations locally allows you to check if changes work without risk to live data.
  2. Step 2: Understand migration purpose remotely

    Running migrations remotely updates the live database after testing is successful.
  3. Final Answer:

    To test changes safely before applying them to the live database -> Option B
  4. Quick Check:

    Test locally first = Safe migration [OK]
Hint: Always test migrations locally before live update [OK]
Common Mistakes:
  • Running migrations directly on live without testing
  • Assuming local migrations update remote automatically
  • Thinking migrations delete all data by default
2. Which command correctly runs migrations on your local Supabase project?
easy
A. supabase db reset
B. supabase db push
C. supabase db migrate
D. supabase migration run

Solution

  1. Step 1: Identify the correct Supabase CLI command

    The command supabase db reset applies all migrations to the local database by resetting it.
  2. Step 2: Check other options

    supabase migration run and supabase db migrate are invalid; supabase db push updates the remote database.
  3. Final Answer:

    supabase db reset -> Option A
  4. Quick Check:

    Local migration command = supabase db reset [OK]
Hint: Use 'supabase db reset' to run and test local migrations [OK]
Common Mistakes:
  • Using remote commands like 'supabase db push' for local
  • Using incorrect commands like 'supabase migration run'
  • Trying to run migrations without Supabase CLI installed
3. Given this sequence of commands, what is the expected result?
supabase db push
supabase db remote commit
supabase db remote apply
medium
A. The commands will cause an error due to invalid syntax
B. Migrations are only applied locally, remote stays unchanged
C. Remote migrations are applied without local testing
D. Migrations are applied locally and then committed and applied remotely

Solution

  1. Step 1: Analyze each command

    supabase db push applies local schema changes to remote; supabase db remote commit generates a migration from remote schema differences; supabase db remote apply applies pending migrations on remote.
  2. Step 2: Understand the flow

    All commands target the remote database; no local application occurs in this sequence.
  3. Final Answer:

    Remote migrations are applied without local testing -> Option C
  4. Quick Check:

    db push + remote commit/apply = remote only [OK]
Hint: db push + remote commit/apply affects remote without local changes [OK]
Common Mistakes:
  • Thinking 'supabase db push' applies locally
  • Expecting local database changes from remote commands
  • Believing commands have invalid syntax
4. You ran supabase db reset locally but forgot to run supabase db remote apply. What issue will you face?
medium
A. Local database will reset to remote state
B. Remote database will automatically update
C. Migration files will be deleted
D. Local and remote databases will be out of sync

Solution

  1. Step 1: Understand local reset effect

    supabase db reset reapplies all migrations to the local database only.
  2. Step 2: Understand remote apply necessity

    Without supabase db remote apply, the remote database remains unchanged, causing out-of-sync databases.
  3. Final Answer:

    Local and remote databases will be out of sync -> Option D
  4. Quick Check:

    Missing remote apply = databases out of sync [OK]
Hint: Always run remote apply after local reset to sync [OK]
Common Mistakes:
  • Assuming remote updates automatically after local reset
  • Thinking local reset affects remote database
  • Believing migration files get deleted after reset
5. You want to update your live Supabase database with a new table but keep your local database unchanged for now. Which approach is correct?
hard
A. Run supabase db remote apply without running supabase db reset
B. Run supabase db push only
C. Run supabase db push then supabase db remote apply
D. Run supabase db reset locally then supabase db remote apply

Solution

  1. Step 1: Understand local vs remote migration commands

    supabase db reset affects local; supabase db remote apply applies pending migrations to remote only.
  2. Step 2: Apply only remote changes

    Create/edit migration file for new table, then run supabase db remote apply; skip local commands like supabase db reset.
  3. Final Answer:

    Run supabase db remote apply without running supabase db reset -> Option A
  4. Quick Check:

    Remote apply only = live DB updated, local unchanged [OK]
Hint: Use remote apply after creating migration file to update only remote [OK]
Common Mistakes:
  • Running local reset or push which updates local DB unnecessarily
  • Resetting local DB when not needed
  • Assuming remote apply requires local reset first
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard