Skip to content

Commit

Permalink
Merge pull request #2199 from prisma/named-constraint-forgotten-gates
Browse files Browse the repository at this point in the history
Remove residual NamedConstraint gating
  • Loading branch information
tomhoule committed Sep 2, 2021
2 parents 97b69d7 + de76a9d commit 587d59c
Show file tree
Hide file tree
Showing 35 changed files with 1,008 additions and 580 deletions.
Expand Up @@ -13,7 +13,10 @@ async fn a_table_without_uniques_should_ignore(api: &TestApi) -> TestResult {
t.add_column("id", types::integer());
t.add_column("user_id", types::integer().nullable(false));
t.add_index("Post_user_id_idx", types::index(&["user_id"]));
t.add_foreign_key(&["user_id"], "User", &["id"]);
t.add_constraint(
"thefk",
types::foreign_constraint(&["user_id"], "User", &["id"], None, None),
);
});
})
.await?;
Expand All @@ -23,7 +26,7 @@ async fn a_table_without_uniques_should_ignore(api: &TestApi) -> TestResult {
model Post {
id Int
user_id Int
User User @relation(fields: [user_id], references: [id], onUpdate: NoAction)
User User @relation(fields: [user_id], references: [id], onUpdate: NoAction, map: "thefk")
@@index([user_id])
@@ignore
Expand Down
Expand Up @@ -51,7 +51,7 @@ async fn a_table_without_uniques_should_ignore(api: &TestApi) -> TestResult {
model Post {
id Int
user_id Int
User User @relation(fields: [user_id], references: [id])
User User @relation(fields: [user_id], references: [id], map: "user_id")
@@index([user_id])
@@ignore
Expand Down
Expand Up @@ -12,7 +12,7 @@ use introspection_engine_tests::TestResult;
use quaint::prelude::Queryable;
use test_macros::test_connector;

#[test_connector(preview_features("NamedConstraints"), tags(Mssql, Postgres))]
#[test_connector(tags(Mssql, Postgres))]
async fn introspecting_non_default_pkey_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -47,7 +47,7 @@ async fn introspecting_non_default_pkey_names_works(api: &TestApi) -> TestResult
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql, Postgres))]
#[test_connector(tags(Mssql, Postgres))]
async fn introspecting_default_pkey_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -82,7 +82,7 @@ async fn introspecting_default_pkey_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql, Postgres))]
#[test_connector(tags(Mssql, Postgres))]
async fn introspecting_non_default_unique_constraint_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -117,7 +117,7 @@ async fn introspecting_non_default_unique_constraint_names_works(api: &TestApi)
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql, Postgres))]
#[test_connector(tags(Mssql, Postgres))]
async fn introspecting_default_unique_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -152,7 +152,7 @@ async fn introspecting_default_unique_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql, Postgres))]
#[test_connector(tags(Mssql, Postgres))]
async fn introspecting_non_default_index_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -193,7 +193,7 @@ async fn introspecting_non_default_index_names_works(api: &TestApi) -> TestResul
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql, Postgres))]
#[test_connector(tags(Mssql, Postgres))]
async fn introspecting_default_index_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -234,7 +234,7 @@ async fn introspecting_default_index_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), exclude(Mssql, Mysql))]
#[test_connector(exclude(Mssql, Mysql))]
async fn introspecting_default_fk_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down Expand Up @@ -276,7 +276,7 @@ async fn introspecting_default_fk_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), exclude(Sqlite, Mssql, Mysql))]
#[test_connector(exclude(Sqlite, Mssql, Mysql))]
async fn introspecting_custom_fk_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down Expand Up @@ -318,7 +318,7 @@ async fn introspecting_custom_fk_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql))]
#[test_connector(tags(Mssql))]
async fn introspecting_custom_default_names_should_output_to_dml(api: &TestApi) -> TestResult {
let create_table = format!(
"CREATE TABLE [{}].[custom_defaults_test] (id INT CONSTRAINT pk_meow PRIMARY KEY, data NVARCHAR(255) CONSTRAINT meow DEFAULT 'foo')",
Expand All @@ -339,7 +339,7 @@ async fn introspecting_custom_default_names_should_output_to_dml(api: &TestApi)
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql))]
#[test_connector(tags(Mssql))]
async fn introspecting_default_default_names_should_not_output_to_dml(api: &TestApi) -> TestResult {
let create_table = format!(
"CREATE TABLE [{}].[custom_defaults_test] (id INT CONSTRAINT pk_meow PRIMARY KEY, data NVARCHAR(255) CONSTRAINT custom_defaults_test_data_df DEFAULT 'foo')",
Expand Down
Expand Up @@ -4,7 +4,7 @@ use expect_test::expect;
use introspection_engine_tests::{test_api::*, TestResult};
use test_macros::test_connector;

#[test_connector(preview_features("NamedConstraints"), tags(Mssql))]
#[test_connector(tags(Mssql))]
async fn introspecting_custom_fk_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down Expand Up @@ -46,7 +46,7 @@ async fn introspecting_custom_fk_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mssql))]
#[test_connector(tags(Mssql))]
async fn introspecting_default_fk_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down
Expand Up @@ -7,7 +7,7 @@ use introspection_engine_tests::test_api::*;
use introspection_engine_tests::TestResult;
use test_macros::test_connector;

#[test_connector(preview_features("NamedConstraints"), tags(Mysql))]
#[test_connector(tags(Mysql))]
async fn introspecting_custom_fk_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down Expand Up @@ -48,7 +48,7 @@ async fn introspecting_custom_fk_names_works(api: &TestApi) -> TestResult {
Ok(())
}

#[test_connector(preview_features("NamedConstraints"), tags(Mysql))]
#[test_connector(tags(Mysql))]
async fn introspecting_default_fk_names_works(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down
Expand Up @@ -4,7 +4,7 @@ use expect_test::expect;
use introspection_engine_tests::{test_api::*, TestResult};
use test_macros::test_connector;

#[test_connector(preview_features("NamedConstraints"), tags(Sqlite))]
#[test_connector(tags(Sqlite))]
async fn introspecting_custom_fk_names_does_not_return_them(api: &TestApi) -> TestResult {
api.barrel()
.execute(move |migration| {
Expand Down
Expand Up @@ -1627,7 +1627,7 @@ async fn do_not_try_to_keep_custom_many_to_many_self_relation_names(api: &TestAp
Ok(())
}

#[test_connector(tags(Postgres, Mssql), preview_features("NamedConstraints"))]
#[test_connector(tags(Postgres, Mssql))]
async fn re_introspecting_custom_compound_unique_names(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand All @@ -1650,11 +1650,6 @@ async fn re_introspecting_custom_compound_unique_names(api: &TestApi) -> TestRes
.await?;

let input_dm = indoc! {r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["NamedConstraints"]
}
model User {
id Int @id @default(autoincrement())
first Int
Expand All @@ -1665,11 +1660,6 @@ async fn re_introspecting_custom_compound_unique_names(api: &TestApi) -> TestRes
"#};

let final_dm = indoc! {r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["NamedConstraints"]
}
model User {
id Int @id @default(autoincrement())
first Int
Expand Down Expand Up @@ -1698,7 +1688,7 @@ async fn re_introspecting_custom_compound_unique_names(api: &TestApi) -> TestRes
Ok(())
}

#[test_connector(tags(Postgres, Mssql), preview_features("NamedConstraints"))]
#[test_connector(tags(Postgres, Mssql))]
async fn re_introspecting_custom_compound_id_names(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
Expand Down Expand Up @@ -1726,11 +1716,6 @@ async fn re_introspecting_custom_compound_id_names(api: &TestApi) -> TestResult

let input_dm = api.dm_with_sources(
r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["NamedConstraints"]
}
model User {
first Int
last Int
Expand All @@ -1748,11 +1733,6 @@ async fn re_introspecting_custom_compound_id_names(api: &TestApi) -> TestResult
);

let final_dm = r#"
generator js {
provider = "prisma-client-js"
previewFeatures = ["NamedConstraints"]
}
model User {
first Int
last Int
Expand Down
Expand Up @@ -4,29 +4,35 @@ use introspection_engine_tests::test_api::*;

#[test_connector(tags(Mssql))]
async fn multiple_changed_relation_names(api: &TestApi) -> TestResult {
api.barrel()
.execute(|migration| {
migration.create_table("Employee", |t| {
t.add_column("id", types::integer().increments(true));
t.add_constraint("Employee_pkey", types::primary_constraint(&["id"]))
});
let setup = format!(
r#"
CREATE TABLE [{schema}].[Employee] (
id INTEGER IDENTITY,
migration.create_table("Schedule", |t| {
t.add_column("id", types::integer().increments(true));
t.add_column("morningEmployeeId", types::integer().nullable(false));
t.add_column("eveningEmployeeId", types::integer().nullable(false));
CONSTRAINT [Employee_pkey] PRIMARY KEY ("id")
);
t.add_foreign_key(&["morningEmployeeId"], "Employee", &["id"]);
t.add_foreign_key(&["eveningEmployeeId"], "Employee", &["id"]);
t.add_constraint("Schedule_pkey", types::primary_constraint(&["id"]))
});
migration.create_table("Unrelated", |t| {
t.add_column("id", types::integer().increments(true));
t.add_constraint("Unrelated_pkey", types::primary_constraint(&["id"]))
});
})
.await?;
CREATE TABLE [{schema}].[Schedule] (
id INTEGER IDENTITY,
[morningEmployeeId] INTEGER,
[eveningEmployeeId] INTEGER,
CONSTRAINT [morning_fkey] FOREIGN KEY ([morningEmployeeId]) REFERENCES [{schema}].[Employee] ("id"),
CONSTRAINT [evening_fkey] FOREIGN KEY ([eveningEmployeeId]) REFERENCES [{schema}].[Employee] ("id"),
CONSTRAINT [Schedule_pkey] PRIMARY KEY ("id")
);
CREATE TABLE [{schema}].[Unrelated] (
id INTEGER IDENTITY,
CONSTRAINT [Unrelated_pkey] PRIMARY KEY ("id")
);
"#,
schema = api.schema_name()
);

api.raw_cmd(&setup).await;

let input_dm = indoc! {r#"
model Employee {
Expand All @@ -52,11 +58,11 @@ async fn multiple_changed_relation_names(api: &TestApi) -> TestResult {
}
model Schedule {
id Int @id @default(autoincrement())
morningEmployeeId Int
eveningEmployeeId Int
Employee_EmployeeToSchedule_eveningEmployeeId Employee @relation("EmployeeToSchedule_eveningEmployeeId", fields: [eveningEmployeeId], references: [id], onUpdate: NoAction)
Employee_EmployeeToSchedule_morningEmployeeId Employee @relation("EmployeeToSchedule_morningEmployeeId", fields: [morningEmployeeId], references: [id], onUpdate: NoAction)
id Int @id @default(autoincrement())
morningEmployeeId Int?
eveningEmployeeId Int?
Employee_EmployeeToSchedule_eveningEmployeeId Employee? @relation("EmployeeToSchedule_eveningEmployeeId", fields: [eveningEmployeeId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "evening_fkey")
Employee_EmployeeToSchedule_morningEmployeeId Employee? @relation("EmployeeToSchedule_morningEmployeeId", fields: [morningEmployeeId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "morning_fkey")
}
model Unrelated {
Expand All @@ -83,8 +89,14 @@ async fn multiple_changed_relation_names_due_to_mapped_models(api: &TestApi) ->
t.add_column("user_id", types::integer().nullable(false));
t.add_column("user_id2", types::integer().nullable(false));

t.add_foreign_key(&["user_id"], "User", &["id"]);
t.add_foreign_key(&["user_id2"], "User", &["id"]);
t.add_constraint(
"post_userid_fk",
types::foreign_constraint(&["user_id"], "User", &["id"], None, None),
);
t.add_constraint(
"post_userid2_fk",
types::foreign_constraint(&["user_id2"], "User", &["id"], None, None),
);
t.add_constraint("Post_pkey", types::primary_constraint(&["id"]));
t.add_constraint("Post_user_id_key", types::unique_constraint(&["user_id"]));
t.add_constraint("Post_user_id2_key", types::unique_constraint(&["user_id2"]));
Expand Down Expand Up @@ -120,8 +132,8 @@ async fn multiple_changed_relation_names_due_to_mapped_models(api: &TestApi) ->
id Int @id @default(autoincrement())
user_id Int @unique
user_id2 Int @unique
custom_User Custom_User @relation("CustomRelationName", fields: [user_id], references: [id], onUpdate: NoAction)
custom_User2 Custom_User @relation("AnotherCustomRelationName", fields: [user_id2], references: [id], onUpdate: NoAction)
custom_User Custom_User @relation("CustomRelationName", fields: [user_id], references: [id], onUpdate: NoAction, map: "post_userid_fk")
custom_User2 Custom_User @relation("AnotherCustomRelationName", fields: [user_id2], references: [id], onUpdate: NoAction, map: "post_userid2_fk")
}
model Custom_User {
Expand Down Expand Up @@ -155,7 +167,10 @@ async fn mapped_model_and_field_name(api: &TestApi) -> TestResult {
t.add_column("id", types::integer().increments(true));
t.add_column("user_id", types::integer().nullable(false));

t.add_foreign_key(&["user_id"], "User", &["id"]);
t.add_constraint(
"Post_fkey",
types::foreign_constraint(&["user_id"], "User", &["id"], None, None),
);
t.add_constraint("Post_pkey", types::primary_constraint(&["id"]))
});

Expand Down Expand Up @@ -185,7 +200,7 @@ async fn mapped_model_and_field_name(api: &TestApi) -> TestResult {
model Post {
id Int @id @default(autoincrement())
c_user_id Int @map("user_id")
Custom_User Custom_User @relation(fields: [c_user_id], references: [c_id], onUpdate: NoAction)
Custom_User Custom_User @relation(fields: [c_user_id], references: [c_id], onUpdate: NoAction, map: "Post_fkey")
}
model Custom_User {
Expand Down
Expand Up @@ -60,8 +60,8 @@ async fn multiple_changed_relation_names(api: &TestApi) -> TestResult {
id Int @id @default(autoincrement())
morningEmployeeId Int
eveningEmployeeId Int
Employee_EmployeeToSchedule_eveningEmployeeId Employee @relation("EmployeeToSchedule_eveningEmployeeId", fields: [eveningEmployeeId], references: [id])
Employee_EmployeeToSchedule_morningEmployeeId Employee @relation("EmployeeToSchedule_morningEmployeeId", fields: [morningEmployeeId], references: [id])
Employee_EmployeeToSchedule_eveningEmployeeId Employee @relation("EmployeeToSchedule_eveningEmployeeId", fields: [eveningEmployeeId], references: [id], map: "eveningEmployeeId")
Employee_EmployeeToSchedule_morningEmployeeId Employee @relation("EmployeeToSchedule_morningEmployeeId", fields: [morningEmployeeId], references: [id], map: "morningEmployeeId")
@@index([eveningEmployeeId], map: "eveningEmployeeId")
@@index([morningEmployeeId], map: "morningEmployeeId")
Expand Down Expand Up @@ -120,7 +120,7 @@ async fn mapped_model_and_field_name(api: &TestApi) -> TestResult {
model Post {
id Int @id @default(autoincrement())
c_user_id Int @map("user_id")
Custom_User Custom_User @relation(fields: [c_user_id], references: [c_id])
Custom_User Custom_User @relation(fields: [c_user_id], references: [c_id], map: "user_id")
@@index([c_user_id], map: "user_id")
}
Expand Down Expand Up @@ -198,8 +198,8 @@ async fn multiple_changed_relation_names_due_to_mapped_models(api: &TestApi) ->
id Int @id @default(autoincrement())
user_id Int @unique(map: "user_id")
user_id2 Int @unique(map: "user_id2")
custom_User Custom_User @relation("CustomRelationName", fields: [user_id], references: [id])
custom_User2 Custom_User @relation("AnotherCustomRelationName", fields: [user_id2], references: [id])
custom_User Custom_User @relation("CustomRelationName", fields: [user_id], references: [id], map: "user_id")
custom_User2 Custom_User @relation("AnotherCustomRelationName", fields: [user_id2], references: [id], map: "user_id2")
}
model Custom_User {
Expand Down

0 comments on commit 587d59c

Please sign in to comment.