Docs/Manual Base/Migrations

Database Migrations

Apply database migrations to set up your schema, tables, and Row Level Security policies.

Push Migrations

Push your local migrations to the remote Supabase database:

supabase db push

This applies all pending migrations in the supabase/migrations directory to your remote database.

Production Warning
Be careful when running migrations against production databases. Always test migrations in a development or staging environment first.

Understanding Migrations

Migrations are SQL files that define changes to your database schema:

Migration Files
supabase/migrations/
├── 20240101000000_create_profiles.sql
├── 20240101000001_create_posts.sql
└── 20240101000002_add_rls_policies.sql

Example migration file:

20240101000000_create_profiles.sql
-- Create profiles table
create table public.profiles (
  id uuid references auth.users on delete cascade primary key,
  email text unique not null,
  full_name text,
  avatar_url text,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null,
  updated_at timestamp with time zone default timezone('utc'::text, now()) not null
);

-- Enable RLS
alter table public.profiles enable row level security;

-- Create policies
create policy "Users can view own profile"
  on public.profiles for select
  using (auth.uid() = id);

create policy "Users can update own profile"
  on public.profiles for update
  using (auth.uid() = id);

Migration Commands

Check Status

supabase migration list

See which migrations have been applied.

Create New Migration

supabase migration new "add_posts_table"

Create a new empty migration file.

Reset Local Database

supabase db reset

Reset your local database and reapply all migrations. Useful for testing.

Troubleshooting

"Migration failed"

Check the error message for SQL syntax issues. You may need to manually fix the migration file or roll back changes in the database.

"Out of sync with remote"

Run supabase db remote commit to sync your local migrations with the remote state.

Migrations | Manual Base | VibeCodeMax Docs