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): remove 'SetDefault' support on MySQL #3363

Closed
wants to merge 7 commits into from

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Nov 4, 2022

See the internal document for reference.

Validation message:

Invalid referential action: SetDefault. Allowed values: (Cascade, Restrict, NoAction, SetNull). SetDefault is invalid for MySQL when using relationMode = "foreignKeys", as MySQL does not support the SET DEFAULT referential action.
Learn more at prisma/prisma#11498

TODO:

Contributes to prisma/prisma#11498.

@jkomyno jkomyno added this to the 4.6.0 milestone Nov 4, 2022
@jkomyno jkomyno marked this pull request as ready for review November 4, 2022 16:49
@jkomyno jkomyno requested a review from a team as a code owner November 4, 2022 16:49
let additional_info = match (action, connector.provider_name()) {
(ReferentialAction::SetDefault, "mysql") => Some(formatdoc! {
r#"
. `{set_default}` is invalid for {provider} when using `relationMode = \"foreignKeys\"`, as {provider} does not support the `SET DEFAULT` referential action.
Copy link
Member

Choose a reason for hiding this comment

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

This also happens when not relationMode is set. Can we take that into account in the error message wording?

Also: MySQL docs say it does support it. How can we make this clearer? "... does not actually support properly ..." is probably a bit too salty :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically the complementary of relationMode = "prisma" is indeed relationMode = "foreignKeys". What's your suggestion here? Should I just get rid of the when using... part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Help with the message wording is welcomed :)

Copy link
Member

Choose a reason for hiding this comment

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

No, for the user there is no relationMode at all in use in most cases.

This could work:
"when using" => "(by default or when using relationMode=foreignKeys)"

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should have a specific message for this, it reads like something generic and it should be (at first sight).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about:

Invalid referential action: SetDefault. Allowed values: (Cascade, Restrict, NoAction, SetNull). Starting from Prisma v4.6.0, we disabled SetDefault on MySQL (when using relationMode = "foreignKeys" or when not using referential integrity at all), as MySQL does not natively support the SET DEFAULT referential action. Learn more at ..."

Copy link
Contributor

Choose a reason for hiding this comment

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

that's fine

Copy link
Member

Choose a reason for hiding this comment

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

We should not include version information in error messages.

Copy link
Member

Choose a reason for hiding this comment

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

The second bit of the error message is because we differ from what MySQL supports there @tomhoule. People can have this in their database, and after Introspection they will get this and then get a validation error. This second sentence gives the necessary context to be able to understand and then links to documentation that goes deeper into that.

Copy link
Member

@janpio janpio Nov 7, 2022

Choose a reason for hiding this comment

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

(We'll talk about this in our team sync today)

(ReferentialAction::SetDefault, "mysql") => Some(formatdoc! {
r#"
. `{set_default}` is invalid for {provider} when using `relationMode = \"foreignKeys\"`, as {provider} does not support the `SET DEFAULT` referential action.
Learn more at https://github.com/prisma/prisma/issues/11498
Copy link
Member

Choose a reason for hiding this comment

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

This should already be a pris.ly link that redirects to this URL, so we can fix this later without a release. Jsut create the shortlink by adding to the vercel config file there via a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't ever done that, could you please post here a link to a pris.ly README or something? I'll address that on Monday.

Copy link
Member

Choose a reason for hiding this comment

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

expected_validation.assert_eq(&validation.err().unwrap());

Ok(())
}
Copy link
Contributor

@tomhoule tomhoule Nov 7, 2022

Choose a reason for hiding this comment

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

We've always strived to make introspected output be valid for any existing database, this is a departure.

@@ -151,8 +152,21 @@ pub(super) fn referential_actions(field: RelationFieldWalker<'_>, ctx: &mut Cont
let msg_foreign_keys = |action: ReferentialAction| {
let allowed_actions = connector.referential_actions();

let additional_info = match (action, connector.provider_name()) {
(ReferentialAction::SetDefault, "mysql") => Some(formatdoc! {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to change it now, but for future PRs: we try hard to avoid connector-specific code in the core. This should be in the MySQL connector.

@jkomyno
Copy link
Contributor Author

jkomyno commented Nov 7, 2022

As discussed on Zoom with @janpio, this PR is no longer needed. We'll resort to warnings rather than errors in order to avoid scenarios where users that do not control their database schema (which may incorrectly have SET DEFAULT actions on MySQL) cannot upgrade to newer Prisma versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants