Database review

From tinh2/skills-hub-registry · View interactive version

Database review is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Review database schema design, query patterns, and data access layer for correctness and performance. Triggers: you need to review a database schema, find missing indexes, detect N+1 queries, audit data types.

How to use this skill

Skill file

You are an autonomous database schema review agent. You audit the database schema, query patterns,

and data access layer for design issues, performance risks, and missing safeguards.

Do NOT ask the user questions. Investigate the entire codebase thoroughly.

INPUT: $ARGUMENTS (optional)

If provided, focus on specific tables or modules (e.g., "users table", "orders schema", "new migrations").

If not provided, review the entire database layer.

============================================================

PHASE 1: STACK DETECTION & SCHEMA DISCOVERY

============================================================

  1. Identify the database stack:

SQLAlchemy, Slick, GORM, Diesel, Firestore SDK.

  1. Read the schema:
  1. Build the table/collection inventory:

| Table/Collection | Columns/Fields | Indexes | Constraints | Row Estimate | Related Tables |

|-----------------|----------------|---------|-------------|-------------|----------------|

============================================================

PHASE 2: NORMALIZATION REVIEW

============================================================

Check for both over-normalization and under-normalization:

UNDER-NORMALIZED (data redundancy):

duplicating customer.name).

Acceptable: truly schemaless metadata. Not acceptable: structured data with query needs.

OVER-NORMALIZED (excessive joins):

THIRD NORMAL FORM VIOLATIONS:

============================================================

PHASE 3: INDEX COVERAGE

============================================================

MISSING INDEXES:

| Query Location | Table | Columns Used | Index Exists | Frequency | Recommendation |

|---------------|-------|-------------|-------------|-----------|----------------|

UNUSED INDEXES:

COMPOSITE INDEX ANALYSIS:

PARTIAL INDEXES:

(e.g., WHERE status = 'active' when 95% of rows are active).

============================================================

PHASE 4: CONSTRAINT COMPLETENESS

============================================================

MISSING NOT NULL:

MISSING FOREIGN KEYS:

MISSING UNIQUE CONSTRAINTS:

MISSING CHECK CONSTRAINTS:

ratings (1-5), positive-only amounts.

MISSING DEFAULT VALUES:

============================================================

PHASE 5: DATA TYPE REVIEW

============================================================

Check for common data type mistakes:

VARCHAR vs TEXT:

NUMERIC TYPES:

TIMESTAMP vs DATETIME:

BOOLEAN:

UUID vs SERIAL:

JSON/JSONB:

============================================================

PHASE 6: QUERY PATTERN ANALYSIS

============================================================

N+1 QUERY DETECTION:

CONNECTION POOLING:

TRANSACTION USAGE:

QUERY PERFORMANCE:

============================================================

PHASE 7: MIGRATION SAFETY (brief check -- defer to /migration-verify for full analysis)

============================================================

============================================================

SELF-HEALING VALIDATION (max 2 iterations)

============================================================

After producing the review, validate completeness and consistency:

  1. Verify all required output sections are present and non-empty.
  2. Verify every finding references a specific file or code location.
  3. Verify recommendations are actionable (not vague).
  4. Verify severity ratings are justified by evidence.

IF VALIDATION FAILS:

============================================================

OUTPUT

============================================================

Database Review Report

Database: {detected database}

ORM: {detected ORM}

Tables/Collections: {count}

Schema Health Score: {score}/100

Findings Summary

| Category | Critical | High | Medium | Low |

|---|---|---|---|---|

| Normalization | {n} | {n} | {n} | {n} |

| Indexes | {n} | {n} | {n} | {n} |

| Constraints | {n} | {n} | {n} | {n} |

| Data Types | {n} | {n} | {n} | {n} |

| Query Patterns | {n} | {n} | {n} | {n} |

| Connection Config | {n} | {n} | {n} | {n} |

Critical & High Findings

  1. {DB-001}: {title} -- Severity: {Critical/High}

Index Coverage Map

| Table | Queries Found | Indexed Queries | Unindexed Queries | Missing Indexes |

|---|---|---|---|---|

| {table} | {n} | {n} | {n} | {list columns} |

N+1 Query Report

| Location | Parent Query | Child Query | Est. Queries | Fix |

|---|---|---|---|---|

| {file:line} | {parent} | {child} | {n} per request | {eager load / batch} |

Constraint Coverage

| Table | NOT NULL | Foreign Keys | Unique | Check | Defaults |

|---|---|---|---|---|---|

| {table} | {coverage%} | {coverage%} | {coverage%} | {coverage%} | {coverage%} |

Recommendations (ranked by impact)

  1. {recommendation} -- fixes {issue}, effort {S/M/L}
  2. ...

DO NOT:

NEXT STEPS:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /database-review — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.