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 mysql8 compatibility #395

Merged
merged 1 commit into from
Sep 8, 2020
Merged

Fix mysql8 compatibility #395

merged 1 commit into from
Sep 8, 2020

Conversation

zhouzhuojie
Copy link
Collaborator

@zhouzhuojie zhouzhuojie commented Sep 5, 2020

Fix mysql8 compatibility by removing the unnecessary "ASC" keyword in preload gorm queries.
The actual root cause is that Rank is a new keyword in mysql8, and we need to safely escape that for MySQL and Postgres.

Tried a few solutions, and the safest is actually remove the "ASC" so that gorm can handle the name escape correctly for mysql and postgres.

Description

Fix #386

Motivation and Context

How Has This Been Tested?

Tested locally for mysql 5.6 and mysql 8+.
Tested in integration tests.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov-commenter
Copy link

Codecov Report

Merging #395 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #395   +/-   ##
=======================================
  Coverage   83.01%   83.01%           
=======================================
  Files          27       27           
  Lines        1755     1755           
=======================================
  Hits         1457     1457           
  Misses        214      214           
  Partials       84       84           
Impacted Files Coverage Δ
pkg/entity/flag.go 95.45% <100.00%> (ø)
pkg/entity/segment.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c7ca05...3c29f43. Read the comment docs.

MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "flagr"
MYSQL_USER: "root"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added integration tests for mysql 5.6 and mysql 8

Preload("Segments", func(db *gorm.DB) *gorm.DB {
return PreloadConstraintsDistribution(db).
Order("rank ASC").
Order("id ASC")
Order("rank").
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"rank ASC" was not escaped correctly in mysql8 due to the new keyword RANK function. Here we can just remove ASC and let gorm handle the field name escape correctly.

@zhouzhuojie zhouzhuojie force-pushed the zz/fix-mysql-compatibility branch from 3c29f43 to 4ad0a8e Compare September 5, 2020 00:58
@zhouzhuojie zhouzhuojie merged commit 8df1f0a into master Sep 8, 2020
@zhouzhuojie zhouzhuojie deleted the zz/fix-mysql-compatibility branch September 8, 2020 16:48
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.

MYSQL image compatibility
3 participants