Skip to content

ADR 0017: Prisma 7 over Drizzle / TypeORM

  • Status: Accepted
  • Date: 2026-04-14
  • Deciders: Ideony team

Ideony uses PostgreSQL 18 + PostGIS 3.5. The ORM/query-builder must support: type-safe CRUD, schema migrations, raw SQL for PostGIS spatial queries (ST_Distance, ST_Within), and Prisma schema as the single source of truth for DB types. Two leading alternatives were Drizzle ORM and TypeORM.

Use Prisma 7 as the ORM. The prisma/ directory at monorepo root holds schema.prisma; apps/api/prisma.config.ts points to it. Migrations run via cd apps/api && pnpm prisma migrate dev. @prisma/client is generated into apps/api. PostGIS spatial queries use prisma.$queryRaw with Prisma.sql tagged template for safe parameter binding.

  • Prisma schema is the single source of truth: models, relations, enums — generates both the migration SQL and the TypeScript client.
  • Type-safe query builder with full IntelliSense on model fields and relations.
  • prisma.$queryRaw with Prisma.sql handles PostGIS functions (ST_Distance, ST_Within, ST_DWithin) safely without raw string interpolation.
  • Prisma Migrate tracks migration history in _prisma_migrations; deterministic replay on new environments.
  • PrismaModule (@Global()) injected project-wide in NestJS; no per-module PrismaService imports needed.
  • Prisma’s generated client adds bundle weight; not suitable for edge runtimes (Cloudflare Workers) without adapter.
  • No native PostGIS type support — spatial columns stored as Unsupported("geometry") in schema; raw queries required for spatial logic.
  • Prisma 7 (preview at decision date) — must track breaking changes in client API; prisma generate must be re-run after schema changes.
  • Drizzle ORM — considered seriously: lighter, SQL-first, good PostGIS raw query story. Rejected: Prisma’s migration system and schema-as-source-of-truth model preferred; Drizzle migration tooling (drizzle-kit) less mature at decision date.
  • TypeORM — rejected: decorator-based, requires reflect-metadata, historically unstable with major Postgres features; poor PostGIS integration.
  • Knex.js (query builder only) — rejected: no schema/migration management; would require a separate migration tool (e.g., Flyway) adding tooling overhead.