database-schema
Installation
SKILL.md
Database Schema
Designs clean schemas, writes migrations, and sets up seed data conventions.
Design principles
- Model the domain, not the UI: tables/collections represent entities and relationships, not screens.
- Relationships: prefer explicit FKs (or references) with clear cascade behavior; avoid circular dependencies.
- Naming: plural table names,
snake_casecolumns (or match the ORM's convention),idas primary key,created_at/updated_attimestamps on all tables that need them. - Types: use the strictest type that fits (UUID/auto-increment id, proper enums or check constraints, decimals for money, timestamptz for dates).
- Indexes: add indexes for every FK and every column used in frequent
WHERE/ORDER BY; don't index everything. - Soft vs hard delete: agree with the user; default to hard delete unless audit needs exist.
Workflow with an ORM (Prisma example)
- Edit
schema.prisma. - Run
npx prisma formatthennpx prisma migrate dev --name <short_description>(dev) to generate and apply the migration. - Check the generated SQL in
prisma/migrations/<name>/migration.sqlbefore applying to prod. - For production:
npx prisma migrate deploy.