ワンクリックで
database
This skill should be used when reviewing database queries, migrations, indexes, or schema changes.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
This skill should be used when reviewing database queries, migrations, indexes, or schema changes.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Canonical algorithm for consuming DECISIONS_CONTEXT index — scan index, identify relevant entries, Read full bodies on demand, cite verbatim IDs inline.
This skill should be used when evaluating implementation quality before submission, checking correctness, security, and simplicity.
This skill should be used when performing a code review to apply the standard 6-step review process.
This skill should be used when the user asks to "add accessibility", "check ARIA", "handle keyboard navigation", "add focus management", or creates UI components, forms, or interactive elements. Provides WCAG 2.2 AA patterns for keyboard navigation, ARIA roles and states, focus management, color contrast, and screen reader support.
Consumption algorithm for FEATURE_KNOWLEDGE variable — pre-computed feature context
This skill should be used when reviewing code for SOLID violations, tight coupling, or layering issues.
| name | database |
| description | This skill should be used when reviewing database queries, migrations, indexes, or schema changes. |
| user-invocable | false |
| allowed-tools | Read, Grep, Glob |
Domain expertise for database design and optimization. Use alongside devflow:review-methodology for complete database reviews.
EVERY QUERY MUST HAVE AN EXECUTION PLAN
Never deploy a query without understanding its execution plan. Every WHERE clause needs an index analysis. Every JOIN needs cardinality consideration. "It works in dev" is not validation. Production data volumes will expose every missing index and inefficient join.
| Issue | Problem | Solution |
|---|---|---|
| Missing Foreign Keys | No referential integrity, orphaned records | Add FK with ON DELETE action |
| Denormalization | Unnecessary duplication, update anomalies | Normalize unless performance requires |
| Poor Data Types | VARCHAR for everything, lost precision | Use appropriate types (DECIMAL, BOOLEAN, TIMESTAMP) |
| Missing Constraints | No data validation at DB level | Add NOT NULL, CHECK, UNIQUE constraints |
Example - Missing Constraints:
-- VIOLATION
CREATE TABLE products (id SERIAL, name VARCHAR(100), price DECIMAL);
-- CORRECT
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL CHECK (LENGTH(TRIM(name)) > 0),
price DECIMAL(10, 2) NOT NULL CHECK (price >= 0)
);
| Issue | Problem | Solution |
|---|---|---|
| N+1 Queries | Query per iteration, O(n) round trips | JOIN or batch with IN/ANY |
| Missing Indexes | Full table scans on large tables | Add indexes for WHERE/JOIN columns |
| Full Table Scans | Functions prevent index use | Functional indexes or query rewrite |
| Inefficient JOINs | Joining before filtering | Filter early, select specific columns |
Example - N+1 Query:
// VIOLATION: 101 queries for 100 users
for (const user of users) {
user.orders = await db.query('SELECT * FROM orders WHERE user_id = ?', [user.id]);
}
// CORRECT: 2 queries total
const orders = await db.query('SELECT * FROM orders WHERE user_id = ANY($1)', [userIds]);
| Issue | Problem | Solution |
|---|---|---|
| Breaking Changes | Data loss, no recovery path | Phased approach with backups |
| Data Loss Risk | Type changes truncate data | Validate before changing types |
| Missing Rollback | Cannot undo migration | Always implement down() method |
| Performance Impact | Table locks during migration | Add columns nullable, backfill in batches |
Example - Safe Column Addition:
-- Step 1: Add nullable (instant)
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
-- Step 2: Backfill in batches
UPDATE users SET phone = 'UNKNOWN' WHERE phone IS NULL AND id BETWEEN 1 AND 10000;
-- Step 3: Add constraint after backfill
ALTER TABLE users ALTER COLUMN phone SET NOT NULL;
| Issue | Problem | Solution |
|---|---|---|
| SQL Injection | String interpolation in queries | Parameterized queries only |
| Excessive Privileges | App has GRANT ALL | Minimum required privileges |
Example - SQL Injection:
// VULNERABLE
const query = `SELECT * FROM users WHERE email = '${email}'`;
// SECURE
const query = 'SELECT * FROM users WHERE email = $1';
await db.query(query, [email]);
For detailed examples and detection commands, see:
| Severity | Criteria | Examples |
|---|---|---|
| CRITICAL | Data integrity or severe performance | SQL injection, N+1 unbounded, data loss migrations, missing FK on critical relations |
| HIGH | Significant database issues | Inefficient JOINs, missing constraints, migrations without rollback |
| MEDIUM | Moderate concerns | Minor denormalization, missing non-critical indexes |
| LOW | Minor improvements | Naming conventions, index organization |
Before approving database changes: