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

feat(psl): add warning when SetDefault is used on mysql with relationMode = "foreignKeys" #3435

Merged
merged 9 commits into from Nov 24, 2022

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Nov 23, 2022

Context: see internal Notion document

Closes prisma/prisma#16259.

  • test validation
  • test introspection
  • test migration

TODOs (which do not block the PR):

  • agree on the warning message

Warning message:

"""
MySQL does not actually support the SetDefault referential action, so using it may result in unexpected errors. Read more at https://pris.ly/d/mysql-set-default
"""

@@ -240,7 +240,7 @@ pub(crate) fn primary_key_connector_specific(model: ModelWalker<'_>, ctx: &mut C
}

pub(super) fn connector_specific(model: ModelWalker<'_>, ctx: &mut Context<'_>) {
ctx.connector.validate_model(model, ctx.diagnostics)
ctx.connector.validate_model(model, ctx.relation_mode, ctx.diagnostics)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing access to relation_mode in the connectors implementing the Connector trait turned into a bit of diff noise, you can read the discussion happened before the implementation here.

Comment on lines +66 to +75
pub fn warnings_to_pretty_string(&self, file_name: &str, datamodel_string: &str) -> String {
let mut message: Vec<u8> = Vec::new();

for warn in self.warnings() {
warn.pretty_print(&mut message, file_name, datamodel_string)
.expect("printing datamodel warning");
}

String::from_utf8_lossy(&message).into_owned()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to snapshot the warnings in the new introspection-tests tests. At some point in the future, we might as well rename the existing to_pretty_string into errors_to_pretty_string, and create a new to_pretty_string method to be used in validation_tests.rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkomyno jkomyno added this to the 4.7.0 milestone Nov 23, 2022
Comment on lines +109 to +114
format!(
"Using {set_default} on {connector} may yield to unexpected results, as the database will silently change the referential action to `{no_action}`.",
set_default = ReferentialAction::SetDefault.as_str(),
connector = connector.name(),
no_action = ReferentialAction::NoAction.as_str(),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's agree on the actual message to show the users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could link to https://pris.ly/d/referential-actions?

@Jolg42 Jolg42 marked this pull request as ready for review November 24, 2022 11:18
@Jolg42 Jolg42 requested a review from a team as a code owner November 24, 2022 11:18
Copy link
Contributor

@pimeys pimeys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. A small nitpick, so maybe do that and I'm fine with the PR.

@jkomyno jkomyno requested a review from pimeys November 24, 2022 15:18
@jkomyno jkomyno merged commit b56b159 into main Nov 24, 2022
@jkomyno jkomyno deleted the feat/add-set-default-warning-on-mysql branch November 24, 2022 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants