From 51eca8590c4d4dc41ae9395b4f2c9c140952c9d9 Mon Sep 17 00:00:00 2001 From: Sophie Atkins Date: Fri, 14 Jun 2024 11:32:30 +0200 Subject: [PATCH] Add test for missing index quick fix with multibyte characters comment --- .../schema.prisma | 13 +++--- .../result.json | 41 +++++++++++++++++++ .../schema.prisma | 22 ++++++++++ prisma-fmt/tests/code_actions/tests.rs | 1 + 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/result.json create mode 100644 prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/schema.prisma diff --git a/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/schema.prisma b/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/schema.prisma index bb29fe70cb06..bfa8b520fd54 100644 --- a/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/schema.prisma +++ b/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index/schema.prisma @@ -1,21 +1,22 @@ generator client { - provider = "prisma-client-js" + provider = "prisma-client-js" previewFeatures = ["referentialIntegrity"] } datasource db { - provider = "mysql" - url = env("TEST_DATABASE_URL") + provider = "mysql" + url = env("TEST_DATABASE_URL") relationMode = "prisma" } model SomeUser { - id Int @id + id Int @id posts Post[] } +// comment model Post { - id Int @id + id Int @id userId Int - user SomeUser @relation(fields: [userId], references: [id]) + user SomeUser @relation(fields: [userId], references: [id]) } diff --git a/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/result.json b/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/result.json new file mode 100644 index 000000000000..24a4b67c02e3 --- /dev/null +++ b/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/result.json @@ -0,0 +1,41 @@ +[ + { + "title": "Add an index for the relation's field(s)", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 19, + "character": 18 + }, + "end": { + "line": 19, + "character": 63 + } + }, + "severity": 2, + "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-prisma-indexes\" " + } + ], + "edit": { + "changes": { + "file:///path/to/schema.prisma": [ + { + "range": { + "start": { + "line": 20, + "character": 0 + }, + "end": { + "line": 20, + "character": 1 + } + }, + "newText": "\n @@index([userId])\n}" + } + ] + } + } + } +] \ No newline at end of file diff --git a/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/schema.prisma b/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/schema.prisma new file mode 100644 index 000000000000..617895ccd8d3 --- /dev/null +++ b/prisma-fmt/tests/code_actions/scenarios/relation_mode_prisma_missing_index_multibyte/schema.prisma @@ -0,0 +1,22 @@ +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]) +} diff --git a/prisma-fmt/tests/code_actions/tests.rs b/prisma-fmt/tests/code_actions/tests.rs index b80f2cdbb31f..7bce24f57779 100644 --- a/prisma-fmt/tests/code_actions/tests.rs +++ b/prisma-fmt/tests/code_actions/tests.rs @@ -31,6 +31,7 @@ scenarios! { one_to_one_referencing_side_misses_unique_compound_field_indentation_four_spaces relation_mode_prisma_missing_index relation_mode_prisma_missing_index_multifile + relation_mode_prisma_missing_index_multibyte relation_mode_referential_integrity relation_mode_mysql_foreign_keys_set_default relation_mode_mysql_foreign_keys_set_default_multifile