-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
relation_fields
validation to accept primary key indexes (#4376)
* Fix `relation_fields` validation to accept primary key indexes This resolves prisma/language-tools#1387 --------- Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
- Loading branch information
Showing
4 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
...ion/attributes/index/missing_index_warning/relation_mode_prisma/one_field_at_at_id.prisma
This file contains 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,19 @@ | ||
// no relation index validation warning on relationMode = "prisma" when a referenced field is already in @@id. | ||
|
||
datasource db { | ||
provider = "mysql" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
|
||
model SomeUser { | ||
id Int @id | ||
profile Profile? | ||
} | ||
|
||
model Profile { | ||
id Int | ||
user SomeUser? @relation(fields: [id], references: [id]) | ||
@@id([id]) | ||
} |
17 changes: 17 additions & 0 deletions
17
...dation/attributes/index/missing_index_warning/relation_mode_prisma/one_field_at_id.prisma
This file contains 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,17 @@ | ||
// no relation index validation warning on relationMode = "prisma" when a referenced field is already in @id. | ||
|
||
datasource db { | ||
provider = "mysql" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
|
||
model SomeUser { | ||
id Int @id | ||
profile Profile? | ||
} | ||
|
||
model Profile { | ||
id Int @id | ||
user SomeUser? @relation(fields: [id], references: [id]) | ||
} |
32 changes: 32 additions & 0 deletions
32
.../attributes/index/missing_index_warning/relation_mode_prisma/three_fields_mixed_id.prisma
This file contains 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,32 @@ | ||
// add missing relation index validation warning on relationMode = "prisma". | ||
|
||
datasource db { | ||
provider = "mysql" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
|
||
model SomeUser { | ||
idA Int | ||
idB Int | ||
idC Int | ||
posts Post[] | ||
@@id([idA, idB, idC]) | ||
} | ||
|
||
model Post { | ||
userIdA Int @unique | ||
userIdB Int | ||
userIdC Int @unique | ||
user SomeUser @relation(fields: [userIdA, userIdB, userIdC], references: [idA, idB, idC]) | ||
@@id([userIdA, userIdB]) | ||
} | ||
|
||
// [1;93mwarning[0m: [1mWith `relationMode = "prisma"`, no foreign keys are used, so relation fields will not benefit from the index usually created by the relational database under the hood. This can lead to poor performance when querying these fields. We recommend adding an index manually. Learn more at https://pris.ly/d/relation-mode-prisma-indexes" [0m | ||
// [1;94m-->[0m [4mschema.prisma:22[0m | ||
// [1;94m | [0m | ||
// [1;94m21 | [0m userIdC Int @unique | ||
// [1;94m22 | [0m user SomeUser [1;93m@relation(fields: [userIdA, userIdB, userIdC], references: [idA, idB, idC])[0m | ||
// [1;94m | [0m |