0
0
Supabasecloud~3 mins

Creating migrations in Supabase - Why You Should Know This

Choose your learning style9 modes available
The Big Idea

What if one small mistake in your database update could break your entire app?

The Scenario

Imagine you have a growing app and you need to change your database structure. You try to update tables and columns by hand every time you add a feature or fix a bug.

Each time you do this, you write SQL commands manually and run them on your database.

The Problem

Doing this manually is slow and risky. You might forget a step or make a typo that breaks your app.

Also, if you have multiple developers, everyone might change the database differently, causing confusion and errors.

The Solution

Creating migrations means writing small, clear steps that change your database structure in a safe and repeatable way.

These steps can be saved, shared, and run automatically, so everyone's database stays the same and your app works smoothly.

Before vs After
Before
ALTER TABLE users ADD COLUMN age INT;
After
-- migration file
create table users (id serial primary key, name text);
alter table users add column age int;
What It Enables

It lets you update your database confidently and keep your app working well as it grows.

Real Life Example

A team building a social app adds a new feature to track user birthdays. They create a migration to add a birthday column to the users table. Everyone runs this migration, so all databases match perfectly.

Key Takeaways

Manual database changes are slow and error-prone.

Migrations automate and organize database updates.

Migrations keep all developers' databases in sync.