Schema mistakes are the most expensive kind: cheap to fix in review, brutal to fix after a billion rows arrive. Have AI critique proposed DDL against the workload — keys, types, nullability, index strategy, anti-pattern flags — delivered as a review memo the human rules on before anything ships.
Tier: Foundation · Workflow area: Schema & Change Management · ~30 minutes
A schema review is pattern-matching against a large catalog of known mistakes, which is precisely what LLMs are good at. This playbook makes AI the always-available first reviewer on every table that ships — with the human as the ruling reviewer, because half of what looks like an anti-pattern is a deliberate trade-off the model cannot know about.
Collect the DDL and the workload truth. A schema is only right relative to its queries. Gather: the full proposed DDL (tables, constraints, indexes), the expected top queries or API access patterns, growth estimates (rows/day, retention), and write/read mix.
Prompt for a structured review memo with severity levels.
You are a senior database engineer reviewing proposed PostgreSQL 16
DDL before it ships. Below: the DDL, the expected access patterns,
growth estimates and write/read mix.
Produce a REVIEW MEMO:
For each finding: [BLOCKER] / [WARN] / [CONSIDER], the table.column,
the issue, why it bites AT SCALE (use my growth numbers), and the
concrete fix as DDL.
Review, in order:
1. KEYS — PK choice and type (int vs bigint vs UUID trade-offs for
this insert rate), FK coverage, natural-key uniqueness gaps.
2. TYPES — money in float [BLOCKER], timestamps without time zone,
varchar(255) reflexes, text vs enum vs lookup table.
3. NULLABILITY — columns nullable by omission vs by meaning;
NOT NULL + DEFAULT opportunities.
4. INDEXES — do the proposed indexes serve the stated queries?
key order, missing FK indexes, redundant/overlapping indexes.
5. ANTI-PATTERNS — EAV, JSON-as-schema-dodge, wide rows, soft-delete
columns without partial-index support, missing created/updated
audit columns, polymorphic FKs.
6. SCALE — partitioning candidacy against my retention numbers,
fill-factor for update-heavy tables.
Skip naming style. End with: what is GOOD about this design.
The severity split keeps the memo actionable — blockers stop the ship, warns get a decision, considers get a line in the ticket.
Verify the load-bearing claims empirically. Two spot-checks catch most model overreach. First, index-vs-query claims — build the schema empty and check the planner's intent with realistic row counts faked via stats, or simply load a synthetic million rows:
CREATE TABLE orders_review AS TABLE orders WITH NO DATA;
INSERT INTO orders_review
SELECT gen.i, (gen.i % 50000) + 1, now() - (gen.i % 365) * interval '1 day',
(ARRAY['new','paid','shipped','refunded'])[1 + gen.i % 4]
FROM generate_series(1, 1_000_000) AS gen(i);
ANALYZE orders_review;
EXPLAIN SELECT * FROM orders_review
WHERE customer_id = 42 ORDER BY ordered_at DESC LIMIT 20;
Second, type claims — confirm version-specific advice (identity columns vs serial, UUID v7 availability, enum alteration behavior) against the docs for your engine version.
Rule on every finding in writing. The human pass over the memo produces the actual review record:
[BLOCKER] amount NUMERIC not FLOAT -> ACCEPTED, DDL fixed
[WARN] status as text, no constraint -> ACCEPTED, CHECK constraint added
[WARN] UUID v4 PK fragments index at
this insert rate -> REJECTED — multi-region write
requirement, fragmentation
priced in; noted in ADR-114
[CONSIDER] partition by month -> DEFERRED — revisit at 100M rows,
calendar reminder set
Rejected findings with reasons are the most important rows: they document deliberate trade-offs so the next reviewer (or the next AI pass) does not re-litigate them.
Ship the ruled memo with the DDL. The migration ticket carries the DDL, the memo, and the rulings. Findings that changed the design are fixed pre-merge — this is the entire point: the fix happened while it was still a text edit.
Proposed schemas reveal product plans — table names alone can leak an unannounced feature. Route pre-launch DDL through a tenant-approved model rather than a public assistant.
The cheapest schema migration is the one that became a text edit in review. AI makes that review thorough on every table, every time — and the human ruling, recorded finding by finding, is what makes it a review rather than a suggestion box.