Skip to content
supabase-migrations logo

Supabase Database Migrations

supabase-migrations

Create and manage Supabase database migrations. Use when making schema changes, creating tables, adding columns, or managing database structure. Triggers on "migration", "schema", "database", "table", "Supabase".

SKILL.md

Full skill instructions

Supabase Database Migrations

Create, test, and deploy Supabase database migrations safely.

When to Use

  • User mentions "migration", "schema change", "database"
  • User wants to create/​modify tables
  • User asks about Supabase database structure
  • User needs to add columns, indexes, or constraints
  • User mentions RLS or Row Level Security

Migration Workflow

# Create new migration
npx supabase migration new <name>

# Test locally (resets local DB)
npx supabase db reset

# Push to production
npx supabase db push

# Repair if remote is out of sync
npx supabase migration repair --status applied <version>

Migration File Format

Location: supabase/​migrations/ Format: YYYYMMDDHHMMSS_description.sql

Example Migration

-- supabase/​migrations/​20250106120000_add_user_preferences.sql

-- Add new column
ALTER TABLE users
ADD COLUMN preferences JSONB DEFAULT '{}';

-- Create index for faster queries
CREATE INDEX idx_users_preferences ON users USING GIN (preferences);

-- Add RLS policy
CREATE POLICY "Users can update own preferences"
ON users
FOR UPDATE
USING (auth.uid() = id)
WITH CHECK (auth.uid() = id);

Key Rules

DO:

  • Test migrations locally first with npx supabase db reset
  • Use npx supabase migration repair if remote is out of sync
  • Create new migrations (never modify applied ones)
  • Include RLS policies in migrations
  • Use descriptive migration names

DON'T:

  • Modify already-applied migrations
  • Push untested migrations to production
  • Forget RLS policies on new tables
  • Use destructive operations without backup

Common Patterns

Create Table with RLS

-- Create table
CREATE TABLE items (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID REFERENCES auth.users(id) NOT NULL,
  name TEXT NOT NULL,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- Enable RLS
ALTER TABLE items ENABLE ROW LEVEL SECURITY;

-- Policy: Users see own items
CREATE POLICY "Users can view own items"
ON items FOR SELECT
USING (auth.uid() = user_id);

-- Policy: Users insert own items
CREATE POLICY "Users can insert own items"
ON items FOR INSERT
WITH CHECK (auth.uid() = user_id);

Add Column Safely

-- Add nullable column first
ALTER TABLE users ADD COLUMN phone TEXT;

-- Then add constraint if needed
ALTER TABLE users
ALTER COLUMN phone SET NOT NULL,
ADD CONSTRAINT phone_format CHECK (phone ~ '^\+[0-9]{10,15}$');

Debugging

# Check migration status
npx supabase migration list

# Query production database
npx supabase db query "SELECT * FROM items LIMIT 10;"

# View table structure
npx supabase db query "\d items"

Environment Setup

Ensure Supabase CLI is linked to your project:

npx supabase link --project-ref <project-id>

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View