-
Notifications
You must be signed in to change notification settings - Fork 6
feat(sql-contract-psl): support composite primary keys #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+98
−0
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # WS5: PSL composite primary keys | ||
|
|
||
| ## Summary | ||
|
|
||
| Support SQL PSL model-level composite primary keys via `@@id([fieldA, fieldB])` in the contract interpreter, closing the current printer/interpreter asymmetry for greenfield junction tables. | ||
|
|
||
| ## Problem | ||
|
|
||
| `contract infer` can already print composite SQL primary keys as `@@id([...])`, but the PSL interpreter rejects `@@id` as an unsupported model attribute. This blocks the WS5 M2 SaaS skeleton, specifically membership/junction models that use composite primary keys instead of surrogate IDs. | ||
|
|
||
| ## Scope | ||
|
|
||
| - Accept `@@id([fieldA, fieldB])` on SQL PSL models. | ||
| - Preserve declared field order in the emitted primary key. | ||
| - Resolve fields through existing `@map`/`@@map` mappings so storage primary keys use column names. | ||
| - Support the `map: "constraint_name"` argument consistently with `@@unique` and `@@index`. | ||
| - Return diagnostics for malformed field lists, unknown fields, nullable fields, and duplicate field-level/model-level primary key declarations. | ||
| - Add a regression proving PSL emitted by `contract infer` for a composite primary key can be interpreted back into an equivalent contract shape. | ||
|
|
||
| ## Out of Scope | ||
|
|
||
| - Native scalar arrays. | ||
| - `@updatedAt`. | ||
| - Inline `@db.*` field attributes. | ||
| - P7 upgrade compatibility syntax. | ||
| - New relation inference behavior beyond what composite primary keys require. | ||
|
|
||
| ## Acceptance Criteria | ||
|
|
||
| - A model with `@@id([orgId, userId])` emits `storage.tables.<table>.primaryKey.columns` with the mapped column names in the same order. | ||
| - A model with `@@id([orgId, userId], map: "membership_pkey")` emits the primary key name. | ||
| - A model with `@@id` and no field-level `@id` no longer triggers `PSL_MISSING_PRIMARY_KEY`. | ||
| - A model that combines field-level `@id` with model-level `@@id` fails with a clear diagnostic. | ||
| - A model that references an unknown or nullable field in `@@id` fails with a clear diagnostic. | ||
| - Focused package tests pass for `@prisma-next/sql-contract-psl`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.