-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3337 from prisma/fix/re-introspection-referential…
…-integrity-16007 fix: re-introspection now preserves 'referentialIntegrity' policy
- Loading branch information
Showing
7 changed files
with
1,214 additions
and
1 deletion.
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
1 change: 1 addition & 0 deletions
1
introspection-engine/introspection-engine-tests/tests/re_introspection/mod.rs
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod mssql; | ||
mod mysql; | ||
mod relation_mode; | ||
mod sqlite; | ||
mod vitess; | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
introspection-engine/introspection-engine-tests/tests/re_introspection/relation_mode/mod.rs
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,4 @@ | ||
mod mssql; | ||
mod mysql; | ||
mod postgres; | ||
mod sqlite; |
298 changes: 298 additions & 0 deletions
298
...ospection-engine/introspection-engine-tests/tests/re_introspection/relation_mode/mssql.rs
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,298 @@ | ||
use indoc::indoc; | ||
use introspection_engine_tests::test_api::*; | ||
|
||
// referentialIntegrity="prisma" is renamed as relationMode="prisma", and @relations are preserved. | ||
#[test_connector(tags(Mssql))] | ||
async fn referential_integrity_prisma(api: &TestApi) -> TestResult { | ||
let init = indoc! {r#" | ||
CREATE TABLE [dbo].[Foo] ( | ||
[id] INT NOT NULL, | ||
[bar_id] INT NOT NULL, | ||
CONSTRAINT [Foo_pkey] PRIMARY KEY CLUSTERED ([id]), | ||
CONSTRAINT [Foo_bar_id_key] UNIQUE NONCLUSTERED ([bar_id]) | ||
); | ||
CREATE TABLE [dbo].[Bar] ( | ||
[id] INT NOT NULL, | ||
CONSTRAINT [Bar_pkey] PRIMARY KEY CLUSTERED ([id]) | ||
); | ||
"#}; | ||
|
||
api.raw_cmd(&init).await; | ||
|
||
let input = indoc! {r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
referentialIntegrity = "prisma" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
bar_id Int @unique | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#}; | ||
|
||
let expected = expect![[r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
bar_id Int @unique | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#]]; | ||
|
||
let result = api.re_introspect_config(input).await?; | ||
expected.assert_eq(&result); | ||
|
||
Ok(()) | ||
} | ||
|
||
// referentialIntegrity="foreignKeys" is renamed as relationMode="foreignKeys", and @relations are preserved but moved to the bottom. | ||
#[test_connector(tags(Mssql))] | ||
async fn referential_integrity_foreign_keys(api: &TestApi) -> TestResult { | ||
let init = indoc! {r#" | ||
CREATE TABLE [dbo].[Foo] ( | ||
[id] INT NOT NULL, | ||
[bar_id] INT NOT NULL, | ||
CONSTRAINT [Foo_pkey] PRIMARY KEY CLUSTERED ([id]), | ||
CONSTRAINT [Foo_bar_id_key] UNIQUE NONCLUSTERED ([bar_id]) | ||
); | ||
CREATE TABLE [dbo].[Bar] ( | ||
[id] INT NOT NULL, | ||
CONSTRAINT [Bar_pkey] PRIMARY KEY CLUSTERED ([id]) | ||
); | ||
ALTER TABLE [dbo].[Foo] ADD CONSTRAINT [Foo_bar_id_fkey] FOREIGN KEY ([bar_id]) REFERENCES [dbo].[Bar]([id]) ON DELETE NO ACTION ON UPDATE CASCADE; | ||
"#}; | ||
|
||
api.raw_cmd(&init).await; | ||
|
||
let input = indoc! {r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
referentialIntegrity = "foreignKeys" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
bar_id Int @unique | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#}; | ||
|
||
let expected = expect![[r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "foreignKeys" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar_id Int @unique | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#]]; | ||
|
||
let result = api.re_introspect_config(input).await?; | ||
expected.assert_eq(&result); | ||
|
||
Ok(()) | ||
} | ||
|
||
// relationMode="prisma" preserves the relation policy ("prisma") as well as @relations. | ||
#[test_connector(tags(Mssql))] | ||
async fn relation_mode_prisma(api: &TestApi) -> TestResult { | ||
let init = indoc! {r#" | ||
CREATE TABLE [dbo].[Foo] ( | ||
[id] INT NOT NULL, | ||
[bar_id] INT NOT NULL, | ||
CONSTRAINT [Foo_pkey] PRIMARY KEY CLUSTERED ([id]), | ||
CONSTRAINT [Foo_bar_id_key] UNIQUE NONCLUSTERED ([bar_id]) | ||
); | ||
CREATE TABLE [dbo].[Bar] ( | ||
[id] INT NOT NULL, | ||
CONSTRAINT [Bar_pkey] PRIMARY KEY CLUSTERED ([id]) | ||
); | ||
"#}; | ||
|
||
api.raw_cmd(&init).await; | ||
|
||
let input = indoc! {r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
bar_id Int @unique | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#}; | ||
|
||
let expected = expect![[r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "prisma" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
bar_id Int @unique | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#]]; | ||
|
||
let result = api.re_introspect_config(input).await?; | ||
expected.assert_eq(&result); | ||
|
||
Ok(()) | ||
} | ||
|
||
// relationMode="foreignKeys" preserves the relation policy ("foreignKeys") as well as @relations, which are moved to the bottom. | ||
#[test_connector(tags(Mssql))] | ||
async fn relation_mode_foreign_keys(api: &TestApi) -> TestResult { | ||
let init = indoc! {r#" | ||
CREATE TABLE [dbo].[Foo] ( | ||
[id] INT NOT NULL, | ||
[bar_id] INT NOT NULL, | ||
CONSTRAINT [Foo_pkey] PRIMARY KEY CLUSTERED ([id]), | ||
CONSTRAINT [Foo_bar_id_key] UNIQUE NONCLUSTERED ([bar_id]) | ||
); | ||
CREATE TABLE [dbo].[Bar] ( | ||
[id] INT NOT NULL, | ||
CONSTRAINT [Bar_pkey] PRIMARY KEY CLUSTERED ([id]) | ||
); | ||
ALTER TABLE [dbo].[Foo] ADD CONSTRAINT [Foo_bar_id_fkey] FOREIGN KEY ([bar_id]) REFERENCES [dbo].[Bar]([id]) ON DELETE NO ACTION ON UPDATE CASCADE; | ||
"#}; | ||
|
||
api.raw_cmd(&init).await; | ||
|
||
let input = indoc! {r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "foreignKeys" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
bar_id Int @unique | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#}; | ||
|
||
let expected = expect![[r#" | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["referentialIntegrity"] | ||
} | ||
datasource db { | ||
provider = "sqlserver" | ||
url = env("TEST_DATABASE_URL") | ||
relationMode = "foreignKeys" | ||
} | ||
model Foo { | ||
id Int @id | ||
bar_id Int @unique | ||
bar Bar @relation(fields: [bar_id], references: [id]) | ||
} | ||
model Bar { | ||
id Int @id | ||
foo Foo? | ||
} | ||
"#]]; | ||
|
||
let result = api.re_introspect_config(input).await?; | ||
expected.assert_eq(&result); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.