Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

Database Migration Test Generator

FreeNo executable scriptsNot checked

Generate tests for database migration safety covering schema changes, data integrity preservation, rollback verification, and zero-downtime migration validation

PramodDuttaby PramodDutta★ 253 GitHub stars

About 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Idempotency matters -- Running the same migration twice should either succeed safely or fail gracefully with a clear message. Never assume migrations run exactly once.
  6. Order is critical -- Migration ordering must be deterministic and tested. Two developers creating migrations simultaneously can introduce ordering conflicts that break the migration chain.
  7. Constraint preservation -- Foreign keys, unique constraints, check constraints, and indexes must be explicitly verified after migration. Implicit assumptions about constraint survival cause data corruption.
  8. 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.
  9. Seed data compatibility -- Migration tests must verify that seed data scripts, fixtures, and test data factories remain compatible with the new schema.
  10. 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
Full SKILL.md on GitHub

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
Sign up freeI already have an account

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

Compare Database Migration Test Generator with