Repository navigation
fix: preserve FK referential actions in schema IR - #608
Conversation
📝 WalkthroughWalkthroughThe PR fixes a bug where foreign key referential actions ( ChangesForeign Key Referential Actions Preservation
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 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)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
Signed-off-by: Seven Du <[email protected]>
90ff74f to
951b608
Compare
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/extension-cipherstash
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
SevInf
left a comment
There was a problem hiding this comment.
Thank you very much!
Waiting for CI and merging
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/2-sql/9-family/test/contract-to-schema-ir.test.ts (1)
473-517: ⚡ Quick winConsider adding test cases for additional edge cases.
The test validates that both
onDeleteandonUpdateare preserved when present. Consider adding test cases for:
- Only
onDeletespecified (noonUpdate)- Only
onUpdatespecified (noonDelete)- Explicit
'noAction'values (to verify they're preserved as-is, not normalized during conversion)The existing test at line 643 already covers the case where neither field is present, so basic coverage exists.
🤖 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/2-sql/9-family/test/contract-to-schema-ir.test.ts` around lines 473 - 517, Add three new test cases alongside the existing "converts foreign keys (reshapes references)" test that call contractToSchemaIR with a SqlStorage containing a Post->User foreign key but vary the cascade/update settings: one where only onDelete is set, one where only onUpdate is set, and one where onDelete/onUpdate are explicitly 'noAction'; in each test assert that result.tables['Post']!.foreignKeys contains the corresponding object with the exact onDelete/onUpdate values preserved (use the same storage construction pattern and testRenderer as in the current test to locate SqlStorage and contractToSchemaIR usage).
🤖 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.
Nitpick comments:
In `@packages/2-sql/9-family/test/contract-to-schema-ir.test.ts`:
- Around line 473-517: Add three new test cases alongside the existing "converts
foreign keys (reshapes references)" test that call contractToSchemaIR with a
SqlStorage containing a Post->User foreign key but vary the cascade/update
settings: one where only onDelete is set, one where only onUpdate is set, and
one where onDelete/onUpdate are explicitly 'noAction'; in each test assert that
result.tables['Post']!.foreignKeys contains the corresponding object with the
exact onDelete/onUpdate values preserved (use the same storage construction
pattern and testRenderer as in the current test to locate SqlStorage and
contractToSchemaIR usage).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 0ecdd879-2fce-4116-aab1-de3db8f20422
📒 Files selected for processing (2)
packages/2-sql/9-family/src/core/migrations/contract-to-schema-ir.tspackages/2-sql/9-family/test/contract-to-schema-ir.test.ts
Summary
Preserves
onDeleteandonUpdatewhen converting contract foreign keys into SQL schema IR for migration planning.This prevents unchanged foreign keys with explicit non-default referential actions from being compared as if the source side used the default
noActionbehavior.Fixes #606.
Changes
fk.onDeleteandfk.onUpdatethroughconvertForeignKey()incontract-to-schema-ir.Validation
npm exec --yes [email protected] -- --filter @prisma-next/family-sql... buildnpm exec --yes [email protected] -- --filter @prisma-next/family-sql testnpm exec --yes [email protected] -- --filter @prisma-next/family-sql typechecknpm exec --yes [email protected] -- --filter @prisma-next/family-sql lintSummary by CodeRabbit
New Features
Tests