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
Conversation
@@ -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) |
There was a problem hiding this comment.
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.
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() | ||
} |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will also be useful for https://github.com/prisma/prisma-private/issues/198
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(), | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
psl/builtin-connectors/src/mysql_datamodel_connector/validations.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
Context: see internal Notion document
Closes prisma/prisma#16259.
TODOs (which do not block the PR):
Warning message:
"""
MySQL
does not actually support theSetDefault
referential action, so using it may result in unexpected errors. Read more at https://pris.ly/d/mysql-set-default"""