fix: repair Prisma setup migration flow#35
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a migrate+seed option to the Prisma setup flow and Deno/libsql support: introduces Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
PR preview published
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tasks/setup-prisma.ts`:
- Around line 776-782: The if-block checking options.databaseUrl is dead because
callers compute databaseUrl with a fallback to getDefaultDatabaseUrl(), which
always returns a string; remove the dead guard block that returns
didMigrate/didSeed/warning and its surrounding conditional in setupPrisma
(references: options.databaseUrl, getDefaultDatabaseUrl, the migrate+seed return
object) so migration/seed logic always proceeds, or alternatively change the
callers that construct options.databaseUrl to pass undefined when no real DB URL
exists; pick one approach and update callers or delete this unreachable branch
accordingly.
- Around line 796-798: Add an explanatory comment above the conditional that
waits when context.shouldUsePrismaPostgres is true (the await new
Promise((resolve) => setTimeout(resolve, 2000)) block) describing that the
hardcoded 2-second delay is a deliberate workaround for a known race condition
during Prisma Postgres provisioning, include the issue/PR reference or repro
notes if available, state what could be done to safely remove or shorten the
delay (e.g., replace with an explicit readiness probe or retry loop checking DB
connectivity), and mark it with a TODO and date so future maintainers know why
it exists and how to revisit it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: a78db60a-cfe1-40c3-8048-d62125532f3a
📒 Files selected for processing (7)
src/tasks/setup-prisma.tssrc/templates/shared.tssrc/types.tssrc/utils/runtime.tstemplates/create/elysia/prisma.config.ts.hbstemplates/create/hono/prisma.config.ts.hbstemplates/create/nest/prisma.config.ts.hbs
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (2)
src/tasks/setup-prisma.ts (2)
787-793:⚠️ Potential issue | 🟡 MinorDead code:
databaseUrlalways has a fallback value.At the call site (lines 738-741),
databaseUrlis computed with a fallback chain ending ingetDefaultDatabaseUrl(), which always returns a string. This guard will never trigger.Remove this unreachable block:
Proposed fix
if (!options.didGenerateClient) { return { didMigrate: false, didSeed: false, warning: "Skipped migrate + seed because the Prisma Client was not generated.", }; } - if (!options.databaseUrl) { - return { - didMigrate: false, - didSeed: false, - warning: "Skipped migrate + seed because no DATABASE_URL is available.", - }; - }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tasks/setup-prisma.ts` around lines 787 - 793, The if-check guarding options.databaseUrl is unreachable because databaseUrl is always set via the fallback chain ending in getDefaultDatabaseUrl(); remove the entire conditional block that returns didMigrate/didSeed warning and any now-unused local references tied only to that branch. Update surrounding control flow in the setupPrisma/task function (references: options.databaseUrl, getDefaultDatabaseUrl) so execution continues normally without this dead return.
807-809: 🧹 Nitpick | 🔵 TrivialAdd a comment explaining the 2-second delay.
This hardcoded delay appears to be a workaround for Prisma Postgres provisioning timing. Without documentation, future maintainers won't understand why it exists or when it can be removed.
Proposed documentation
try { if (context.shouldUsePrismaPostgres) { + // Brief delay to allow newly provisioned Prisma Postgres database to become reachable. + // TODO: Replace with an explicit readiness check or retry loop. await new Promise((resolve) => setTimeout(resolve, 2000)); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tasks/setup-prisma.ts` around lines 807 - 809, The 2-second hardcoded wait after checking context.shouldUsePrismaPostgres is a magic-number workaround for Prisma Postgres provisioning timing; add a clear comment directly above the if block (the check using context.shouldUsePrismaPostgres and the await new Promise((resolve) => setTimeout(resolve, 2000))) that explains why the delay is required, under what conditions it can be removed, and link to any related issue/PR or external doc; optionally replace the literal 2000 with a named constant like PRISMA_PROVISION_DELAY_MS to make intent explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@templates/create/astro/prisma.config.ts.hbs`:
- Line 10: Extract the nested inline Handlebars logic that builds the Prisma
seed string into a helper (e.g., seedCommand) or multiline conditional to
improve readability and unify the seed path; update the template reference where
the seed is set (the seed: "..." line in the template) to call the new helper or
use the expanded if/else blocks, ensure all branches use a consistent path
format like "./prisma/seed.ts", and add the helper implementation in the shared
template helpers module (for example src/templates/shared.ts) so all templates
can reuse it.
In `@templates/create/astro/src/lib/prisma.ts.hbs`:
- Line 1: The Handlebars helper calls in this template use an implicit
packageManager reference (see usages of requiresDotenvConfigImport and other
helper invocations at the instances around lines 1, 15, and 45); update those
helper calls to reference the context explicitly by using this.packageManager
(e.g., pass this.packageManager to requiresDotenvConfigImport and any other
helpers that currently rely on packageManager) so the template binds the correct
context and avoids ambiguity when rendering.
In `@templates/create/nuxt/prisma.config.ts.hbs`:
- Line 10: The seed command's path is inconsistent: when packageManager is
"deno" or "bun" it uses "./prisma/seed.ts" but the tsx fallback uses
"prisma/seed.ts"; update the tsx branch in the seed template (the seed: line
that checks packageManager and selects tsx) to use the leading "./" so all
branches consistently reference "./prisma/seed.ts".
---
Duplicate comments:
In `@src/tasks/setup-prisma.ts`:
- Around line 787-793: The if-check guarding options.databaseUrl is unreachable
because databaseUrl is always set via the fallback chain ending in
getDefaultDatabaseUrl(); remove the entire conditional block that returns
didMigrate/didSeed warning and any now-unused local references tied only to that
branch. Update surrounding control flow in the setupPrisma/task function
(references: options.databaseUrl, getDefaultDatabaseUrl) so execution continues
normally without this dead return.
- Around line 807-809: The 2-second hardcoded wait after checking
context.shouldUsePrismaPostgres is a magic-number workaround for Prisma Postgres
provisioning timing; add a clear comment directly above the if block (the check
using context.shouldUsePrismaPostgres and the await new Promise((resolve) =>
setTimeout(resolve, 2000))) that explains why the delay is required, under what
conditions it can be removed, and link to any related issue/PR or external doc;
optionally replace the literal 2000 with a named constant like
PRISMA_PROVISION_DELAY_MS to make intent explicit.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: aefa64d4-d75b-4da5-963e-70241280cade
📒 Files selected for processing (32)
src/constants/db-packages.tssrc/constants/dependencies.tssrc/tasks/install.tssrc/tasks/setup-prisma.tssrc/templates/shared.tstemplates/create/astro/prisma.config.tstemplates/create/astro/prisma.config.ts.hbstemplates/create/astro/prisma/seed.ts.hbstemplates/create/astro/src/lib/prisma.ts.hbstemplates/create/elysia/src/lib/prisma.ts.hbstemplates/create/hono/src/lib/prisma.ts.hbstemplates/create/nest/src/lib/prisma.ts.hbstemplates/create/next/prisma.config.tstemplates/create/next/prisma.config.ts.hbstemplates/create/next/prisma/seed.ts.hbstemplates/create/next/src/lib/prisma.ts.hbstemplates/create/nuxt/prisma.config.tstemplates/create/nuxt/prisma.config.ts.hbstemplates/create/nuxt/prisma/seed.ts.hbstemplates/create/nuxt/server/utils/prisma.ts.hbstemplates/create/svelte/prisma.config.tstemplates/create/svelte/prisma.config.ts.hbstemplates/create/svelte/prisma/seed.ts.hbstemplates/create/svelte/src/lib/server/prisma.ts.hbstemplates/create/tanstack-start/prisma.config.tstemplates/create/tanstack-start/prisma.config.ts.hbstemplates/create/tanstack-start/prisma/seed.ts.hbstemplates/create/tanstack-start/src/lib/prisma.server.ts.hbstemplates/create/turborepo/packages/db/prisma.config.tstemplates/create/turborepo/packages/db/prisma.config.ts.hbstemplates/create/turborepo/packages/db/prisma/seed.ts.hbstemplates/create/turborepo/packages/db/src/client.ts.hbs
💤 Files with no reviewable changes (6)
- templates/create/next/prisma.config.ts
- templates/create/nuxt/prisma.config.ts
- templates/create/turborepo/packages/db/prisma.config.ts
- templates/create/svelte/prisma.config.ts
- templates/create/tanstack-start/prisma.config.ts
- templates/create/astro/prisma.config.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tasks/setup-prisma.ts`:
- Around line 810-811: Update the hardcoded fallback messages that tell users to
run `prisma migrate dev` and `prisma db seed` to instead reference the
package.json scripts `db:migrate` and `db:seed` so they match the rest of the
code (e.g., the messages created near the warning object around the string
"Migration failed; run `prisma migrate dev --name init` manually." and any
similar message at the later occurrence). Replace the literal CLI commands in
those warning strings with the npm script names (`npm run db:migrate` / `npm run
db:seed` or just `db:migrate`/`db:seed` consistent with
buildNextStepsForContext) so the messages are consistent with
buildNextStepsForContext and other user-facing next-step instructions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1e77205e-a77c-43e8-ad54-884275fa82d9
📒 Files selected for processing (3)
src/constants/dependencies.tssrc/tasks/install.tssrc/tasks/setup-prisma.ts
There was a problem hiding this comment.
Actionable comments posted: 13
♻️ Duplicate comments (1)
templates/create/astro/src/lib/prisma.ts.hbs (1)
4-4:⚠️ Potential issue | 🟠 MajorComplete the previous
no-implicit-thiscleanup in this template.Good partial fix, but Line 4 and Line 21 still use implicit
packageManager(and Line 22 uses implicitprovider), so lint still fails.🛠️ Suggested patch
-import { PrismaClient } from "../generated/prisma/client{{`#if` (eq packageManager "deno")}}.ts{{/if}}"; +import { PrismaClient } from "../generated/prisma/client{{`#if` (eq this.packageManager "deno")}}.ts{{/if}}"; @@ -const rawDatabaseUrl = {{`#if` (eq packageManager "deno")}}Deno.env.get("DATABASE_URL"){{else}}import.meta.env?.DATABASE_URL ?? process.env.DATABASE_URL{{/if}}; -{{`#if` (eq provider "sqlite")}} +const rawDatabaseUrl = {{`#if` (eq this.packageManager "deno")}}Deno.env.get("DATABASE_URL"){{else}}import.meta.env?.DATABASE_URL ?? process.env.DATABASE_URL{{/if}}; +{{`#if` (eq this.provider "sqlite")}}Also applies to: 21-22
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@templates/create/astro/src/lib/prisma.ts.hbs` at line 4, The template uses implicit Handlebars variables packageManager and provider which breaks no-implicit-this; update the three occurrences to reference the root context explicitly (e.g. replace packageManager with `@root.packageManager` and provider with `@root.provider`) so the import line and the other usages use `@root.packageManager` and `@root.provider` instead of implicit names.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@templates/create/astro/prisma/seed.ts.hbs`:
- Line 1: The Handlebars template uses implicit `packageManager` references
(e.g., in the import line's conditional and the block around lines 37-41 using
`(eq packageManager "deno")`), which violates no-implicit-this; fix by replacing
those implicit references with explicit root lookups like `@root.packageManager`
(e.g., change `{{`#if` (eq packageManager "deno")}}` to `{{`#if` (eq
`@root.packageManager` "deno")}}` and similarly update the import conditional),
and ensure every occurrence of `packageManager` in Handlebars expressions in
this template is converted to `@root.packageManager`.
In `@templates/create/nest/prisma/seed.ts.hbs`:
- Line 1: The import line in the seed template uses an unqualified Handlebars
variable packageManager; update that conditional to use this.packageManager
(i.e., replace occurrences of packageManager with this.packageManager in the
seed template's import conditional) so scoping matches other templates and
preserves consistency across templates (e.g., where this.packageManager is
already used).
In `@templates/create/nest/src/lib/prisma.ts.hbs`:
- Around line 56-63: The file instantiates a PrismaClient singleton at module
load (const prisma = createPrismaClient()) which runs whenever
prismaClientOptions is imported (e.g., by PrismaService) and can create an
unwanted client; remove the top-level instantiation and either (A) export only
createPrismaClient and have callers (or a dedicated prisma singleton module)
create/hold the app-wide client lazily, or (B) move the seed-only client into a
separate module used only by seeding code, or implement a lazy getter like
getPrismaSingleton that calls createPrismaClient on first use; update imports in
PrismaService to use createPrismaClient/getPrismaSingleton or the new seed
module so no client is created during shared runtime import.
In `@templates/create/next/prisma/seed.ts.hbs`:
- Line 1: The Handlebars template uses the implicit `packageManager` in the
import and later block (in templates/create/next/prisma/seed.ts.hbs at the top
import and the block around lines 37-41); update those `{{`#if` (eq packageManager
"deno")}}`/`{{/if}}` usages to reference the explicit context (e.g.,
`../packageManager`) so they comply with the no-implicit-this rule and continue
to use the `eq` helper; make the same explicit-context change for every
occurrence in the file (the import line and the conditional block around lines
37-41).
In `@templates/create/next/src/lib/prisma.ts.hbs`:
- Around line 1-4: Change all implicit references to packageManager to use the
explicit argument form so the template passes the no-implicit-this lint: replace
packageManager with `@packageManager` in the requiresDotenvConfigImport(...) call,
in the import path string interpolation, and in the eq(...) helper usages (i.e.
update requiresDotenvConfigImport packageManager → requiresDotenvConfigImport
`@packageManager`, eq packageManager "deno" → eq `@packageManager` "deno", and any
other packageManager bare identifiers). This touches the
requiresDotenvConfigImport helper call, the import from
"../generated/prisma/client{{`#if` (eq packageManager "deno")}}.ts{{/if}}", and
every eq/conditional that uses packageManager; ensure all occurrences use
`@packageManager` to satisfy ember-template-lint no-implicit-this.
In `@templates/create/nuxt/prisma/seed.ts.hbs`:
- Line 1: The Handlebars template uses bare packageManager in two conditionals
(the import line referencing prisma and the block around lines 37–41), which
violates no-implicit-this; update both conditionals to reference
this.packageManager instead (e.g., change occurrences of {{`#if` (eq
packageManager "deno")}} and any other packageManager checks to {{`#if` (eq
this.packageManager "deno")}}) so the template explicitly reads from the current
context.
In `@templates/create/nuxt/server/utils/prisma.ts.hbs`:
- Around line 1-4: Update the Handlebars template to use an explicit
this-context for packageManager: replace every implicit packageManager reference
(e.g. in the block helper call {{`#if` (requiresDotenvConfigImport
packageManager)}}, the conditional {{`#if` (eq packageManager "deno")}}, and any
other occurrences) with this.packageManager so the helpers become {{`#if`
(requiresDotenvConfigImport this.packageManager)}}, {{`#if` (eq
this.packageManager "deno")}}, etc.; ensure all occurrences mentioned (imports,
PrismaClient path conditional, and the other conditional uses) are changed
consistently to avoid no-implicit-this lint errors.
In `@templates/create/svelte/prisma/seed.ts.hbs`:
- Line 1: Update the Handlebars template to avoid implicit this references by
changing any occurrences of packageManager to this.packageManager: specifically
update the import line (current import prisma ... {{`#if` (eq packageManager
"deno")}}) to use {{`#if` (eq this.packageManager "deno")}} and update the block
around lines 37-41 where packageManager is checked/used to use
this.packageManager instead so all template helpers reference the explicit this
context.
In `@templates/create/svelte/src/lib/server/prisma.ts.hbs`:
- Line 1: The template uses implicit Handlebars context for packageManager and
provider (e.g., the PrismaClient import line and other template spots
referencing packageManager/provider); update all occurrences to use explicit
this.* references (replace packageManager with this.packageManager and provider
with this.provider) so the import string and any conditional blocks (the import
line with PrismaClient, the blocks around provider usage, and the other template
spots) use this.packageManager and this.provider consistently to satisfy
no-implicit-this.
In `@templates/create/tanstack-start/prisma/seed.ts.hbs`:
- Line 1: Update the Handlebars checks to use an explicit context path instead
of implicit packageManager references: change occurrences like {{`#if` (eq
packageManager "deno")}} and any direct {{packageManager}} uses to {{`#if` (eq
this.packageManager "deno")}} (or {{this.packageManager}}) so the import line
import "../src/lib/prisma.server{{`#if` (eq packageManager "deno")}}.ts{{/if}}";
and the check at line 37 reference this.packageManager explicitly to satisfy the
no-implicit-this lint rule.
In `@templates/create/tanstack-start/src/lib/prisma.server.ts.hbs`:
- Line 1: The template uses implicit `packageManager` usage (e.g. in the helper
call `requiresDotenvConfigImport packageManager`) which triggers
no-implicit-this lint errors; update all occurrences to use explicit context
(replace `packageManager` with `this.packageManager`) wherever it appears in
this template (including the `requiresDotenvConfigImport` call and the other
spots noted) so the Handlebars helper invocations and references are explicit
and lint-clean.
- Line 15: The helper that returns the SQLite adapter
(sqliteAdapterClass/sqliteAdapterPackage) currently maps Bun to
`@prisma/adapter-better-sqlite3` which is incompatible with Bun; update the
mapping logic in the helper in src/templates/shared.ts so that when the runtime
or package manager is Bun it returns `@prisma/adapter-libsql` and the
corresponding class name (instead of adapter-better-sqlite3), and ensure any
callers (e.g., the template usage referencing sqliteAdapterClass and
sqliteAdapterPackage) pick up the new values so Bun+SQLite projects generate
with `@prisma/adapter-libsql`.
In `@templates/create/turborepo/packages/db/src/client.ts.hbs`:
- Around line 1-2: Refactor the duplicate Deno branching in the Handlebars
template by replacing the paired "{{`#if` (eq packageManager \"deno\")}} ...
{{else}} ... {{/if}}" usages with a single inverse-style conditional (e.g., use
"{{`#unless` (eq packageManager \"deno\")}} ... {{/unless}}" or equivalent) in
both occurrences around the "{{`#if` (eq packageManager \"deno\")}}" block and the
second block at lines 24-28 so the template reads more clearly and avoids
duplicated branching logic.
---
Duplicate comments:
In `@templates/create/astro/src/lib/prisma.ts.hbs`:
- Line 4: The template uses implicit Handlebars variables packageManager and
provider which breaks no-implicit-this; update the three occurrences to
reference the root context explicitly (e.g. replace packageManager with
`@root.packageManager` and provider with `@root.provider`) so the import line and
the other usages use `@root.packageManager` and `@root.provider` instead of implicit
names.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2e6628b6-ed17-4b61-82d5-c4e80cdf6114
📒 Files selected for processing (14)
templates/create/astro/prisma/seed.ts.hbstemplates/create/astro/src/lib/prisma.ts.hbstemplates/create/nest/prisma/seed.ts.hbstemplates/create/nest/src/lib/prisma.ts.hbstemplates/create/next/prisma/seed.ts.hbstemplates/create/next/src/lib/prisma.ts.hbstemplates/create/nuxt/prisma/seed.ts.hbstemplates/create/nuxt/server/utils/prisma.ts.hbstemplates/create/svelte/prisma/seed.ts.hbstemplates/create/svelte/src/lib/server/prisma.ts.hbstemplates/create/tanstack-start/prisma/seed.ts.hbstemplates/create/tanstack-start/src/lib/prisma.server.ts.hbstemplates/create/turborepo/packages/db/prisma/seed.ts.hbstemplates/create/turborepo/packages/db/src/client.ts.hbs
|
Addressed the real template issues in ade9b0e: Nest no longer creates an eager PrismaClient singleton, and the Turborepo template uses the cleaner inverse conditional. I am keeping the bare Handlebars context style instead of switching only these files to this.packageManager/this.provider: the repo does not run ember-template-lint/no-implicit-this, existing templates already use bare context, and the rendered output is unchanged. |
Summary
--migrate-and-seed/--no-migrate-and-seeddotenv/configin Prisma config templates for Bun/Node runtimes soenv("DATABASE_URL")works during CLI commandsTest Plan