0
0
Supabasecloud~15 mins

Why migrations version your database schema in Supabase - See It in Action

Choose your learning style9 modes available
Why migrations version your database schema
📖 Scenario: You are working on a Supabase project where your database schema changes over time as you add new features. You want to keep track of these changes safely and clearly.
🎯 Goal: Build a simple migration versioning setup that shows how to track changes to your database schema step-by-step.
📋 What You'll Learn
Create a migration version identifier
Add a description for the migration
Apply a schema change using SQL
Record the migration version in a tracking table
💡 Why This Matters
🌍 Real World
In real projects, migrations help teams safely update databases without losing data or causing errors.
💼 Career
Understanding migrations is key for backend developers and database administrators to manage evolving data structures.
Progress0 / 4 steps
1
Create a migration version variable
Create a variable called migration_version and set it to the string '001_initial_schema'.
Supabase
Hint

This variable helps identify the migration step.

2
Add a migration description
Create a variable called migration_description and set it to the string 'Create users table'.
Supabase
Hint

This description explains what the migration does.

3
Write the SQL to create a users table
Create a variable called migration_sql and set it to the SQL string that creates a table named users with columns id (integer primary key) and email (text).
Supabase
Hint

Use triple quotes for multi-line SQL strings.

4
Record the migration in a migrations table
Write a SQL insert statement in a variable called record_migration_sql that inserts migration_version and migration_description into a table named migrations with columns version and description.
Supabase
Hint

Use an f-string to insert variables into the SQL statement.