Database Selection
Purpose
Make two separate decisions, in order: (1) the database — PostgreSQL, MySQL, or MongoDB — from the data's shape and integrity needs; (2) the data layer — Prisma, Drizzle, Mongoose, or native driver — from team ergonomics and control needs. Feeds ../../stack-recommendation; requires user approval (Gate 2).
When to Use
- At the start of any project that stores data, or when adding a store.
- When re-evaluating persistence for a migration (
../../migration-planning).
- Not after the database is approved and unchanged.
Inputs
- Requirement baseline: entities, relations, integrity needs, reporting needs, expected access patterns.
- Existing infrastructure/team experience (
../../existing-project-audit findings where applicable).
Discovery Questions
- Does the domain involve payments, orders, inventory, reporting, financial data, multi-entity transactions, or strongly related entities? (Any yes → relational is the usual answer.)
- Are document structures genuinely highly variable across records, with data naturally read/written as embedded documents? (That's the MongoDB case — not "we haven't designed the schema yet.")
- What queries will exist: cross-entity joins/aggregations (relational strength) vs whole-document reads by key (document strength)?
- For the data layer: does the team want schema-first ergonomics (Prisma), SQL-proximity and control (Drizzle), ODM conveniences (Mongoose), or minimal abstraction (native driver)?
Responsibilities
- Database decision first, on data shape and integrity:
- Relational (PostgreSQL/MySQL) usually preferred for: payments, orders, inventory, reporting, financial data, transactional multi-entity writes, strong relations/constraints. Between them: PostgreSQL for richer types/features, MySQL where team/infra experience or hosting favors it — record the reason.
- MongoDB may be preferred for: highly variable document structures and access patterns that naturally read/write embedded documents as units.
- Data layer decision second, pairs must be coherent:
- Relational DB → Prisma (schema-first DX, generated types), Drizzle (TypeScript-SQL closeness, control), or native driver/query builder (maximum control, more discipline).
- MongoDB → Mongoose (schemas/middleware over documents) or native driver (direct control).
- Record both decisions with justification and rejected alternatives; note operational implications (backups, migrations tooling —
database-migrations, backup-recovery).
- Hand off to the matching skills:
relational-schema-design + prisma-relational/drizzle-relational, or document-schema-design + mongoose-mongodb.
Required Workflow
- Gather entities, relations, integrity/reporting needs, access patterns.
- Decide the database from data shape (relational signals vs document signals).
- Decide the data layer for that database from team/control needs.
- Record both with trade-offs for Gate 2 approval.
- Hand off to schema-design + data-layer skills.
Decision Rules
- Never conflate the two decisions — "we use Prisma" is not a database choice; "we use Postgres" doesn't pick the data layer.
- Financial/transactional/relational signals outweigh document-flexibility preferences: integrity failures cost more than schema ceremony.
- "Schemaless" is not a reason for MongoDB — undesigned data isn't variable data (
document-schema-design still requires design).
- Polyglot persistence (two stores) needs strong, separate justification per store — default is one.
- Team familiarity tiebreaks between adequate options; it doesn't override a shape mismatch.
Rules
- Recommend, don't pre-select; user approves at Gate 2.
- No installation or schema work before approval.
- Record what would flip each decision.
Anti-Patterns
- Choosing MongoDB for an orders/payments/inventory domain because iteration feels faster.
- Choosing the database by choosing an ORM first.
- Defaulting to PostgreSQL (or anything) without stating why it fits this data.
- "We'll add relations to MongoDB later with manual refs everywhere" — that's a relational domain in denial.
- Two databases because two tutorials.
Validation Checklist
Definition of Done
Two recorded, separately justified decisions — database and data layer — coherent as a pair, tied to the domain's data shape and integrity needs, with trade-offs noted and approval pending.
Related Skills
../../stack-recommendation, relational-schema-design, document-schema-design, prisma-relational, drizzle-relational, mongoose-mongodb, database-migrations, backup-recovery, ../../backend/existing-backend-audit.
Related Knowledge
../../../knowledge/ (domain model, infra constraints, team experience).
Related References
../../../references/database/ (comparison notes, when populated).
Context Loading Guidance
- Requires: entity/relation summary, integrity + reporting needs, access patterns.
- Does not require: full schema drafts, ORM docs, application code.
- May load: one schema-design skill + one data-layer skill after deciding.
- Stop when: both decisions are recorded for Gate 2.
Token Efficiency Guidance
Decide from the requirements summary; the two-decision table (option, fit, trade-off) is the whole artifact. Don't draft schemas here.
1---2name: database-selection3description: Use to choose the database (PostgreSQL, MySQL, MongoDB) and — separately — the data layer (Prisma, Drizzle, Mongoose, native driver). Relational is usually right for payments, orders, inventory, reporting, financial data, transactions, strong relations; MongoDB fits highly variable documents with embedded access patterns.4---56# Database Selection78## Purpose910Make **two separate decisions**, in order: (1) the **database** — PostgreSQL, MySQL, or MongoDB — from the data's shape and integrity needs; (2) the **data layer** — Prisma, Drizzle, Mongoose, or native driver — from team ergonomics and control needs. Feeds `../../stack-recommendation`; requires user approval (Gate 2).1112## When to Use1314- At the start of any project that stores data, or when adding a store.15- When re-evaluating persistence for a migration (`../../migration-planning`).16- **Not** after the database is approved and unchanged.1718## Inputs1920- Requirement baseline: entities, relations, integrity needs, reporting needs, expected access patterns.21- Existing infrastructure/team experience (`../../existing-project-audit` findings where applicable).2223## Discovery Questions2425- Does the domain involve **payments, orders, inventory, reporting, financial data, multi-entity transactions, or strongly related entities**? (Any yes → relational is the usual answer.)26- Are document structures **genuinely highly variable** across records, with data naturally read/written as embedded documents? (That's the MongoDB case — not "we haven't designed the schema yet.")27- What queries will exist: cross-entity joins/aggregations (relational strength) vs whole-document reads by key (document strength)?28- For the data layer: does the team want schema-first ergonomics (Prisma), SQL-proximity and control (Drizzle), ODM conveniences (Mongoose), or minimal abstraction (native driver)?2930## Responsibilities3132- **Database decision first**, on data shape and integrity:33 - **Relational (PostgreSQL/MySQL)** usually preferred for: payments, orders, inventory, reporting, financial data, transactional multi-entity writes, strong relations/constraints. Between them: PostgreSQL for richer types/features, MySQL where team/infra experience or hosting favors it — record the reason.34 - **MongoDB** may be preferred for: highly variable document structures and access patterns that naturally read/write embedded documents as units.35- **Data layer decision second, pairs must be coherent**:36 - Relational DB → **Prisma** (schema-first DX, generated types), **Drizzle** (TypeScript-SQL closeness, control), or **native driver/query builder** (maximum control, more discipline).37 - MongoDB → **Mongoose** (schemas/middleware over documents) or **native driver** (direct control).38- Record both decisions with justification and rejected alternatives; note operational implications (backups, migrations tooling — `database-migrations`, `backup-recovery`).39- Hand off to the matching skills: `relational-schema-design` + `prisma-relational`/`drizzle-relational`, or `document-schema-design` + `mongoose-mongodb`.4041## Required Workflow42431. Gather entities, relations, integrity/reporting needs, access patterns.442. Decide the database from data shape (relational signals vs document signals).453. Decide the data layer for that database from team/control needs.464. Record both with trade-offs for Gate 2 approval.475. Hand off to schema-design + data-layer skills.4849## Decision Rules5051- **Never conflate the two decisions** — "we use Prisma" is not a database choice; "we use Postgres" doesn't pick the data layer.52- Financial/transactional/relational signals outweigh document-flexibility preferences: integrity failures cost more than schema ceremony.53- "Schemaless" is not a reason for MongoDB — undesigned data isn't variable data (`document-schema-design` still requires design).54- Polyglot persistence (two stores) needs strong, separate justification per store — default is one.55- Team familiarity tiebreaks between adequate options; it doesn't override a shape mismatch.5657## Rules5859- Recommend, don't pre-select; user approves at Gate 2.60- No installation or schema work before approval.61- Record what would flip each decision.6263## Anti-Patterns6465- Choosing MongoDB for an orders/payments/inventory domain because iteration feels faster.66- Choosing the database by choosing an ORM first.67- Defaulting to PostgreSQL (or anything) without stating why it fits *this* data.68- "We'll add relations to MongoDB later with manual refs everywhere" — that's a relational domain in denial.69- Two databases because two tutorials.7071## Validation Checklist7273- [ ] Data shape, integrity, reporting, access patterns gathered.74- [ ] Database decided on data shape (relational signals checked explicitly).75- [ ] Data layer decided separately, coherent with the database.76- [ ] Both recorded with trade-offs + rejected alternatives.77- [ ] Handed to schema-design + data-layer skills; Gate 2 pending.7879## Definition of Done8081Two recorded, separately justified decisions — database and data layer — coherent as a pair, tied to the domain's data shape and integrity needs, with trade-offs noted and approval pending.8283## Related Skills8485`../../stack-recommendation`, `relational-schema-design`, `document-schema-design`, `prisma-relational`, `drizzle-relational`, `mongoose-mongodb`, `database-migrations`, `backup-recovery`, `../../backend/existing-backend-audit`.8687## Related Knowledge8889`../../../knowledge/` (domain model, infra constraints, team experience).9091## Related References9293`../../../references/database/` (comparison notes, when populated).9495## Context Loading Guidance9697- **Requires:** entity/relation summary, integrity + reporting needs, access patterns.98- **Does not require:** full schema drafts, ORM docs, application code.99- **May load:** one schema-design skill + one data-layer skill after deciding.100- **Stop when:** both decisions are recorded for Gate 2.101102## Token Efficiency Guidance103104Decide from the requirements summary; the two-decision table (option, fit, trade-off) is the whole artifact. Don't draft schemas here.