Bỏ qua, tới nội dung chính

Kiến trúc · ADR 0020

Domain model and migration plan

Trạng thái
proposed — accepted after team and mentor review
Ngày
2026-09-27
Người quyết định
Alex (mentor), team review pending

Context

The scope brief and 32 user stories need about forty tables. Eight parallel designs disagreed on table names, the mastery formula and several invariants (see docs/spec/technical-plan-vi.html). Four students on a trunk-based repo cannot build from conflicting names: Prisma migrations authored concurrently produce out-of-order history that breaks every teammate's local database.

Decision

  • The target model is docs/design/data-model/schema.target.prisma: 48 tables, 50 enums and 47 passing constraint tests, validated by prisma validate and dry-run on Postgres 17 + pgvector. Its README maps every user story to tables and lists the naming, type and delete rules.
  • It lands in seven migrations, M1–M6 plus an index-only M7, on fixed dates from 2026-10-02 to 2026-11-06, after the M0 move of Prisma to packages/database. One person authors and merges every migration through M6; after M6 the schema is frozen for new tables.
  • Brief invariants are database objects: a human-signature CHECK and a deferred publish trigger (brief §4.2), a monotonic answerSeq for mastery recency, CHECKs on every score and credit bucket, and unique constraints for idempotency. Every migration enables RLS on the tables it creates.

Alternatives considered

  • A visual design tool as the source of truth (dbdiagram, drawSQL). A second source that drifts from schema.prisma; diagrams are generated from the schema instead (tools/prisma-erd.mjs).
  • A weekly migration drip through week 12. Leaves the core learning loop without a schema until week 9.

Consequences

  • Nobody edits the live schema into a shape this target does not describe; the target changes first.
  • The ERD group files are regenerated, never hand-drawn.
  • The target file is deleted once M6 makes it identical to the live schema.