Skip to content
AI & Agents
Skill

/drizzle-safe-migrations

Plan safe Drizzle backfills, enum/check/default changes, constraint tightening, migration ordering, and rollback. Excludes other ORMs, query optimization, and new-schema design.

From plugin
skills
65590 skills1 command

Claude Code

$ npx -y skills add pedronauck/skills --skill drizzle-safe-migrations --agent claude-code

SKILL.md

drizzle-safe-migrations.SKILL.md
name: drizzle-safe-migrations
description: "Plan safe Drizzle backfills, enum/check/default changes, constraint tightening, migration ordering, and rollback. Excludes other ORMs, query optimization, and new-schema design."
metadata:
  author: Pedro Nauck
  github: https://github.com/pedronauck
  repository: https://github.com/pedronauck/skills

Drizzle Safe Migrations

Overview

Use this skill to run database migrations in a way that is auditable, deployment-safe, and consistent with Drizzle's migration model.

Core Rules

  • Generate schema migrations with the existing project script and package manager; `bun run db:generate` below is an example, not a required script name.
  • Never hand-edit generated schema migration files.
  • Generate data backfills as custom migrations (`bun run db:generate -- --custom --name <name>`) and edit only that custom SQL file.
  • Apply data normalization before tightening constraints.
  • Keep one-off data fixes in migration history, not as hidden runtime logic, unless an emergency hotfix requires temporary mitigation.

Workflow

1. Classify the change:

  • `schema-only`: only column/table/index/default changes.
  • `data+schema`: old rows must be transformed before new constraints/defaults.

2. For `data+schema`, create custom migration first:

  • `bun run db:generate -- --custom --name <descriptive_name>`
  • Add idempotent backfill SQL.

3. Generate schema migration second:

  • `bun run db:generate`

4. Verify migration ordering in `drizzle/meta/_journal.json`:

  • backfill migration index must be lower than constraint-tightening migration index.

5. Verify generated SQL and snapshots:

  • backfill migration contains only intended data change.
  • schema migration contains constraint/default/type changes.

6. Run the owning migration suite against existing-data and fresh-install cases, plus required project gates. Reuse current evidence; unrelated backend suites are not an additional skill gate. 7. Record material rollout risks and recovery steps when applicable:

  • expected data transformations,
  • lock-risk areas,
  • rollback strategy.

Backfill Requirements

  • Use restrictive `WHERE` clauses.
  • Prefer idempotent updates (`UPDATE ... WHERE status = 'legacy_value'`).
  • Do not mix unrelated DDL/DML in the same migration.
  • Keep SQL explicit and minimal.

Constraint Tightening Pattern

When removing allowed values (enum/check):

1. Backfill existing rows to valid target value. 2. Update default to new value. 3. Tighten check/enum constraint.

For large tables or strict uptime targets, evaluate staged constraint validation supported by the actual database and driver. PostgreSQL `NOT VALID` / `VALIDATE CONSTRAINT` applies only to supported constraint kinds.

Anti-Patterns

  • Hand-editing generated schema migration files.
  • Tightening constraints before backfilling existing data.
  • Hiding one-time migration logic in app startup code without migration artifacts.
  • Running migrations without validating order in the Drizzle journal.

Reference

  • See `references/production-playbook.md` for command templates and review checklists.
Read more
@pedronauck
Ships withskills

A curated collection of 89 agent skills for Claude Code and compatible AI coding assistants — 43 original (⭐️), 33 hand-picked (💎), and 13 marketing & business (📣).

Stars on GitHub

Momentum

stars in total
655
Star history of pedronauck/skills on GitHub, a chart by star-history.com

Other skills on skills.

agent-browser

agent-browser

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling…

@pedronauck@pedronauckInstall Skill
ai-sdk

ai-sdk

Answer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like…

@pedronauck@pedronauckInstall Skill
autoresearch

autoresearch

Autonomously optimize any Claude Code skill by running it repeatedly, scoring outputs against binary evals, mutating the prompt,…

@pedronauck@pedronauckInstall Skill
centrifugo

centrifugo

Centrifugo real-time messaging server expert for WebSocket PUB/SUB, channel management, JWT authentication, event proxying, and…

@pedronauck@pedronauckInstall Skill
context7

context7

Retrieves up-to-date documentation, API references, and code examples for any developer technology. Use this skill whenever the…

@pedronauck@pedronauckInstall Skill
documentation-writer

documentation-writer

Diátaxis Documentation Expert. An expert technical writer specializing in creating high-quality software documentation, guided by…

@pedronauck@pedronauckInstall Skill

More skills from other plugins.

1password

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

openclaw3w393k
@openclaw@openclawInstall Skill

Questions about drizzle-safe-migrations.

Which coding agents can use drizzle-safe-migrations?
drizzle-safe-migrations installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.