database-testing について
database-testingは、データベースのスキーマ、データ整合性、操作を検証するテストスキルです。開発・テストチーム向けに、マイグレーションのロールバック、トランザクション分離、クエリ性能を扱います。
主な機能
- 01スキーマと制約の検証
- 02一意性・外部キー整合性の確認
- 03マイグレーションとロールバックのテスト
- 04トランザクションのロールバックと並行性の検証
- 05クエリ性能とインデックス利用の測定
活用シーン
- 01新規テーブルやデータベース構造のテスト
- 02マイグレーションと可逆性の確認
- 03整合性やクエリ性能の問題調査
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ proffesor-for-testing/ agentic-qe --skill database-testingインストール後、Claude Code で/database-testingを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
evals/database-testing.yamlschemas/output.jsonscripts/validate-config.json詳細
データベーステスト
<default_to_action> データベース操作をテストする際は、次の手順に従います。
- スキーマを検証します(テーブル、カラム、制約が想定どおりに存在すること)
- データの整合性をテストします(一意制約、外部キー制約、チェック制約)
- マイグレーションを検証します(適用できること、ロールバックできること、データが保持されること)
- トランザクションの分離性を確認します(ACID 特性、同時アクセス)
- クエリのパフォーマンスを測定します(インデックスが使用されること、実行時間)
データベーステストのクイックチェックリスト:
- スキーマが仕様と一致している
- 一意制約によって重複が防止される
- 外部キー制約によって孤立レコードが防止される
- マイグレーションを元に戻せる
- エラー発生時にトランザクションがロールバックされる
重要な成功要因:
- データベースのバグはデータの損失や破損を引き起こします(壊滅的です)
- 本番環境に適用する前に、ステージング環境でマイグレーションをテストします
- トランザクションのテストで並行性のバグを検出できます </default_to_action>
クイックリファレンスカード
使用する場面
- 新しいテーブルやスキーマの作成
- マイグレーションの開発
- データ整合性の検証
- クエリパフォーマンスの最適化
データベーステストの種類
| 種類 | 焦点 | 使用する場面 |
|---|---|---|
| スキーマ | 構造が正しいこと | テーブルの作成 |
| 整合性 | 制約が機能すること | データ操作 |
| マイグレーション | 適用とロールバックが機能すること | スキーマの変更 |
| トランザクション | ACID 特性 | 同時アクセス |
| パフォーマンス | クエリ速度 | 最適化 |
スキーマテスト
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'
});
});
データ整合性テスト
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');
});
マイグレーションテスト
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
});
トランザクションテスト
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
});
エージェント主導のデータベーステスト
// 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");
エージェント連携のヒント
メモリの名前空間
aqe/database-testing/
├── schema-snapshots/* - Current schema state
├── migrations/* - Migration test results
├── integrity/* - Constraint validation
└── performance/* - Query benchmarks
フリート連携
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'
});
関連するスキル
- test-data-management - テストデータを生成します
- performance-testing - クエリパフォーマンス
- compliance-testing - データ保護
忘れないでください
本番環境に適用する前にマイグレーションをテストします: 適用できること、ロールバックできること、データが保持されること、パフォーマンスが許容範囲であることを確認します。テストしていないマイグレーションは決してデプロイしないでください。
エージェントを使用する場合: qe-test-data-architect は、参照整合性を保った現実的なテストデータを生成します。qe-test-executor は、CI/CD でマイグレーションを自動的に検証します。
コメント
Markdown 対応