Context
The platform stores relational data (users, courses, quizzes, attempts) and, from phase 3, text embeddings for retrieval over uploaded lectures. Weak-topic analysis is SQL over attempt rows, so the relational store matters as much as the vector one. The team has four people and one semester; running a second database only for vectors is operational weight we cannot afford.
Decision
- One PostgreSQL 17 database with the pgvector extension, from the
pgvector/pgvector:pg17image. Embeddings live next to the rows they describe and are queried with plain SQL joins. - Prisma 6 as the ORM, pinned to
6.19.3(see ADR-0002, point 7).schema.prismais the source of truth for tables;prisma migrateowns every schema change. - Extensions are not the ORM's job.
infra/db/init/001-extensions.sqlcreatesvectorandpg_trgmonce, when the Postgres volume is first initialised. - The client is generated into
packages/database/generated/prisma, notnode_modules, sopnpm deploy --prodships it inside the container image.binaryTargetsincludeslinux-musl-openssl-3.0.xfor the alpine image. - Conventions: UUID primary keys,
createdAt/updatedAton every table, soft delete (deletedAt) for anything a quiz attempt may reference.
Alternatives considered
- A dedicated vector store (Pinecone, Qdrant). A second system to run, back up and keep consistent, for a corpus of a few thousand chunks. Rejected.
- TypeORM (used in the team's reference project). Weaker migration story and looser types. Prisma's generated client matches the strict TypeScript settings used here.
- Drizzle. Closer to SQL, but the team has no experience with it, and Prisma's tooling (Studio, migrate) shortens onboarding.
Consequences
- Prisma has no vector type. When embeddings land, the column is
Unsupported("vector(…)"), similarity queries go through$queryRaw, and HNSW indexes are added in hand-edited migrations. - Pinning Prisma 6 means reading the v6 docs, not
latest. - A fresh volume gets the extensions automatically. An existing volume created before an extension was added to the init script needs a migration that runs
CREATE EXTENSION IF NOT EXISTS.