Generates database test factories, transaction wrappers, and assertions for automated testing. Supports schema validation, migration testing, and cleanup strategies.
How this command is triggered — by the user, by Claude, or both
Slash command
/database-test-manager:db-testFiles this command reads when invoked
The summary Claude sees in its command listing — used to decide when to auto-load this command
# Database Test Manager Comprehensive database testing utilities including test data generation, transaction management, schema validation, migration testing, and database cleanup. ## What You Do 1. **Test Data Management** - Generate realistic test data with factories - Create database fixtures and seeds - Set up test database state 2. **Transaction Management** - Wrap tests in transactions with automatic rollback - Implement database cleanup strategies - Handle nested transactions 3. **Schema Validation** - Verify database schema matches models - Test migratio...
Comprehensive database testing utilities including test data generation, transaction management, schema validation, migration testing, and database cleanup.
Test Data Management
Transaction Management
Schema Validation
Database Testing Patterns
When invoked, you should:
## Database Test Suite
### Database: [Type]
**ORM:** [Prisma / TypeORM / SQLAlchemy / ActiveRecord]
**Test Framework:** [Jest / Pytest / RSpec]
### Test Data Factories
\`\`\`javascript
// factories/userFactory.js
import { faker } from '@faker-js/faker';
export const userFactory = {
build: (overrides = {}) => ({
id: faker.string.uuid(),
email: faker.internet.email(),
name: faker.person.fullName(),
createdAt: new Date(),
...overrides
}),
create: async (overrides = {}) => {
const data = userFactory.build(overrides);
return await prisma.user.create({ data });
},
createMany: async (count, overrides = {}) => {
const users = Array.from({ length: count }, () =>
userFactory.build(overrides)
);
return await prisma.user.createMany({ data: users });
}
};
\`\`\`
### Transaction Wrapper
\`\`\`javascript
// testHelpers/dbHelper.js
export const withTransaction = (testFn) => {
return async () => {
return await prisma.$transaction(async (tx) => {
try {
await testFn(tx);
} finally {
// Transaction will rollback automatically
throw new Error('ROLLBACK');
}
}).catch(err => {
if (err.message !== 'ROLLBACK') throw err;
});
};
};
// Usage in tests
describe('User Service', () => {
it('should create user', withTransaction(async (tx) => {
const user = await userFactory.create();
expect(user.email).toBeDefined();
// Rolls back automatically after test
}));
});
\`\`\`
### Database Assertions
\`\`\`javascript
// Custom matchers
expect.extend({
async toExistInDatabase(tableName, conditions) {
const record = await prisma[tableName].findFirst({
where: conditions
});
return {
pass: record !== null,
message: () =>
`Expected ${tableName} with ${JSON.stringify(conditions)} ` +
`to ${record ? '' : 'not '}exist in database`
};
},
async toHaveCount(tableName, expectedCount) {
const count = await prisma[tableName].count();
return {
pass: count === expectedCount,
message: () =>
`Expected ${tableName} to have ${expectedCount} records, ` +
`but found ${count}`
};
}
});
// Usage
await expect('user').toExistInDatabase({ email: '[email protected]' });
await expect('user').toHaveCount(5);
\`\`\`
### Migration Testing
\`\`\`javascript
describe('Database Migrations', () => {
it('should run migrations up and down', async () => {
// Run all migrations
await runMigrations('up');
// Verify schema
const tables = await getTables();
expect(tables).toContain('users');
expect(tables).toContain('posts');
// Rollback migrations
await runMigrations('down');
// Verify tables removed
const tablesAfter = await getTables();
expect(tablesAfter).not.toContain('users');
});
it('should enforce constraints', async () => {
const user = await userFactory.create();
// Test foreign key constraint
await expect(
prisma.post.create({
data: {
title: 'Test',
userId: 'non-existent-id'
}
})
).rejects.toThrow('Foreign key constraint');
// Test unique constraint
await expect(
userFactory.create({ email: user.email })
).rejects.toThrow('Unique constraint');
});
});
\`\`\`
### Query Performance Testing
\`\`\`javascript
describe('Query Performance', () => {
beforeAll(async () => {
// Seed large dataset
await userFactory.createMany(10000);
});
it('should query efficiently with indexes', async () => {
const start = performance.now();
await prisma.user.findMany({
where: { email: { contains: '@example.com' } }
});
const duration = performance.now() - start;
expect(duration).toBeLessThan(100); // 100ms threshold
});
it('should use proper indexes', async () => {
const explain = await prisma.$queryRaw`
EXPLAIN ANALYZE
SELECT * FROM users WHERE email LIKE '%@example.com%'
`;
expect(explain).toContain('Index Scan');
expect(explain).not.toContain('Seq Scan'); // No full table scan
});
});
\`\`\`
### Database Cleanup
\`\`\`javascript
// testSetup.js
beforeEach(async () => {
// Clear all tables in reverse dependency order
await prisma.comment.deleteMany();
await prisma.post.deleteMany();
await prisma.user.deleteMany();
});
afterAll(async () => {
await prisma.$disconnect();
});
\`\`\`
### Test Configuration
\`\`\`javascript
// jest.config.js
module.exports = {
testEnvironment: 'node',
setupFilesAfterEnv: ['./tests/setup.js'],
globalSetup: './tests/globalSetup.js',
globalTeardown: './tests/globalTeardown.js'
};
// globalSetup.js
module.exports = async () => {
// Create test database
execSync('createdb myapp_test');
// Run migrations
process.env.DATABASE_URL = 'postgresql://localhost/myapp_test';
execSync('npx prisma migrate deploy');
};
\`\`\`
### Next Steps
- [ ] Implement test data factories
- [ ] Set up transaction rollback
- [ ] Add database assertions
- [ ] Test migrations
- [ ] Configure test database
npx claudepluginhub aiminnovations/claude-code-plugins-plus --plugin database-test-manager19plugins reuse this command
First indexed Dec 31, 2025
Showing the 6 earliest of 19 plugins
/db-testGenerates database test factories, transaction wrappers, and assertions for automated testing. Supports schema validation, migration testing, and cleanup strategies.
/seed-dbDetects the project's database and ORM, reads the schema, generates a seed script with realistic test data, and runs it safely with transaction wrapping and idempotent checks.
/f5-dbManages database operations including schema viewing, migrations, seeding, model generation, and ER diagrams for auto-detected project stack. Supports schema, migrate, seed, model, diagram subcommands.
/seed-dataGenerates realistic seed data scripts for dev or test environments. Accepts table names, schema files, or free-form descriptions and produces properly formatted fixtures matching the project conventions.
/prisma-schema-genGenerates a complete Prisma schema file from natural language descriptions, including models, relationships, indexes, and constraints.
/generateGenerates API clients from OpenAPI specs, data models from JSON schemas, test suites from code, and database migrations from models. Supports TypeScript, Python, Go, Java, C#.