database-testing
关于
This Claude Skill provides specialized database testing capabilities including schema validation, data integrity checks, and migration testing. It enables developers to verify transaction isolation, measure query performance, and ensure ACID compliance. Use it when testing data persistence, validating database migrations, or ensuring referential integrity in your applications.
快速安装
Claude Code
推荐/plugin add https://github.com/proffesor-for-testing/agentic-qegit clone https://github.com/proffesor-for-testing/agentic-qe.git ~/.claude/skills/database-testing在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Database Testing
<default_to_action> When testing database operations:
- VALIDATE schema (tables, columns, constraints exist as expected)
- TEST data integrity (unique, foreign key, check constraints)
- VERIFY migrations (forward works, rollback works, data preserved)
- CHECK transaction isolation (ACID properties, concurrent access)
- MEASURE query performance (indexes used, execution time)
Quick DB Testing Checklist:
- Schema matches specification
- Unique constraints prevent duplicates
- Foreign keys prevent orphaned records
- Migrations are reversible
- Transactions roll back on error
Critical Success Factors:
- Database bugs cause data loss/corruption (catastrophic)
- Test migrations in staging before production
- Transaction tests catch concurrency bugs </default_to_action>
Quick Reference Card
When to Use
- New table/schema creation
- Migration development
- Data integrity validation
- Query performance optimization
Database Test Types
| Type | Focus | When |
|---|---|---|
| Schema | Structure correct | Table creation |
| Integrity | Constraints work | Data operations |
| Migration | Up/down work | Schema changes |
| Transaction | ACID properties | Concurrent access |
| Performance | Query speed | Optimization |
ACID Properties
| Property | Test Focus |
|---|---|
| Atomicity | All or nothing (rollback on error) |
| Consistency | Constraints always valid |
| Isolation | Concurrent transactions don't interfere |
| Durability | Committed data persists |
Schema Testing
test('users table has correct schema', async () => {
const schema = await db.raw(`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'users'
`);
expect(schema).toContainEqual({
column_name: 'id',
data_type: 'integer',
is_nullable: 'NO'
});
expect(schema).toContainEqual({
column_name: 'email',
data_type: 'character varying',
is_nullable: 'NO'
});
});
Data Integrity Testing
test('email must be unique', async () => {
await db.users.create({ email: '[email protected]' });
await expect(
db.users.create({ email: '[email protected]' })
).rejects.toThrow('unique constraint violation');
});
test('foreign key prevents orphaned records', async () => {
const user = await db.users.create({ email: '[email protected]' });
await db.orders.create({ userId: user.id, total: 100 });
await expect(
db.users.delete({ id: user.id })
).rejects.toThrow('foreign key constraint');
});
Migration Testing
test('migration is reversible', async () => {
await migrate('add-users-table');
// Table exists after migration
const tables = await db.raw(`SELECT table_name FROM information_schema.tables`);
expect(tables.map(t => t.table_name)).toContain('users');
await rollback('add-users-table');
// Table gone after rollback
const tablesAfter = await db.raw(`SELECT table_name FROM information_schema.tables`);
expect(tablesAfter.map(t => t.table_name)).not.toContain('users');
});
test('migration preserves existing data', async () => {
await db.users.create({ email: '[email protected]' });
await migrate('add-age-column');
const user = await db.users.findOne({ email: '[email protected]' });
expect(user).toBeDefined();
expect(user.age).toBeNull(); // New column, null default
});
Transaction Testing
test('transaction rolls back on error', async () => {
const initialCount = await db.users.count();
try {
await db.transaction(async (trx) => {
await trx('users').insert({ email: '[email protected]' });
await trx('users').insert({ email: '[email protected]' });
throw new Error('Rollback test');
});
} catch (error) { /* Expected */ }
expect(await db.users.count()).toBe(initialCount);
});
test('concurrent transactions isolated', async () => {
const user = await db.users.create({ balance: 100 });
// Two concurrent withdrawals (race condition test)
await Promise.all([
db.transaction(async (trx) => {
const current = await trx('users').where({ id: user.id }).first();
await trx('users').update({ balance: current.balance - 50 });
}),
db.transaction(async (trx) => {
const current = await trx('users').where({ id: user.id }).first();
await trx('users').update({ balance: current.balance - 50 });
})
]);
const final = await db.users.findOne({ id: user.id });
expect(final.balance).toBe(0); // Proper isolation
});
Agent-Driven Database Testing
// Generate test data with integrity
await Task("Generate Test Data", {
schema: 'ecommerce',
tables: ['users', 'products', 'orders'],
count: { users: 1000, products: 500, orders: 5000 },
preserveReferentialIntegrity: true
}, "qe-test-data-architect");
// Test migration safety
await Task("Migration Test", {
migration: 'add-payment-status-column',
tests: ['forward', 'rollback', 'data-preservation'],
environment: 'staging'
}, "qe-test-executor");
Agent Coordination Hints
Memory Namespace
aqe/database-testing/
├── schema-snapshots/* - Current schema state
├── migrations/* - Migration test results
├── integrity/* - Constraint validation
└── performance/* - Query benchmarks
Fleet Coordination
const dbFleet = await FleetManager.coordinate({
strategy: 'database-testing',
agents: [
'qe-test-data-architect', // Generate test data
'qe-test-executor', // Run DB tests
'qe-performance-tester' // Query performance
],
topology: 'sequential'
});
Related Skills
- test-data-management - Generate test data
- performance-testing - Query performance
- compliance-testing - Data protection
Remember
Database bugs are catastrophic. Data loss is unrecoverable. Corruption spreads silently. Performance issues compound.
Test migrations before production: Forward works, rollback works, data preserved, performance acceptable. Never deploy untested migrations.
With Agents: qe-test-data-architect generates realistic test data with referential integrity. qe-test-executor validates migrations automatically in CI/CD.
GitHub 仓库
相关推荐技能
performance-analysis
其他该Skill为Claude Flow群组提供全面的性能分析,能自动检测通信、处理和网络等瓶颈。它通过实时监控和性能剖析生成详细报告,并给出AI驱动的优化建议。开发者可快速识别系统性能问题并获得具体改进方案。
when-profiling-performance-use-performance-profiler
其他这是一个全面的性能分析工具,帮助开发者识别和优化应用性能瓶颈。它支持跨平台性能分析,涵盖CPU、内存、I/O和网络等关键维度。通过基准测试、瓶颈检测和根因分析,为性能优化提供系统化的解决方案。
performance-analysis
其他这个Claude Skill为开发者提供全面的性能分析和瓶颈检测功能,帮助优化Claude Flow群集的运行效率。它能实时监控系统性能、识别通信和处理瓶颈,并生成详细的优化建议报告。开发者可以用它快速定位性能问题并获得AI驱动的改进方案。
when-analyzing-performance-use-performance-analysis
其他该Skill为Claude Flow集群提供全面的性能分析,帮助开发者识别瓶颈并给出优化建议。它包含性能分析、基准测试等专业代理,适用于已部署工作流的性能调优场景。通过详细的指标分析和具体优化方案,能显著提升集群运行效率。
