fix(migrate): stabilize migrate diff when config has no datasource#29539
fix(migrate): stabilize migrate diff when config has no datasource#29539narcilee7 wants to merge 1 commit into
Conversation
Summary by CodeRabbit
WalkthroughThis PR fixes a flaky schema engine invocation error by ensuring ChangesSchema Engine Datasource Initialization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/migrate/src/__tests__/MigrateDiff.test.ts`:
- Around line 251-257: Add an explicit assertion that no error output was
produced for this test case: after the existing
expect(ctx.normalizedCapturedStdout()).toMatchInlineSnapshot(...) add an
assertion that ctx.mocked['console.error'] (or the stderr capture used in this
suite) is empty or was not called (e.g.,
expect(ctx.mocked['console.error']).toEqual([]) or toHaveBeenCalledTimes(0)).
This ensures the test checks both stdout via ctx.normalizedCapturedStdout() and
that there is no stderr via ctx.mocked['console.error'] for the Added tables
case.
🪄 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: e1f897f5-e011-4f21-9d15-7a0bdedfb841
📒 Files selected for processing (3)
packages/migrate/src/SchemaEngineCLI.tspackages/migrate/src/__tests__/MigrateDiff.test.tspackages/migrate/src/__tests__/fixtures/schema-only-sqlite-no-config/prisma/schema.prisma
| expect(ctx.normalizedCapturedStdout()).toMatchInlineSnapshot(` | ||
| " | ||
| [+] Added tables | ||
| - Blog | ||
| " | ||
| `) | ||
| }) |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
Add an explicit stderr/console.error assertion for this new case.
For consistency with adjacent tests and to catch partial regressions, consider asserting no error output (e.g., ctx.mocked['console.error'] is empty) after Line 250.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/migrate/src/__tests__/MigrateDiff.test.ts` around lines 251 - 257,
Add an explicit assertion that no error output was produced for this test case:
after the existing
expect(ctx.normalizedCapturedStdout()).toMatchInlineSnapshot(...) add an
assertion that ctx.mocked['console.error'] (or the stderr capture used in this
suite) is empty or was not called (e.g.,
expect(ctx.mocked['console.error']).toEqual([]) or toHaveBeenCalledTimes(0)).
This ensures the test checks both stdout via ctx.normalizedCapturedStdout() and
that there is no stderr via ctx.mocked['console.error'] for the Added tables
case.
Summary
Fixes a
prisma migrate difffailure mode where schema-engine could exit withError in Schema enginein schema-only diff flows whenprisma.config.tshas nodatasourceconfigured.Closes #29062.
Root cause
SchemaEngineCLIonly passed--datasourcewhenconfig.datasourceexisted. In schema-only diff scenarios (--from/--to-schema), this could lead schema-engine startup to fail with a required--datasourceargument error.Changes
--datasourceto schema-engine startup inSchemaEngineCLI.JSON.stringify(this.datasource ?? {})as fallback when datasource is absent.MigrateDiff.test.tsfor--from-empty --to-schemawith no datasource in Prisma config.schema-only-sqlite-no-config.Testing
pnpm --filter @prisma/migrate test MigrateDiff.test.ts --runInBand --testNamePattern "without datasource in Prisma config"MigrateDiff.test.tsrun in this environment has unrelated DB connectivity failures for provider suites requiring running local services (Postgres/MySQL/MSSQL/Cockroach).