database-migrations
Skill1 starsChanged 6 months agoMITView on GitHub
Manages Drizzle ORM migration generation, safety review, testing, and rollback procedures. Detects schema changes, runs drizzle-kit generate, reviews generated SQL for destructive operations, tests migrations against a copy database, and provides rollback strategies. Keywords: migration, drizzle-kit, schema-change, alter-table, add-column, rename, rollback, destructive, sql, migrate, database, version, deploy, ci, safety
- Deletes or force-pushes
- Installs packages
71 other projects use a version of this.
Adopted by
Most recently taken up by
- KevinLoichot/everything-claude-codetheir own version, first seen Nov 29, 2026
- aayushsoam/clawbot-plustheir own version, first seen Nov 29, 2026
- multiplex-ai/muggle-ai-teamstheir own version, first seen Nov 29, 2026
- Cyvid7-Darus10/claude-code-configtheir own version, first seen Nov 29, 2026
- satvikgbusiness-jpg/Claude-skillstheir own version, first seen Nov 29, 2026
- leileigwl/claude-skillstheir own version, first seen Nov 29, 2026
Used with
Projects with it also use docker-and-compose, add-a-use-case and 10 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.
JameMy0001Skilldocker-and-compose
Production containerization patterns, multi-stage Dockerfiles, Docker Compose orchestrations, non-root security hardening, and cache optimization.
Also in 6 projects that use this
LeanMeanCleanAppsSkilladd-a-use-case
How to add a command or query to the Application layer as a vertical slice (request, handler, validator, tests) using source-generated Mediator. Use when adding a new feature, a new query, or a new write operation.
Also in 5 projects that use this
LeanMeanCleanAppsSkillbranches-and-pull-requests
Branch naming (feature/, fix/, chore/), how labels and release notes follow from the branch, the pull request template, and how changes get merged in the template repository. Use when creating a branch, writing a commit or opening a pull request.
Also in 5 projects that use this
- +9 more from LeanMeanCleanApps
Other versions71 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 71
- LeanMeanCleanApps/CleanMinimalApi★ 401same name
- loulanyue/awesome-claude-notes★ 272same name
- langchain-ai/skills-benchmarks★ 116same name
- Fmarzochi/EGC★ 61same name
- skateddu/claude-code-python-setup★ 28same name
- LeanMeanCleanApps/CleanGraphQLApi★ 13same name
- wpank/ai★ 11same name
- gongyijie85/dsh-ecc★ 8same name
- reddygopalkrishna/developer-agent-skills★ 8same name
- zero-click/zero-ratchet★ 8same name
61 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-authenticationSkill
- api-documentationSkill
- api-performanceSkill
- api-securitySkill
- api-testing-verificationSkill
- api-validationSkill
- database-designSkill
- deployment-config-generatorSkill
- route-generationSkill
- schema-intakeSkill
- tdd-from-schemaSkill
The file
We split this skill into the rules it gives an agent
9 rules. 1 is common, 8 are distinctive, and 0 are very specific to this project.
1
Common
Most of the 68 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Before deploying schema changes to staging or production.
- Distinctive: line 26
When reviewing or troubleshooting migration failures.
- Distinctive: line 40
Before generating a migration, verify there are actual changes:
- Distinctive: line 47
If no changes detected, stop here.
- Distinctive: line 290
Add migration testing to the CI/CD pipeline:
- Common: line 348
Before applying any migration to production:
- Distinctive: line 351
Test migration against a copy of production data.
- Distinctive: line 352
Run integration tests against the migrated database.
- Distinctive: line 355
Verify staging is healthy.
“Common” is measured: kept by at least 6 in 10 of the 68 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Migrations
Purpose
Manages the full lifecycle of database schema changes using Drizzle ORM migrations. Provides safe patterns for common operations (add column, rename, backfill), reviews generated SQL for destructive changes, tests migrations before applying to production, and documents rollback procedures.
When to Use
- A Drizzle schema file has been modified and migrations need generating.
- The user says "migrate", "schema change", "add column", "rename table", or "rollback".
- Before deploying schema changes to staging or production.
- When reviewing or troubleshooting migration failures.
Inputs
| Input | Required | Description |
| Drizzle schemas | Yes | api/src/db/schema/*.ts |
| Drizzle config | Yes | api/drizzle.config.ts |
| Existing migrations | No | api/src/db/migrations/ |
Steps
Step 1 -- Detect Schema Changes
Before generating a migration, verify there are actual changes:
# Preview what drizzle-kit would generate without writing files
cd api && npx drizzle-kit generate --dry-runIf no changes detected, stop here. Do not generate empty migrations.
Step 2 -- Generate Migration
cd api && npx drizzle-kit generateThis creates a new SQL file in api/src/db/migrations/. The file name follows
the pattern NNNN_migration_name.sql.
Step 3 -- Review Generated SQL for Safety
Destructive operation checklist:
| Operation | Risk Level | Action Required |
| DROP TABLE | Critical | Require explicit confirmation, backup data first |
| DROP COLUMN | Critical | Require explicit confirmation, backup data first |
| ALTER COLUMN type | High | Check for data loss, test with production data copy |
| ALTER COLUMN NOT NULL | High | Ensure no null values exist, add default first |
| DROP INDEX | Medium | Verify no queries depend on it |
| RENAME TABLE | Medium | Update all references, use alias during transition |
| RENAME COLUMN | Medium | Update all application code references |
| ADD COLUMN NOT NULL | Medium | Must have DEFAULT or existing rows will fail |
Safety review script:
// scripts/review-migration.ts
import { readFile, readdir } from 'fs/promises';
import path from 'path';
const DANGEROUS_PATTERNS = [
{ pattern: /DROP TABLE/i, level: 'CRITICAL', message: 'Table will be permanently deleted' },
{ pattern: /DROP COLUMN/i, level: 'CRITICAL', message: 'Column data will be permanently lost' },
{ pattern: /ALTER.*TYPE/i, level: 'HIGH', message: 'Column type change may cause data loss' },
{ pattern: /SET NOT NULL/i, level: 'HIGH', message: 'Existing null values will cause failure' },
{ pattern: /DROP INDEX/i, level: 'MEDIUM', message: 'Query performance may degrade' },
{ pattern: /RENAME/i, level: 'MEDIUM', message: 'Application code may need updating' },
{ pattern: /TRUNCATE/i, level: 'CRITICAL', message: 'All table data will be deleted' },
];
async function reviewLatestMigration() {
const migrationsDir = path.join(process.cwd(), 'src', 'db', 'migrations');
const files = await readdir(migrationsDir);
const sqlFiles = files
.filter((f) => f.endsWith('.sql'))
.sort()
.reverse();
if (sqlFiles.length === 0) {
console.log('No migration files found.');
return;
}
const latestFile = sqlFiles[0];
const sql = await readFile(
path.join(migrationsDir, latestFile),
'utf-8',
);
console.log(`Reviewing: ${latestFile}`);
console.log('─'.repeat(60));
const warnings: { level: string; message: string; line: string }[] = [];
const lines = sql.split('\n');
for (const line of lines) {
for (const check of DANGEROUS_PATTERNS) {
if (check.pattern.test(line)) {
warnings.push({
level: check.level,
message: check.message,
line: line.trim(),
});
}
}
}
if (warnings.length === 0) {
console.log('No dangerous operations detected. Migration looks safe.');
} else {
console.log(`Found ${warnings.length} warning(s):\n`);
for (const w of warnings) {
console.log(` [${w.level}] ${w.message}`);
console.log(` SQL: ${w.line}\n`);
}
}
}
reviewLatestMigration();Run the review:
cd api && pnpm tsx ../scripts/review-migration.tsStep 4 -- Safe Migration Patterns
Adding a column with a default (safe):
// In Drizzle schema -- add field with default
export const users = pgTable('users', {
// ... existing fields
bio: text('bio').default(''), // New field with default
});Generated SQL:
ALTER TABLE "users" ADD COLUMN "bio" text DEFAULT '';Adding a NOT NULL column to existing table (two-step):
Step 1: Add as nullable with default:
-- Migration 0002
ALTER TABLE "users" ADD COLUMN "phone" text DEFAULT '';Step 2: Backfill data, then add constraint:
-- Migration 0003
UPDATE "users" SET "phone" = '' WHERE "phone" IS NULL;
ALTER TABLE "users" ALTER COLUMN "phone" SET NOT NULL;Renaming a column safely (three-step):
-- Migration 0004: Add new column
ALTER TABLE "users" ADD COLUMN "full_name" text;
-- Migration 0005: Backfill data
UPDATE "users" SET "full_name" = "name";
ALTER TABLE "users" ALTER COLUMN "full_name" SET NOT NULL;
-- Migration 0006: Drop old column (after all code is updated)
ALTER TABLE "users" DROP COLUMN "name";Adding an index concurrently (no table lock):
-- Use CONCURRENTLY to avoid locking the table during index creation
CREATE INDEX CONCURRENTLY IF NOT EXISTS "users_full_name_idx"
ON "users" USING btree ("full_name");Note: Drizzle-kit does not support CONCURRENTLY by default. You may need to manually edit the generated SQL for large tables.
Step 5 -- Test Migration Against Copy Database
# Create a copy of the production database for testing
pg_dump --no-owner --no-acl production_db > /tmp/prod_copy.sql
createdb migration_test
psql migration_test < /tmp/prod_copy.sql
# Run the migration against the copy
DATABASE_URL=postgresql://localhost/migration_test \
npx drizzle-kit migrate
# Verify data integrity
psql migration_test -c "SELECT count(*) FROM users;"
psql migration_test -c "SELECT count(*) FROM books;"
# Run integration tests against the migrated copy
DATABASE_URL=postgresql://localhost/migration_test \
pnpm vitest run
# Clean up
dropdb migration_testStep 6 -- Apply Migration
# Apply to staging first
cd api && DATABASE_URL=$STAGING_DATABASE_URL npx drizzle-kit migrate
# Verify staging
curl -s https://api-staging.example.com/health | jq .
# Apply to production
cd api && DATABASE_URL=$PRODUCTION_DATABASE_URL npx drizzle-kit migrateStep 7 -- Rollback Procedures
Drizzle ORM does not have built-in rollback. Use manual SQL scripts:
// scripts/generate-rollback.ts
// For each migration, generate a corresponding rollback script
const ROLLBACK_MAP: Record<string, string> = {
'ADD COLUMN': 'DROP COLUMN',
'CREATE TABLE': 'DROP TABLE',
'CREATE INDEX': 'DROP INDEX',
};
function generateRollbackSQL(forwardSQL: string): string {
const lines = forwardSQL.split('\n').filter((l) => l.trim());
const rollback: string[] = [];
for (const line of lines.reverse()) {
if (line.match(/ALTER TABLE .* ADD COLUMN/i)) {
const table = line.match(/ALTER TABLE "(\w+)"/)?.[1];
const column = line.match(/ADD COLUMN "(\w+)"/)?.[1];
if (table && column) {
rollback.push(`ALTER TABLE "${table}" DROP COLUMN "${column}";`);
}
}
if (line.match(/CREATE TABLE/i)) {
const table = line.match(/CREATE TABLE.*"(\w+)"/)?.[1];
if (table) {
rollback.push(`DROP TABLE IF EXISTS "${table}" CASCADE;`);
}
}
if (line.match(/CREATE.*INDEX/i)) {
const index = line.match(/INDEX.*"(\w+)"/)?.[1];
if (index) {
rollback.push(`DROP INDEX IF EXISTS "${index}";`);
}
}
}
return rollback.join('\n');
}Step 8 -- CI Migration Testing
Add migration testing to the CI/CD pipeline:
# In .github/workflows/ci.yml
migration-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test_db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- run: cd api && pnpm install --frozen-lockfile
- name: Run migrations
run: cd api && npx drizzle-kit migrate
env:
DATABASE_URL: postgresql://test:test@localhost:5432/test_db
- name: Verify schema
run: cd api && npx drizzle-kit check
- name: Run tests against migrated db
run: cd api && pnpm vitest run
env:
DATABASE_URL: postgresql://test:test@localhost:5432/test_dbOutput
| Artifact | Location | Description |
| Migration files | api/src/db/migrations/*.sql | Generated SQL migrations |
| Migration review | Console output | Safety analysis of generated SQL |
| Rollback scripts | api/src/db/rollbacks/*.sql | Manual rollback SQL (if generated) |
Integration
| Skill | Relationship |
database-design | Initial migration generated during Phase 1 |
deployment-config-generator | Migration step in CI/CD pipeline |
api-testing-verification | Tests run against migrated database |
api-performance | Index changes affect query performance |
Migration Checklist
Before applying any migration to production:
- Review generated SQL for destructive operations.
- Test migration against a copy of production data.
- Run integration tests against the migrated database.
- Prepare rollback SQL script.
- Apply to staging environment first.
- Verify staging is healthy.
- Apply to production during low-traffic window.
- Monitor error rates and response times after deployment.
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
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.

