Skip to content

datit309/supergraph / plugins/supergraph/skills/database-migrations

database-migrations

Unverified

Database migration best practices for schema changes, data migrations, rollbacks, and zero-downtime deployments across PostgreSQL, MySQL, and common ORMs (Prisma, Drizzle, Kysely, Django, TypeORM, golang-migrate).

/supergraph:database-migrations

Safe, reversible database schema changes for production systems.

Announce: "πŸ—„οΈ /supergraph:database-migrations β€” checking blast radius and migration safety..."

When to Activate

  • Creating or altering database tables
  • Adding/removing columns or indexes
  • Running data migrations (backfill, transform)
  • Planning zero-downtime schema changes
  • Setting up migration tooling for a new project

Steps

1. Check blast radius (MANDATORY before writing any migration)

Use CBM_PROJECT: search_graph schema/model symbols, trace_path inbound and data-flow, then validated dependencies, hubs, and test-gaps recipes. Schema changes to hub tables (e.g. users, orders) ripple through repositories, queries, services. If blast radius > 20 files β†’ STOP and discuss with user.

Serena symbol-level impact (optional):

mcp__serena__find_referencing_symbols(symbol=<column_or_model_name>)

Finds ORM field references that graph tools see only at file level β€” e.g. a Prisma field rename that query_graph sees as "file touched" but Serena sees as "12 usages in service layer". Skip if Serena unavailable.

2. Choose migration pattern

Select the appropriate pattern from the sections below (PostgreSQL, Prisma, Drizzle, etc.) based on detected project type from .supergraph-env.

3. Write migration

Follow Migration Safety Checklist before writing SQL/ORM migration code.

4. Verify flows

After migration written: Use trace_path(project=CBM_PROJECT, mode="data_flow") and the dependencies recipe. Empty results are unavailable evidence requiring Serena/filesystem fallback, not invented flows. All data flows still intact? Application code updated to match schema?

5. Report

βœ… /supergraph:database-migrations
- Pattern: [expand-contract | add-column | add-index | data-migration | ...]
- Blast radius: N files | Hub tables: [list/none]
- Safety checklist: PASS | BLOCKED (list issues)
- Next: /supergraph:tdd β†’ /supergraph:fix β†’ /supergraph:verify

Core Principles

  1. Every change is a migration β€” never alter production databases manually
  2. Migrations are forward-only in production β€” rollbacks use new forward migrations
  3. Schema and data migrations are separate β€” never mix DDL and DML in one migration
  4. Test migrations against production-sized data β€” a migration that works on 100 rows may lock on 10M
  5. Migrations are immutable once deployed β€” never edit a migration that has run in production

Migration Safety Checklist

Before applying any migration:

  • Migration has both UP and DOWN (or is explicitly marked irreversible)
  • No full table locks on large tables (use concurrent operations)
  • New columns have defaults or are nullable (never add NOT NULL without default)
  • Indexes created concurrently (not inline with CREATE TABLE for existing tables)
  • Data backfill is a separate migration from schema change
  • Tested against a copy of production data
  • Rollback plan documented

Full ORM examples (PostgreSQL, Prisma, Drizzle, Kysely, Django, golang-migrate): REFERENCE.md

Anti-Patterns

Anti-PatternWhy It FailsBetter Approach
Manual SQL in productionNo audit trail, unrepeatableAlways use migration files
Editing deployed migrationsCauses drift between environmentsCreate new migration instead
NOT NULL without defaultLocks table, rewrites all rowsAdd nullable, backfill, then add constraint
Inline index on large tableBlocks writes during buildCREATE INDEX CONCURRENTLY
Schema + data in one migrationHard to rollback, long transactionsSeparate migrations
Dropping column before removing codeApplication errors on missing columnRemove code first, drop column next deploy

Rules

  • ALWAYS check blast radius before writing any migration β€” hub table changes need user approval
  • NEVER alter production databases manually β€” every change goes through migration files
  • NEVER mix DDL and DML in one migration β€” separate schema changes from data migrations
  • NEVER add NOT NULL column without a default to existing tables β€” locks and rewrites all rows
  • ALWAYS create indexes with CONCURRENTLY on live tables
  • ALWAYS test against production-sized data before deploying
  • NEVER edit a migration that has already run in production β€” create a new one
  • Use expand-contract pattern for zero-downtime column renames and removals
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 318kUpdated Claude CodeCodexUnverifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path β€” even casually (like "the xlsx in my downloads") β€” and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 117kUpdated Claude CodeCodexUnverifiedInstall