0
0
Supabasecloud~30 mins

Running migrations locally and remotely in Supabase - Mini Project: Build & Apply

Choose your learning style9 modes available
Running migrations locally and remotely
📖 Scenario: You are managing a database for a web application using Supabase. You need to apply database changes called migrations both on your local machine and on the remote Supabase project to keep the database structure consistent.
🎯 Goal: Learn how to create a migration file locally, configure the Supabase project reference, apply the migration locally, and then push the migration to the remote Supabase database.
📋 What You'll Learn
Create a migration file with a specific name
Set the Supabase project reference URL
Apply the migration locally
Push the migration to the remote Supabase project
💡 Why This Matters
🌍 Real World
Database migrations keep your database structure consistent across development and production environments, preventing errors and data loss.
💼 Career
Knowing how to manage migrations is essential for backend developers, DevOps engineers, and cloud architects working with databases and cloud services.
Progress0 / 4 steps
1
Create a migration file locally
Use the Supabase CLI command supabase migration new add_users_table to create a new migration file named add_users_table in your local migrations folder.
Supabase
Hint

This command creates a new migration file with the name add_users_table in your local migrations directory.

2
Configure the Supabase project reference URL
Set the Supabase project reference URL by running supabase link --project-ref your-project-ref where your-project-ref is your actual Supabase project reference string.
Supabase
Hint

This command links your local setup to the remote Supabase project using the project reference.

3
Apply the migration locally
Run supabase db migrate up to apply the migration changes to your local development database.
Supabase
Hint

This command applies your migration changes to the local database.

4
Push the migration to the remote Supabase project
Run supabase db push to push your local migration changes to the remote Supabase database.
Supabase
Hint

This command pushes your local migration changes to the remote Supabase project database.