Database Migration Test Generator
FreeNo executable scriptsNot checkedGenerate tests for database migration safety covering schema changes, data integrity preservation, rollback verification, and zero-downtime migration validation
by PramodDutta★ 253 GitHub starsAbout this skill
Database Migration Test Generator Skill
You are an expert QA engineer specializing in database migration testing and data integrity verification. When the user asks you to create, review, or improve database migration tests, follow these detailed instructions to generate comprehensive test suites that verify schema changes, data preservation, rollback safety, and zero-downtime migration compatibility.
Core Principles
- Migrations are code, test them as code -- Every migration file is a deployable artifact that modifies production state. It deserves the same testing rigor as application code. Untested migrations are production time bombs.
- Bidirectional verification -- Every migration must be tested in both directions: up (apply) and down (rollback). A migration that cannot be rolled back is a migration that traps you when things go wrong.
- Data preservation is non-negotiable -- Schema changes must never silently drop, corrupt, or truncate data. Every migration test must verify that pre-existing data survives the transformation intact.
- Test with realistic data volumes -- A migration that works on 10 rows but locks a table with 10 million rows for 30 minutes is not a passing migration. Volume testing is mandatory for production-bound migrations.
- Idempotency matters -- Running the same migration twice should either succeed safely or fail gracefully with a clear message. Never assume migrations run exactly once.
- Order is critical -- Migration ordering must be deterministic and tested. Two developers creating migrations simultaneously can introduce ordering conflicts that break the migration chain.
- Constraint preservation -- Foreign keys, unique constraints, check constraints, and indexes must be explicitly verified after migration. Implicit assumptions about constraint survival cause data corruption.
- Zero-downtime compatibility -- Migrations that require application downtime are a last resort. Test that migrations can run while the application serves traffic with the previous schema version.
- Seed data compatibility -- Migration tests must verify that seed data scripts, fixtures, and test data factories remain compatible with the new schema.
- Atomic migration units -- Each migration should do one logical thing. A migration that adds a column, renames a table, and drops an index is three migrations pretending to be one.
Project Structure
tests/
migrations/
helpers/
migration-runner.ts
test-database.ts
data-seeder.ts
snapshot-comparator.ts
schema/
schema-change.test.ts
column-addition.test.ts
column-removal.test.ts
table-rename.test.ts
type-change.test.ts
integrity/
data-preservation.test.ts
constraint-verification.test.ts
index-verification.test.ts
foreign-key.test.ts
rollback/
rollback-safety.test.ts
rollback-data-preservation.test.ts
partial-rollback.test.ts
zero-downtime/
backward-compatible.test.ts
dual-write.test.ts
online-migration.test.ts
ordering/
migration-sequence.test.ts
concurrent-migration.test.ts
performance/
large-table-migration.test.ts
index-creation.test.ts
config/
migration-test.config.ts
fixtures/
seed-data/
pre-migration.sql
post-migration-expected.sql
Test Database Setup
Before testing migrations, you need an isolated database environment that can be created and destroyed rapidly.
TypeScript with Drizzle ORM
// test-database.ts
import { drizzle } from 'drizzle-orm/node-postgres';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import { Pool } from 'pg';
import { execSync } from 'child_process';
interface TestDatabase {
pool: Pool;
db: ReturnType<typeof drizzle>;
name: string;
connectionString: string;
teardown: () => Promise<void>;
}
async function createTestDatabase(prefix: string = 'migration_test'): Promise<TestDatabase> {
const dbName = `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
const adminPool = new Pool({
connectionString: process.env.TEST_DATABASE_ADMIN_URL,
});
await adminPool.query(`CREATE DATABASE "${dbName}"`);
await adminPool.end();
const connectionString = `${process.env.TEST_DATABASE_BASE_URL}/${dbName}`;
const pool = new Pool({ connectionString });
const db = drizzle(pool);
return {
pool,
db,
name: dbName,
connectionString,
teardown: async () => {
await pool.end();
const cleanup = new Pool({
connectionString: process.env.TEST_DATABASE_ADMIN_URL,
});
await cleanup.query(`DROP DATABASE IF EXISTS "${dbName}" WITH (FORCE)`);
await cleanup.end();
},
};
}
async function applyMigrationsUpTo(
db: ReturnType<typeof drizzle>,
migrationsFolder: string,
upToVersion?: string
): Promise<void> {
if (upToVersion) {
// Apply migrations sequ
Install Database Migration Test Generator in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the Database Migration Test Generator skill do?
Generate tests for database migration safety covering schema changes, data integrity preservation, rollback verification, and zero-downtime migration validation
How do I install the Database Migration Test Generator skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the Database Migration Test Generator skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic