schema-review
When to use
- A migration diff, new migration file, or schema change is under review
and the question is scale-shaped: indexes, reversibility, growth,
query patterns against the new columns.
- The user asks "will this scale", "review this migration", "check the
schema", or a PR touches migrations/, schema.prisma, or raw .sql
migration files.
- NOT for runtime performance analysis of live traffic (no APM here —
route to performance-analysis) and NOT for authoring a new migration
from scratch (route to laravel-migration or the stack-native tool,
then come back with the diff), and NOT for designing the schema itself
(route to database, which owns relational modeling).
Procedure
- Detect the stack surface in the diff: Laravel migrations
(database/migrations/*.php), Prisma (schema.prisma +
prisma/migrations/**/migration.sql), raw SQL (*.sql). One diff can
carry several.
- Run the deterministic linter on the touched files plus the query
surface that references the changed tables:
```bash
npx tsx node_modules/@event4u/agent-config/src/scripts/lint_persistence.ts --dir <path> [--stack eloquent|prisma|raw-sql] --format json
```
The linter emits gate findings (pattern-detected: F1 N+1, F2
index-parity, F3 unbounded reads, F6 migration-safety, F7
growth-budget, F8 audit-coverage, F9 sync-in-handler, F11 non-durable
async) and advice findings (heuristics — never treat as blockers).
- Walk the gap table — for every
gatefinding decide: fix, or
waiver with a reason (// no-index: <reason>, `// sync-required:
<reason>, -- no-retention: <reason>`, …). An empty waiver reason is
itself a finding.
- Check the R-A6/R-A7 invariants by hand where the linter is blind:
reversibility of data transformations, retention policy for any new
append-only table (the -- retention: <policy> line), backfill plan
for new NOT NULL columns on large tables.
- A drop or rename → run the consumer census before judging it safe: