Database schema design
Tables that make bad data impossible
Your AI designs or reviews a relational schema the way a database engineer on call would: entities and keys, types and constraints that enforce meaning, tenancy and soft-delete decisions, indexes derived from your real queries, and runnable migration SQL.
By Vander Labs. A Vander Labs Original, written by the Vander Labs team with AI assistance. Works with Claude, ChatGPT, Cursor and Claude Code.
What your AI learns
- Models business facts, normalizes to 3NF and denormalizes only on purpose
- Chooses keys, types and constraints that encode the rules
- Indexes from the actual queries and writes expand-migrate-contract migrations
How it works
- Model entities: Entities with definitions and natural identifiers, relationships with cardinality, a Mermaid ERD.
- Normalize deliberately: Third normal form, then denormalization only for a measured read path with an invalidation rule.
- Choose keys: Identity or UUID surrogates, natural keys as unique constraints, foreign keys with explicit delete behavior.
- Pick types: timestamptz, numeric for money, text with checks, lookup tables over enums, jsonb only for schemaless data.
- Constraints: Not null by default, checks for ranges and states, unique and exclusion constraints for business rules.
- Standard patterns: Timestamps, tenant_id first in indexes with row-level security, partial unique indexes under soft delete.
- Index from queries: Composite indexes in equality, range, sort order per listed query, with explain analyze to confirm.
- Write the migration: Ordered SQL files, concurrent index creation, destructive changes split so old code keeps running.
- Review mode: Existing schemas checked against the same rules with severity and fix SQL.
Limits and safety
- Says when a document store or a warehouse schema fits better than a relational design.
- Refuses float for money and timestamp without time zone, and explains why.
Topics: postgresql, schema, sql, migrations, indexing