Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make foreign key fields cascade on delete by default #560

Merged
merged 1 commit into from Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -269,7 +269,7 @@ impl<'a> SqlSchemaCalculator<'a> {
.map(|referenced_field| referenced_field.db_name().to_owned())
.collect(),
on_delete_action: match column_arity(field.arity()) {
ColumnArity::Required => sql::ForeignKeyAction::Restrict,
ColumnArity::Required => sql::ForeignKeyAction::Cascade,
_ => sql::ForeignKeyAction::SetNull,
},
};
Expand Down
18 changes: 9 additions & 9 deletions migration-engine/migration-engine-tests/tests/migration_tests.rs
Expand Up @@ -243,7 +243,7 @@ async fn changing_the_type_of_an_id_field_must_work(api: &TestApi) {
columns: vec![column.name.clone()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);

Expand Down Expand Up @@ -271,7 +271,7 @@ async fn changing_the_type_of_an_id_field_must_work(api: &TestApi) {
columns: vec![column.name.clone()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ async fn changing_a_relation_field_to_a_scalar_field_must_work(api: &TestApi) ->
columns: vec!["b".to_owned()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
})
})?;

Expand Down Expand Up @@ -395,7 +395,7 @@ async fn changing_a_scalar_field_to_a_relation_field_must_work(api: &TestApi) {
columns: vec![column.name.clone()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);
}
Expand Down Expand Up @@ -573,7 +573,7 @@ async fn adding_an_inline_relation_must_result_in_a_foreign_key_in_the_model_tab
columns: vec![b_column.name.clone()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict, // required relations can't set ON DELETE SET NULL
on_delete_action: ForeignKeyAction::Cascade, // required relations can't set ON DELETE SET NULL
},
ForeignKey {
constraint_name: match api.sql_family() {
Expand Down Expand Up @@ -617,7 +617,7 @@ async fn specifying_a_db_name_for_an_inline_relation_must_work(api: &TestApi) {
columns: vec![column.name.clone()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);
}
Expand Down Expand Up @@ -649,7 +649,7 @@ async fn adding_an_inline_relation_to_a_model_with_an_exotic_id_type(api: &TestA
columns: vec![column.name.clone()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);
}
Expand Down Expand Up @@ -718,7 +718,7 @@ async fn moving_an_inline_relation_to_the_other_side_must_work(api: &TestApi) ->
columns: vec!["b".to_string()],
referenced_table: "B".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);

Expand All @@ -745,7 +745,7 @@ async fn moving_an_inline_relation_to_the_other_side_must_work(api: &TestApi) ->
columns: vec!["a".to_string()],
referenced_table: "A".to_string(),
referenced_columns: vec!["id".to_string()],
on_delete_action: ForeignKeyAction::Restrict,
on_delete_action: ForeignKeyAction::Cascade,
}]
);

Expand Down