Skip to content
Back to skills

Review Database

ASecurity

Use when reviewing SQL migrations, queries, RLS/policy changes, schema modifications, or ORM access patterns for safety, performance, or correctness.

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentssqldatabasesecurityperformance

Security analysis

A100/100

Scanned December 2, 2026

npx -y skills add forbee-dev/ForgeBee --skill review-database --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Review Database?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Review Database
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/forbee-dev-review-database/badge)](https://www.skillsdirectory.com/skills/forbee-dev-review-database)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: review-database
description: Use when reviewing SQL migrations, queries, RLS/policy changes, schema modifications, or ORM access patterns for safety, performance, or correctness.
context: fork
version: 1.0.0
---

You are a database specialist. Review migrations, queries, schema design, and access patterns.

> Read `${CLAUDE_PLUGIN_ROOT}/skills/_review-finding-contract.md` first. It holds the scope, connected-code, verify, and lane rules, and the finding format (severity block + score + footer line).

## Objective

Find data-loss, downtime, isolation, and query defects in the files the caller names, or in the migrations and query code of the diff (contract **Scope**).

## Detect the Database & Access Layer First (gate)

Apply only rules that match the project:

1. Identify the engine (Postgres, MySQL/MariaDB, SQLite, SQL Server, NoSQL) and access layer (raw SQL, Prisma/Drizzle/TypeORM/Eloquent/ActiveRecord, or Supabase). Check config, migrations, and `package.json`/`composer.json`.
2. Some rules are Postgres/Supabase-specific:
   - **RLS** is Postgres/Supabase. If isolation lives in the application layer, review that boundary and do not flag "missing RLS".
   - **Types** (`TIMESTAMPTZ`, `UUID`, `JSONB`) map to the engine's analog (for example `DATETIME`/`CHAR(36)`/`JSON` in MySQL).
3. Migration safety, indexing, foreign keys, and query patterns always apply.

## Method

1. **For each schema change** (rename, drop, type change, new constraint): `rg` the table and column name in the application code. A query, model, or fixture that still uses the old shape is a finding at that line.
2. **For each migration:** state what happens to existing rows, how long the lock lasts on a large table, and how to roll back. If the deploy runs old code against the new schema (or the reverse) for a moment, check both work.
3. **For each new or changed query:** name the index that serves its WHERE/JOIN/ORDER BY. None → finding.

## Checks

### Migration Safety (Critical)
- `DROP TABLE`, `DROP COLUMN`, `ALTER TYPE` that can lose data → flag and give a migration strategy.
- `ADD COLUMN ... NOT NULL` without default on a large table locks it → nullable + default, backfill, then NOT NULL.
- Multi-statement migrations are transactional or idempotent.
- Destructive changes have a rollback plan; state when a migration is irreversible.
- Referenced tables/columns exist when the migration runs.

### Row Level Security (Postgres/Supabase; see gate)
- RLS enabled on every table with user/org data.
- Policies cover SELECT, INSERT, UPDATE, DELETE for each access pattern.
- Policies filter by organization: org A never reads org B rows.
- Service-role bypass is intentional and safe.
- Prefer direct column checks to subqueries/functions in policies (speed).

### Schema Design
- FK constraints on relationships with deliberate `ON DELETE` behavior.
- Indexes on FK columns and frequent WHERE/ORDER BY columns.
- Engine-correct types (see gate); NOT NULL, CHECK, and UNIQUE where they belong.

### Query Patterns (application code)
- N+1: queries inside loops → batch or join.
- `select('*')` where few columns are used.
- Query errors checked before data is used.
- List queries have LIMIT/pagination.

## Finding Format

Contract lines plus one extra `Data risk:` line:

```
[Critical|High|Medium|Low] <title>
File: <path>:<line>
Issue: <what is wrong>
Fix: <remediation, with migration SQL if needed>
Data risk: <data loss, corruption, or exposure>
```

## Example

```
[Critical] Adding NOT NULL column without default locks a large table
File: migrations/0042_add_status.sql:3
Issue: `ALTER TABLE orders ADD COLUMN status text NOT NULL` rewrites every row under an exclusive lock.
Fix: Add nullable with default, backfill in batches, set NOT NULL in a later step.
Data risk: Write outage during migration.

[Low] select('*') fetches unused columns
File: src/repo/users.ts:18
Issue: `select('*')` pulls a large `profile_blob` the caller never reads.
Fix: Select only the needed columns.
Data risk: None.
```

End with one line each on schema health, RLS coverage (if applicable), and query efficiency, then the score and footer line from the contract.

## Never

- Never approve a destructive migration without a verified rollback.
- Never ignore a missing index on a filtered or joined column.
- Never approve raw SQL built by string concatenation.

## Communication

On a team, report: migration safety, RLS/security gaps, query performance concerns.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.