agentleFS
buildpad-aibuildpad-ai/skills/create-migration/SKILL.md

create-migration

Skill1 starsChanged 4 months agoMITView on GitHub

Generate a Supabase PostgreSQL database migration with proper schema, RLS policies, indexes, triggers, and grants. Follows DaaS naming conventions and includes standard audit columns. Use when the user needs a database migration, table creation, schema change, or wants to add columns to a collection.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Create Database Migration

Generate a Supabase PostgreSQL migration with proper schema, RLS policies, and indexes.

Migration File Location

supabase/migrations/[YYYYMMDDHHMMSS]_[description].sql

Naming Conventions

  • Tables: snake_case, plural (user_profiles, blog_posts)
  • Columns: snake_case (date_created, user_id)
  • Primary keys: id (UUID)
  • Foreign keys: [referenced_table]_id (category_id)
  • Junction tables: [table1]_[table2] (products_tags)

Standard Columns

id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
date_created timestamptz DEFAULT now(),
date_updated timestamptz,
user_created uuid REFERENCES auth.users(id),
user_updated uuid REFERENCES auth.users(id)

Migration Sections (Required)

  1. Header Comment — description, author, date
  2. CREATE TABLE — with data types and constraints
  3. Enable RLS — ALTER TABLE ... ENABLE ROW LEVEL SECURITY
  4. RLS Policies — SELECT, INSERT, UPDATE, DELETE
  5. Indexes — FK columns, filtered columns, sorted columns
  6. Triggers — date_updated auto-update, audit logging
  7. GRANT — permissions for authenticated and anon roles

Data Types

Use CasePostgreSQL Type
IDuuid
Short texttext or varchar(n)
Long texttext
Integerinteger or bigint
Decimalnumeric(precision, scale)
Booleanboolean
Timestamptimestamptz
JSONjsonb
Arraytext[], uuid[]
Enumtext with CHECK

Relationships

One-to-Many

category_id uuid REFERENCES public.categories(id) ON DELETE SET NULL

Many-to-Many (junction table)

CREATE TABLE public.products_tags (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  products_id uuid NOT NULL REFERENCES public.products(id) ON DELETE CASCADE,
  tags_id uuid NOT NULL REFERENCES public.tags(id) ON DELETE CASCADE,
  UNIQUE(products_id, tags_id)
);

RLS Policy Patterns

-- Owner can CRUD their own
CREATE POLICY "users_own_data" ON public.[table]
  FOR ALL USING (auth.uid() = user_created);

-- Published items are public
CREATE POLICY "published_public" ON public.[table]
  FOR SELECT USING (status = 'published' OR auth.uid() = user_created);

Commands

supabase migration new [description]
supabase db push
supabase db reset

References

  • Special fields

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.