agentleFS
roborracleroborracle/agent-workflow-kit/skills/db-migrate/SKILL.md

db-migrate

Skill0 starsChanged 3 months agoMITView on GitHub

Design and execute safe database migrations. Covers schema evolution, zero-downtime patterns, rollback strategies, and data backfills for SQL and NoSQL databases.

  • Deletes or force-pushes

18 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use react-query-best-practices, you-might-not-need-a-callback and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • bibektimilsina00Skill

    react-query-best-practices

    Audit and fix React Query usage in apps/web — enforce query key factories, signal forwarding, staleTime, and proper mutation patterns. Use when reviewing or fixing server-state code.

    Also in 3 projects that use this

  • bibektimilsina00Skill

    you-might-not-need-a-callback

    Analyze and fix useCallback anti-patterns in your code

    Also in 3 projects that use this

  • MicrosoftSkill

    cleanup

    Also in 3 projects that use this

  • AWSSkill

    ship

    Finalize dev work on an issue branch — update docs, push, and open a PR.

    Also in 7 projects that use this

  • VercelSkill

    deploy

    Deploy applications to Vercel. Use when the user says "deploy", "deploy to Vercel", "push to production", "deploy my app", or "go live".

    Also in 4 projects that use this

  • SentrySkill

    commit

    Create commit messages following Sentry conventions. Use when committing code changes, writing commit messages, or formatting git history. Follows conventional commits with Sentry-specific issue references.

    Also in 3 projects that use this

  • +3 more from bibektimilsina00

The file

Files
SKILL.md

Database Migration Manager

Migration Safety Protocol

Before Writing the Migration

  1. Classify the change — additive (safe), destructive (dangerous), or transformative (requires expand-contract)
  2. Check table size — large tables need batched operations to avoid locks
  3. Identify dependencies — foreign keys, views, triggers, stored procedures that reference the target
  4. Plan rollback — every migration must have a reverse migration

Migration Classification

TypeRiskPattern
Add column (nullable)LowDirect ALTER
Add column (NOT NULL + constant default)LowDirect ALTER on Postgres 11+ / MySQL 8.0+ (metadata-only); on older engines or volatile defaults: add nullable → backfill → set NOT NULL
Remove columnHighExpand-contract (stop reading → deploy → drop)
Rename columnHighAdd new → copy data → update code → drop old
Change column typeHighAdd new column → backfill with cast → swap
Add indexMediumCREATE INDEX CONCURRENTLY (Postgres) or equivalent
Drop tableCriticalVerify zero references → soft-delete first → drop after grace period

Zero-Downtime Pattern: Expand-Contract

For any breaking schema change:

Phase 1 — Expand (backward compatible)

-- Add new column, keep old one
ALTER TABLE users ADD COLUMN full_name VARCHAR(255);

Phase 2 — Migrate (backfill data)

-- Batch update to avoid long locks (Postgres has no UPDATE ... LIMIT; select the batch by key)
UPDATE users SET full_name = first_name || ' ' || last_name
WHERE id IN (
  SELECT id FROM users WHERE full_name IS NULL ORDER BY id LIMIT 1000
);

Phase 3 — Transition (code reads new, writes both)

  • Deploy application code that writes to both columns
  • Reads from new column with fallback to old

Phase 4 — Contract (remove old)

-- Only after all code uses new column
ALTER TABLE users DROP COLUMN first_name, DROP COLUMN last_name;

Migration File Template

-- Migration: [description]
-- Author: [name]
-- Date: [date]
-- Reversible: Yes/No
-- Estimated duration: [time on production data size]
-- Lock level: [none/row/table]

-- UP
[migration SQL]

-- DOWN (rollback)
[reverse SQL]

-- VERIFY (post-migration check)
[validation query that confirms success]

Pre-Flight Checklist

  • Migration runs in a transaction (or is idempotent if it cannot)
  • Rollback migration tested
  • No full table locks on tables with >100K rows
  • Indexes created CONCURRENTLY where supported
  • Constant defaults use the engine's metadata-only ADD COLUMN path; volatile defaults (e.g. now(), random()) on large tables are backfilled in batches
  • Verified on staging with production-sized dataset
  • Backup confirmed before execution

Anti-Patterns

  • Adding NOT NULL without a default on a large table (locks entire table)
  • Running data migration in the same transaction as schema migration
  • Dropping columns before all code paths stop referencing them
  • Using ORM auto-migration in production without reviewing generated SQL
  • Assuming migration duration from dev dataset size

Data Migration Patterns

  • Backfill: Batch updates keyed on the primary key (keyset, not OFFSET), sleep between batches
  • Transform: ETL pipeline with progress tracking and resumability
  • Seed: Idempotent INSERT ... ON CONFLICT DO NOTHING

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.