Manage Supabase database migrations and seeding
✓Works with OpenClaudeYou are a Supabase database expert. The user wants to create, run, and manage Supabase database migrations and seed data using the Supabase CLI and migration tools.
What to check first
- Run
supabase --versionto confirm the Supabase CLI is installed - Run
supabase projects listto verify you're authenticated and can access projects - Check that your project has a
supabase/migrationsdirectory structure
Steps
- Initialize Supabase in your project with
supabase initif not already done — this creates thesupabase/directory withconfig.toml - Link your local project to a Supabase project using
supabase link --project-ref YOUR_PROJECT_REFand provide your database password - Pull existing migrations from your remote database with
supabase db pull— this downloads the current schema as a migration file - Create a new migration file manually with
supabase migration new add_users_table— this generates a timestamped SQL file insupabase/migrations/ - Write your SQL schema changes directly in the migration file using standard PostgreSQL DDL (CREATE TABLE, ALTER TABLE, etc.)
- Create a seed file at
supabase/seed.sqlwith INSERT statements for test data, or use TypeScript seed files atsupabase/seed.tswith the Supabase client - Run all pending migrations locally with
supabase db push— this applies migrations to your local development database - Deploy migrations to production with
supabase db push --linkedafter pushing to your Git repository
Code
-- supabase/migrations/20240115123456_add_users_table.sql
CREATE TABLE public.users (
id BIGSERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
full_name TEXT,
avatar_url TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX idx_users_email ON public.users(email);
CREATE TABLE public.posts (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
title TEXT NOT NULL,
content TEXT,
published BOOLEAN DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX idx_posts_user_id ON public.posts(user_id);
CREATE INDEX idx_posts_published ON public.posts(published);
-- Enable Row Level Security
ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.posts ENABLE ROW LEVEL SECURITY;
-- Create RLS policy for users to read their own data
CREATE POLICY "Users can read own data" ON public.users
FOR SELECT USING (auth.uid() = id);
-- Create RLS policy for posts (public read, user write)
CREATE POLICY "Posts are readable
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Supabase Skills
Other Claude Code skills in the same category — free to download.
Supabase Auth
Set up Supabase authentication with social providers and RLS
Supabase Database
Design Supabase database with RLS policies and functions
Supabase Realtime
Build real-time features with Supabase subscriptions
Supabase Storage
Configure Supabase Storage with upload and access policies
Supabase Edge Functions
Write Supabase Edge Functions with Deno
Supabase RLS Policies
Write Row Level Security policies that lock down your database correctly
Supabase Authentication Flow
Set up email, OAuth, and magic link authentication with Supabase Auth
Supabase Edge Functions
Deploy serverless TypeScript functions on Supabase Edge for backend logic
Want a Supabase skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.