Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/supabase-migration-deep-dive

@0d57af8
Run it yourself

Database migration patterns with the Supabase CLI: npx supabase migration new, zero-downtime migrations, data backfill strategies, schema versioning, rollback strategies, and TypeScript type generation. Use when creating database migrations, performing zero-downtime schema changes, backfilling data in production, managing schema versions, or planning rollback strategies. Trigger with "supabase migration", "supabase schema change", "supabase zero downtime", "supabase rollback", "supabase db push", "supabase migration new".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/supabase-migration-deep-dive

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesimplementation-plan.md

≈689 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Implementation Plan

1. Establish a Reviewed Migration Boundary

Install a reviewed compatible SDK version through the project's lockfile. The SDK has no package-level ping() method. Validate configuration locally, then run a separately authorized read against a known fixture table to test connectivity. Never infer successful RLS or authentication from construction alone.

Record source/destination project identities, schema revision, approved fields, retention rules, backup/restore evidence, and rollback ownership. Do not migrate production data from an unreviewed shell one-liner.

2. Use Real Database Operations

This adapter assumes an existing products(id, name) schema with a unique id and an explicitly authorized migration client. It accepts only the mapped fields and checks the SDK's returned error. create() and batchCreate() are not generic Supabase client methods.

import type { SupabaseClient } from '@supabase/supabase-js';
type Product = { id: string; name: string };

export async function insertProducts(client: SupabaseClient, products: Product[]) {
  if (products.length === 0 || products.length > 100) throw new Error('Expected 1–100 rows');
  const rows = products.map(({ id, name }) => ({ id, name }));
  const { error } = await client.from('products').insert(rows);
  if (error) throw error;
  return { submitted: rows.length };
}

The receipt means the insert returned success, not that the whole migration is complete. Do not blindly retry a timed-out insert. Reconcile immutable source IDs against destination IDs before deciding whether to retry; choose upsert semantics only after reviewing conflict keys and whether overwrites are authorized.

3. Batch, Reconcile, and Pause on Failure

Read the source with bounded stable pagination or a reviewed snapshot. Record each batch's source IDs and checksum in protected migration evidence, not stdout. Stop on any read/write/transform error; retain an explicit partial receipt rather than silently skipping a failed batch. Compare counts, approved field checksums, RLS, and representative reads before traffic shifts. Redact personal data from reports.

4. Shift Traffic Without Splitting an Identity's Writes

Use a persisted, deterministic tenant/user cohort assignment, not a fresh random choice on every request. Define source of truth and write ownership per cohort, reconciliation, a tested rollback boundary, and how already-written records are handled. Restore schema/data only through a separately reviewed restore plan; changing an application feature flag does not undo a data migration.

Insert Upsert

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides comprehensive patterns and commands for managing Supabase database migrations, including zero-downtime schema changes, data backfilling, and TypeScript type generation. It uses official Supabase CLI tools and adheres to secure database management practices.

  • Socket2mo

    1 alert: gptAnomaly

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
What it can do
Reads files Edits files Runs commands
version
1.55.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 8 allowed tools
ReadWriteEditBash(npx supabase:*)Bash(supabase:*)Bash(psql:*)GrepGlob
Other metadata
tags
[
  "saas",
  "supabase",
  "migration",
  "database",
  "schema",
  "zero-downtime",
  "rollback"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/supabase-migration-deep-dive