1. Create a Database Migration

Purpose: Create a new numbered SQL migration file with the standardized header format, then regenerate the migrations index and DB types.

Prerequisites:

  • Familiarity with the existing schema (check supabase/migrations-index.md)
  • Know the next migration number (ls supabase/migrations/ | tail -1)

Cost / Duration: $0 | 5-30 min

Prompt

Create a new database migration.

Step 1 — Determine the next migration number:

```bash
ls supabase/migrations/ | tail -1
```

Use the next sequential number (e.g., if last is `0148`, use `0149`).

Step 2 — Create the migration file:

```bash
touch supabase/migrations/0149_your_migration_name.sql
```

Name should be descriptive using underscores.

Step 3 — Write the migration with standard header:

```sql
-- ============================================================================
-- MIGRATION 0149: Title of Migration
--
-- Brief description of what this migration does.
--
-- Changes:
--   - Change 1
--   - Change 2
-- ============================================================================
```

Step 4 — Regenerate migrations index:

```bash
bun run migrations:index
```

This updates `supabase/migrations-index.md` to include the new migration.

Step 5 — Generate updated DB types (if migration changes table structure):

```bash
bun run db:types
```

Step 6 — Verify the index is current:

```bash
bun run migrations:check
```

Expected: Exit code 0 — migrations index is current.

Verification

  • Migration file created with correct sequential number
  • Standard header format used (MIGRATION NNNN, description, Changes list)
  • bun run migrations:index regenerated successfully
  • bun run migrations:check passes (exit code 0)
  • DB types regenerated if schema changed (bun run db:types)

Back to index