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

Fix anomalies in migration of integer columns in MySQL 8 (#1358) #1360

Merged
merged 5 commits into from
Mar 11, 2022

Conversation

paul-rouse
Copy link
Contributor

@paul-rouse paul-rouse commented Feb 9, 2022

Fixes #1358. I believe this remains compatible with older versions of MySQL, so should be a minor version bump.

Before submitting your PR, check that you've:

  • Ran stylish-haskell on any changed files.
  • Adhered to the code style (see the .editorconfig file for details)

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Bumped the version number if there isn't an (unreleased) on the Changelog
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

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

A few questions but otherwise looks great, thank you!

Comment on lines 1026 to 1031
-- The non-default display width "(1)" is kept for now to avoid differences
-- between persistent versions running against older MySQL versions (eg 5.7):
showSqlType SqlBool _ _ = "TINYINT(1)"
showSqlType SqlDay _ _ = "DATE"
showSqlType SqlDayTime _ _ = "DATETIME"
showSqlType SqlInt32 _ _ = "INT(11)"
showSqlType SqlInt32 _ _ = "INT"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment doesn't appear to agree with the code change - can you clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a great comment - I'll add a commit to try to improve it! The point is I'm trying to avoid changing anything about what is put into the information schema in MySQL 5.7 and early members of the 8.X series. In 5.7, INT gets a default display width (11) anyway, so I felt it would be clearer in the future to omit it here (as was already done for BIGINT). However (1) is not the default for TINYINT, and omitting it would make MySQL 5.7 add (4) instead in the information schema. It doesn't affect the data storage for the column itself, of course, but the different information schema might cause spurious migrations in persistent, or be incompatible with some external program the user might depend upon.

Comment on lines +836 to +841
parseColumnType "tinyint" ci
| ciColumnType ci == "tinyint" || ciColumnType ci == "tinyint(1)" = return (SqlBool, Nothing)
parseColumnType "int" ci
| ciColumnType ci == "int" || ciColumnType ci == "int(11)" = return (SqlInt32, Nothing)
parseColumnType "bigint" ci
| ciColumnType ci == "bigint" || ciColumnType ci == "bigint(20)" = return (SqlInt64, Nothing)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it maybe make sense to do a Just _ <- Text.stripPrefix "tinyint" pattern? That would match tinyint, tinyint(1), and tinyint(2345) etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, I am trying to avoid changing anything for MySQL 5.7 and early 8.X. These versions will always report the display width, so I thought it best to match it exactly, as before, to avoid including cases which were not included in persistent-mysql-2.13.1.0. The addition is the matching of the bare type, eg int, which will only be reported by later 8.X versions

@paul-rouse
Copy link
Contributor Author

@parsonsmatt I will add a commit to improve the comment in the code, but would you like me to merge and release then? I tend to leave things persistent to you, but quite happy to do this.

@paul-rouse
Copy link
Contributor Author

I've got this one - just remembered it's sitting around.

@paul-rouse paul-rouse merged commit ccc66c6 into yesodweb:master Mar 11, 2022
@paul-rouse paul-rouse deleted the mysql-int-width branch March 11, 2022 09:13
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.

Repeated migrations of an Int32 column in MySQL 8
2 participants