From 36989165073d0f9b2b66346195f5f50851d1bf9c Mon Sep 17 00:00:00 2001 From: abdout Date: Sun, 10 May 2026 10:07:04 +0300 Subject: [PATCH] fix(seed): make seed-sudan-cities.ts work with Prisma 7.x adapters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two issues needed fixing to actually run the script against the live Neon DB (which is what just produced the 42 listings now in prod): 1. Prisma 7.x rejects 'new PrismaClient()' with no options — it requires either an adapter or accelerateUrl. The fix: import the app's existing 'db' from '@/lib/db', which already wires up PrismaPg / PrismaNeon based on DATABASE_URL_ADAPTER. 2. ES module imports are hoisted and execute in source order. If '@/lib/db' is imported before dotenv runs, its module-level 'createPrismaClient()' reads an empty process.env and can't find DATABASE_URL. Switch to 'import "dotenv/config"' as a side-effect entry — it runs config() at module-load time, so DATABASE_URL is set by the time any other import resolves. Run as: DATABASE_URL_ADAPTER=neon FORCE_SEED=1 pnpm seed:sudan Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/seed-sudan-cities.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/seed-sudan-cities.ts b/scripts/seed-sudan-cities.ts index 18de9ae..911fc70 100644 --- a/scripts/seed-sudan-cities.ts +++ b/scripts/seed-sudan-cities.ts @@ -18,19 +18,23 @@ * see fallback below). */ -import { config } from "dotenv"; -config(); +// CRITICAL ORDER: load .env via the side-effect entry point BEFORE any +// other module (especially @/lib/db) is imported. ES module imports are +// hoisted and execute in source order; if @/lib/db is imported first, +// its module-level `createPrismaClient()` runs against an empty +// process.env and the adapter can't find DATABASE_URL. +import "dotenv/config"; import { - PrismaClient, PropertyType, Amenity, Highlight, CancellationPolicy, } from "@prisma/client"; import bcrypt from "bcryptjs"; - -const prisma = new PrismaClient(); +// Reuse the app's PrismaClient so we get the same Neon/PG adapter +// selection and connection pool config the running app uses. +import { db as prisma } from "@/lib/db"; const DEMO_PASSWORD = "123456";