supabase-migration

Create idempotent Supabase PostgreSQL migrations with RLS policies and profile_id foreign keys.

Updated Oct 12, 2025
One-click install
npx skills add https://github.com/amo-tech-ai/medellin-spark --skill supabase-migration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-migration
Source: https://github.com/amo-tech-ai/medellin-spark/tree/main/.claude/skills/supabase-migration
Command: npx skills add https://github.com/amo-tech-ai/medellin-spark --skill supabase-migration

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires supabase-cli.

What problem does it solve?

This Skill ensures that your Supabase PostgreSQL database migrations are created, tested, and applied safely, preventing data loss, security vulnerabilities, and schema inconsistencies. It enforces best practices like idempotency and Row-Level Security (RLS), saving you from critical database errors.

Core Features & Use Cases

  • Idempotent Migrations: Guides in writing SQL that can be run multiple times without error, using IF NOT EXISTS and conditional logic.
  • RLS Security Enforcement: Ensures every new table includes RLS policies, enforcing data security by default.
  • Foreign Key Conventions: Promotes using profile_id instead of user_id for robust data relationships.
  • Use Case: When adding a new table to your database, use this skill to generate a migration file that includes RLS, proper foreign keys, and indexes, then verify its application and security policies.

Quick Start

1. Create Migration File

cd /home/sk/template-copilot-kit-py/supabase/migrations touch $(date +%Y%m%d%H%M%S)_description.sql

2. Apply Migration

supabase db push

Frequently Asked Questions about supabase-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write idempotent database migrations for Supabase PostgreSQL?

Idempotent migrations use `CREATE TABLE IF NOT EXISTS`, `ALTER TABLE ... ADD COLUMN IF NOT EXISTS`, and conditional DO blocks so they run safely multiple times without errors. This prevents failures when reapplying migrations across environments.

Why should I enforce row-level security on every Supabase table?

Row-level security policies restrict data access at the database level, ensuring users only see their own records. This Skill enforces RLS by default on new tables, preventing unauthorized data exposure and reducing application-layer security gaps.

What's the best way to manage PostgreSQL schema changes safely in Supabase?

Create timestamped migration files with idempotent SQL, include RLS policies and foreign key constraints, test locally with `supabase db push`, then verify rollback workflows. This approach prevents schema drift and data loss across development, testing, and production.

Can I use profile_id instead of user_id for foreign keys in Supabase migrations?

Yes, using `profile_id` as a foreign key convention provides more robust data relationships and aligns with Supabase auth patterns. This Skill promotes this practice to ensure consistent referential integrity across your schema.

How do I test and rollback Supabase database migrations locally?

Create migration files with reversible SQL, apply them with `supabase db push`, verify schema and RLS policies, then test rollback by reverting the migration file. This workflow ensures migrations are reproducible across local, CI, and production environments.