Migrations help you save and track changes to your database structure. They make it easy to update your database safely and share changes with your team.
Creating migrations in Supabase
supabase migration new <migration_name> supabase db reset supabase migration apply
supabase migration new creates a new migration file with your changes.
supabase db reset resets the local database and applies migrations.
supabase migration apply applies migrations to the remote database.
supabase migration new add_users_table
supabase db reset
supabase migration apply
This migration creates a new table called users with three columns: id, name, and email. The commands create the migration file, reset and apply it locally, and then apply it to the remote database.
-- Migration file: 20240601_add_users_table.sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
);
-- Commands to run:
supabase migration new add_users_table
supabase db reset
supabase migration applyAlways write clear and descriptive migration names.
Test migrations locally before applying them to production.
Keep migrations small and focused on one change at a time.
Migrations save and track database changes.
Use supabase migration new to create migration files.
Reset and apply migrations locally with supabase db reset and apply migrations remotely with supabase migration apply.