From 905ce15c0b89e3647146bb4f6e9ba1db5ac8d066 Mon Sep 17 00:00:00 2001 From: maotora Date: Tue, 24 Mar 2026 08:05:11 +0300 Subject: [PATCH] fix: allow direct postgres in production --- README.md | 7 ++++--- src/config.ts | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9c63225..94d4101 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ Compatibility-first REST API for Tanzania location data backed by PostgreSQL and 3. Start PostgreSQL and update your connection strings if needed. - Local and test environments use a direct PostgreSQL `DATABASE_URL`. - - Production uses a Prisma Accelerate `DATABASE_URL`. - - If you run `pnpm db:migrate` against an Accelerate-backed environment, also provide `DIRECT_DATABASE_URL` so the migration bootstrap can talk to Postgres directly. + - Production can use either a direct PostgreSQL `DATABASE_URL` or a Prisma Accelerate `DATABASE_URL`. + - If `DATABASE_URL` points at Prisma Accelerate, also provide `DIRECT_DATABASE_URL` so migrations can talk to Postgres directly. 4. Apply the checked-in schema and seed deterministic fixture data. @@ -70,7 +70,8 @@ pnpm openapi:json - On a fresh database it bootstraps the historical `init` migration, marks that baseline as applied, and then deploys later migrations - On an existing database that already has the older Prisma migration history, it only applies the new additive migrations - Prefer `pnpm db:migrate` over calling `prisma migrate deploy` directly -- `DATABASE_URL` may point at Prisma Accelerate in production, but `pnpm db:migrate` still requires a direct Postgres URL in `DIRECT_DATABASE_URL` +- `DATABASE_URL` may point at direct Postgres or Prisma Accelerate +- If `DATABASE_URL` points at Prisma Accelerate, `pnpm db:migrate` still requires a direct Postgres URL in `DIRECT_DATABASE_URL` ## Testing diff --git a/src/config.ts b/src/config.ts index 7166270..7f3fb8e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -19,10 +19,6 @@ const env = envSchema.parse(process.env); const usesAccelerate = isAccelerateUrl(env.DATABASE_URL); const directDatabaseUrl = env.DIRECT_DATABASE_URL ?? (usesAccelerate ? undefined : env.DATABASE_URL); -if (env.NODE_ENV === 'production' && !usesAccelerate) { - throw new Error('Production requires DATABASE_URL to be a Prisma Accelerate URL.'); -} - if (env.NODE_ENV !== 'production' && !directDatabaseUrl) { throw new Error('Non-production requires a direct PostgreSQL URL via DIRECT_DATABASE_URL or DATABASE_URL.'); }