fix(react-router-example): fallback to dummy database url in prisma config for CI#40
Conversation
📝 WalkthroughWalkthroughThe pull request adds Prisma datasource URL configuration with a fallback to a local PostgreSQL instance when the DATABASE_URL environment variable is not set, allowing Prisma generate to run without external database connectivity. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
Actualización: Se ha eliminado la propiedad |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@apps/react-router-example/prisma.config.ts`:
- Around line 11-15: The datasource url fallback currently uses
env("DATABASE_URL") ?? "postgresql://postgres:postgres@localhost:5432/..." which
masks missing DATABASE_URL in dev; change it to only apply the hardcoded
fallback when running in CI (e.g. when process.env.CI === "true" or a dedicated
CI flag) so local/machine runs fail fast; update the datasource.url expression
to check process.env.CI (or similar) and only return the localhost fallback in
CI, keeping the runtime guard in app/lib/prisma.ts intact.
| datasource: { | ||
| url: env("DATABASE_URL"), | ||
| // Provide a default value for CI/CD environments where the database URL is not set | ||
| // This allows prisma generate to run without connecting to the database | ||
| url: env("DATABASE_URL") ?? "postgresql://postgres:postgres@localhost:5432/effectify", | ||
| }, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "prisma.config.ts" -type fRepository: devx-op/effectify
Length of output: 140
🏁 Script executed:
cat -n ./apps/react-router-example/prisma.config.tsRepository: devx-op/effectify
Length of output: 765
🏁 Script executed:
git log --oneline -n 10 -- ./apps/react-router-example/prisma.config.tsRepository: devx-op/effectify
Length of output: 146
🏁 Script executed:
find ./apps/react-router-example -type f \( -name "*.yml" -o -name "*.yaml" -o -name ".env*" \) | head -20Repository: devx-op/effectify
Length of output: 107
🏁 Script executed:
rg "CI|DATABASE_URL" ./apps/react-router-example --type ts --type js -A 2 -B 2Repository: devx-op/effectify
Length of output: 1231
🏁 Script executed:
cat -n ./apps/react-router-example/docker-compose.ymlRepository: devx-op/effectify
Length of output: 417
🏁 Script executed:
cat -n ./apps/react-router-example/app/lib/prisma.tsRepository: devx-op/effectify
Length of output: 681
Restrict fallback URL to CI only; avoid masking misconfiguration in dev.
The unconditional fallback to localhost:5432 risks silent misconfiguration during development. If DATABASE_URL is missing when running prisma CLI commands, it will silently connect to the hardcoded local database instead of failing fast. Additionally, the fallback port (5432) differs from the docker-compose setup (5433), compounding the risk.
While runtime protection exists in app/lib/prisma.ts (which enforces DATABASE_URL), the config-level fallback still creates friction during local development. Restrict the fallback to CI environments only:
+const databaseUrl =
+ env("DATABASE_URL") ??
+ (process.env.CI ? "postgresql://postgres:postgres@localhost:5432/effectify" : undefined)
+
+if (!databaseUrl && !process.env.CI) {
+ throw new Error("DATABASE_URL is required outside CI")
+}
+
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
// Provide a default value for CI/CD environments where the database URL is not set
// This allows prisma generate to run without connecting to the database
- url: env("DATABASE_URL") ?? "postgresql://postgres:postgres@localhost:5432/effectify",
+ url: databaseUrl,
},
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| datasource: { | |
| url: env("DATABASE_URL"), | |
| // Provide a default value for CI/CD environments where the database URL is not set | |
| // This allows prisma generate to run without connecting to the database | |
| url: env("DATABASE_URL") ?? "postgresql://postgres:postgres@localhost:5432/effectify", | |
| }, | |
| const databaseUrl = | |
| env("DATABASE_URL") ?? | |
| (process.env.CI ? "postgresql://postgres:postgres@localhost:5432/effectify" : undefined) | |
| if (!databaseUrl && !process.env.CI) { | |
| throw new Error("DATABASE_URL is required outside CI") | |
| } | |
| export default defineConfig({ | |
| schema: "prisma/schema.prisma", | |
| migrations: { | |
| path: "prisma/migrations", | |
| }, | |
| datasource: { | |
| // Provide a default value for CI/CD environments where the database URL is not set | |
| // This allows prisma generate to run without connecting to the database | |
| url: databaseUrl, | |
| }, | |
| }) |
🤖 Prompt for AI Agents
In `@apps/react-router-example/prisma.config.ts` around lines 11 - 15, The
datasource url fallback currently uses env("DATABASE_URL") ??
"postgresql://postgres:postgres@localhost:5432/..." which masks missing
DATABASE_URL in dev; change it to only apply the hardcoded fallback when running
in CI (e.g. when process.env.CI === "true" or a dedicated CI flag) so
local/machine runs fail fast; update the datasource.url expression to check
process.env.CI (or similar) and only return the localhost fallback in CI,
keeping the runtime guard in app/lib/prisma.ts intact.
…onfig for CI (#40) * fix(react-router-example): fallback to dummy database url in prisma config for CI * fix(react-router-example): remove url from schema.prisma to support prisma v7
This PR resolves the CD failure where
prisma generatefails due to missingDATABASE_URL.prisma.config.ts.schema.prismato useenv("DATABASE_URL").Summary by CodeRabbit