11import path from "node:path" ;
2- import { cancel , isCancel , log , select , spinner , text } from "@clack/prompts" ;
2+ import { cancel , isCancel , log , select , text } from "@clack/prompts" ;
33import { consola } from "consola" ;
44import { execa } from "execa" ;
55import fs from "fs-extra" ;
@@ -23,7 +23,7 @@ async function setupWithCreateDb(
2323) {
2424 try {
2525 log . info (
26- "Starting Prisma PostgreSQL setup. Please follow the instructions below:" ,
26+ "Starting Prisma Postgres setup. Please follow the instructions below:" ,
2727 ) ;
2828
2929 const createDbCommand = getPackageExecutionCommand (
@@ -149,6 +149,20 @@ async function writeEnvFile(projectDir: string, config?: PrismaConfig) {
149149 }
150150}
151151
152+ async function addDotenvImportToPrismaConfig ( projectDir : string ) {
153+ try {
154+ const prismaConfigPath = path . join (
155+ projectDir ,
156+ "apps/server/prisma.config.ts" ,
157+ ) ;
158+ let content = await fs . readFile ( prismaConfigPath , "utf8" ) ;
159+ content = `import "dotenv/config";\n${ content } ` ;
160+ await fs . writeFile ( prismaConfigPath , content ) ;
161+ } catch ( _error ) {
162+ consola . error ( "Failed to update prisma.config.ts" ) ;
163+ }
164+ }
165+
152166function displayManualSetupInstructions ( ) {
153167 log . info ( `Manual Prisma PostgreSQL Setup Instructions:
154168
@@ -226,7 +240,7 @@ export async function setupPrismaPostgres(config: ProjectConfig) {
226240 }
227241
228242 const setupMethod = await select ( {
229- message : "Choose your Prisma setup method:" ,
243+ message : "Choose your Prisma Postgres setup method:" ,
230244 options : setupOptions ,
231245 initialValue : "create-db" ,
232246 } ) ;
@@ -246,28 +260,23 @@ export async function setupPrismaPostgres(config: ProjectConfig) {
246260
247261 if ( prismaConfig ) {
248262 await writeEnvFile ( projectDir , prismaConfig ) ;
263+
264+ await addDotenvImportToPrismaConfig ( projectDir ) ;
265+
249266 if ( orm === "prisma" ) {
250267 await addPrismaAccelerateExtension ( serverDir ) ;
251- log . info (
252- pc . cyan (
253- 'NOTE: Make sure to uncomment `import "dotenv/config";` in `apps/server/src/prisma.config.ts` to load environment variables.' ,
254- ) ,
255- ) ;
256268 }
257269 log . success (
258- pc . green ( "Prisma PostgreSQL database configured successfully!" ) ,
270+ pc . green ( "Prisma Postgres database configured successfully!" ) ,
259271 ) ;
260272 } else {
261- const fallbackSpinner = spinner ( ) ;
262- fallbackSpinner . start ( "Setting up fallback configuration..." ) ;
263273 await writeEnvFile ( projectDir ) ;
264- fallbackSpinner . stop ( "Fallback configuration ready" ) ;
265274 displayManualSetupInstructions ( ) ;
266275 }
267276 } catch ( error ) {
268277 consola . error (
269278 pc . red (
270- `Error during Prisma PostgreSQL setup: ${
279+ `Error during Prisma Postgres setup: ${
271280 error instanceof Error ? error . message : String ( error )
272281 } `,
273282 ) ,
0 commit comments