-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fmt): add quick-fix for missing indexes when relationMode = "pri…
…sma" (#3431) Co-authored-by: Tom tom@tomhoule.com
- Loading branch information
Showing
6 changed files
with
243 additions
and
33 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
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
16 changes: 16 additions & 0 deletions
16
prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/diagnostics.json
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,16 @@ | ||
[ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 19, | ||
"character": 20 | ||
}, | ||
"end": { | ||
"line": 19, | ||
"character": 63 | ||
} | ||
}, | ||
"severity": 1, | ||
"message": "With `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#indexes" | ||
} | ||
] |
41 changes: 41 additions & 0 deletions
41
prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/result.json
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,41 @@ | ||
[ | ||
{ | ||
"title": "Add an index for the relation's field(s)", | ||
"kind": "quickfix", | ||
"diagnostics": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 19, | ||
"character": 20 | ||
}, | ||
"end": { | ||
"line": 19, | ||
"character": 63 | ||
} | ||
}, | ||
"severity": 1, | ||
"message": "With `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#indexes" | ||
} | ||
], | ||
"edit": { | ||
"changes": { | ||
"file:///path/to/schema.prisma": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 20, | ||
"character": 0 | ||
}, | ||
"end": { | ||
"line": 20, | ||
"character": 1 | ||
} | ||
}, | ||
"newText": "\n @@index([userId])\n}" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] |
21 changes: 21 additions & 0 deletions
21
prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/schema.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,21 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
|
||
datasource db { | ||
provider = "mysql" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
|
||
model SomeUser { | ||
id Int @id | ||
posts Post[] | ||
} | ||
|
||
model Post { | ||
id Int @id | ||
userId Int | ||
user SomeUser @relation(fields: [userId], references: [id]) | ||
} |
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