Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
psl: fix database name clash validation with multiSchema
The validation we have validates that no two models in the whole schema have the same database name. Database name is defined as the contents of the model's `@@map` attribute, or the model name if the model name does not have an `@@map` attribute. It is the name we give to the table/collection corresponding to the model in the database. When the `multiSchema` preview feature is turned on, the tables in the database can be in different schemas, so we have to adapt the validation to allow multiple models to have the same database name, as long as they are in a different schema. This is what this commit does. closes prisma/prisma#15009
- Loading branch information
Showing
9 changed files
with
136 additions
and
26 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
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
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
23 changes: 23 additions & 0 deletions
23
psl/psl/tests/validation/attributes/map/duplicate_models_with_map_on_both_sides.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,23 @@ | ||
datasource mydb { | ||
provider = "sqlite" | ||
url = env("TEST_DB_URL") | ||
} | ||
|
||
model Dog { | ||
id Int @id | ||
@@map("pets") | ||
} | ||
|
||
model Cat { | ||
id Int @id | ||
@@map("pets") | ||
} | ||
|
||
// [1;91merror[0m: [1mThe model with database name "pets" could not be defined because another model with this name exists: "Dog"[0m | ||
// [1;94m-->[0m [4mschema.prisma:15[0m | ||
// [1;94m | [0m | ||
// [1;94m14 | [0m | ||
// [1;94m15 | [0m [1;91m@@map("pets")[0m | ||
// [1;94m | [0m |
30 changes: 30 additions & 0 deletions
30
...sts/validation/attributes/schema/tables_in_different_schemas_with_same_mapped_name.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,30 @@ | ||
// issue: https://github.com/prisma/prisma/issues/15009 | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["multiSchema"] | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("TEST_DATABASE_URL") | ||
schemas = ["base", "transactional"] | ||
} | ||
|
||
model User { | ||
id String @id | ||
email String | ||
posts Post[] | ||
@@map("some_table") | ||
@@schema("base") | ||
} | ||
|
||
model Post { | ||
title String | ||
authorId String @unique | ||
author User? @relation(fields: [authorId], references: [id]) | ||
@@map("some_table") | ||
@@schema("transactional") | ||
} |
31 changes: 31 additions & 0 deletions
31
...psl/tests/validation/attributes/schema/tables_in_same_schema_with_same_mapped_name.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,31 @@ | ||
datasource mydb { | ||
provider = "sqlserver" | ||
url = env("TEST_DB_URL") | ||
schemas = ["base", "transactional"] | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["multiSchema"] | ||
} | ||
|
||
|
||
model Dog { | ||
id Int @id | ||
@@map("pets") | ||
} | ||
|
||
model Cat { | ||
id Int @id | ||
@@map("pets") | ||
} | ||
|
||
// [1;91merror[0m: [1mThe model with database name "pets" could not be defined because another model with this name exists: "Dog"[0m | ||
// [1;94m-->[0m [4mschema.prisma:15[0m | ||
// [1;94m | [0m | ||
// [1;94m14 | [0m | ||
// [1;94m15 | [0m [1;91m@@map("pets")[0m | ||
// [1;94m | [0m | ||
|