-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Mysql8 rename table #796
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
Open
raidivyansh074
wants to merge
5
commits into
abort-missing-backend-tables
Choose a base branch
from
mysql8-rename-table
base: abort-missing-backend-tables
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mysql8 rename table #796
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ package mysql | |
import ( | ||
gosql "database/sql" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
@@ -203,3 +204,47 @@ func GetTableColumns(db *gosql.DB, databaseName, tableName string) (*sql.ColumnL | |
} | ||
return sql.NewColumnList(columnNames), sql.NewColumnList(virtualColumnNames), nil | ||
} | ||
|
||
func versionTokens(version string, digits int) []int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @raidivyansh074 I suggest we use https://github.com/hashicorp/go-version for this instead so there is less code to maintain into the future |
||
v := strings.Split(version, "-")[0] | ||
tokens := strings.Split(v, ".") | ||
intTokens := make([]int, digits) | ||
for i := range tokens { | ||
if i >= digits { | ||
break | ||
} | ||
intTokens[i], _ = strconv.Atoi(tokens[i]) | ||
} | ||
return intTokens | ||
} | ||
|
||
func isSmallerVersion(version string, otherVersion string, digits int) bool { | ||
v := versionTokens(version, digits) | ||
o := versionTokens(otherVersion, digits) | ||
for i := 0; i < len(v); i++ { | ||
if v[i] < o[i] { | ||
return true | ||
} | ||
if v[i] > o[i] { | ||
return false | ||
} | ||
if i == digits { | ||
break | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// IsSmallerMajorVersion tests two versions against another and returns true if | ||
// the former is a smaller "major" varsion than the latter. | ||
// e.g. 5.5.36 is NOT a smaller major version as comapred to 5.5.40, but IS as compared to 5.6.9 | ||
func IsSmallerMajorVersion(version string, otherVersion string) bool { | ||
return isSmallerVersion(version, otherVersion, 2) | ||
} | ||
|
||
// IsSmallerMinorVersion tests two versions against another and returns true if | ||
// the former is a smaller "minor" varsion than the latter. | ||
// e.g. 5.5.36 is a smaller major version as comapred to 5.5.40, as well as compared to 5.6.7 | ||
func IsSmallerMinorVersion(version string, otherVersion string) bool { | ||
return isSmallerVersion(version, otherVersion, 3) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2016 GitHub Inc. | ||
See https://github.com/github/gh-ost/blob/master/LICENSE | ||
*/ | ||
|
||
package mysql | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/outbrain/golib/log" | ||
test "github.com/outbrain/golib/tests" | ||
) | ||
|
||
func init() { | ||
log.SetLevel(log.ERROR) | ||
} | ||
|
||
func TestVersionTokens(t *testing.T) { | ||
test.S(t).ExpectTrue(reflect.DeepEqual(versionTokens("5.7.24-log", 3), []int{5, 7, 24})) | ||
test.S(t).ExpectTrue(reflect.DeepEqual(versionTokens("8.0.13", 3), []int{8, 0, 13})) | ||
test.S(t).ExpectTrue(reflect.DeepEqual(versionTokens("5.5", 2), []int{5, 5})) | ||
test.S(t).ExpectTrue(reflect.DeepEqual(versionTokens("5.5", 3), []int{5, 5, 0})) | ||
test.S(t).ExpectTrue(reflect.DeepEqual(versionTokens("5.5-log", 3), []int{5, 5, 0})) | ||
} | ||
|
||
func TestIsSmallerMajorVersion(t *testing.T) { | ||
i55 := "5.5" | ||
i5516 := "5.5.16" | ||
i5517 := "5.5.17" | ||
i56 := "5.6" | ||
i8013 := "8.0.13" | ||
|
||
test.S(t).ExpectFalse(IsSmallerMajorVersion(i55, i5517)) | ||
test.S(t).ExpectFalse(IsSmallerMajorVersion(i5516, i5517)) | ||
test.S(t).ExpectFalse(IsSmallerMajorVersion(i56, i5517)) | ||
test.S(t).ExpectTrue(IsSmallerMajorVersion(i55, i56)) | ||
test.S(t).ExpectTrue(IsSmallerMajorVersion(i56, i8013)) | ||
test.S(t).ExpectFalse(IsSmallerMajorVersion(i8013, i56)) | ||
} | ||
|
||
func TestIsSmallerMinorVersion(t *testing.T) { | ||
i55 := "5.5" | ||
i5516 := "5.5.16" | ||
i5517 := "5.5.17" | ||
i56 := "5.6" | ||
i8013 := "8.0.13" | ||
|
||
test.S(t).ExpectTrue(IsSmallerMinorVersion(i55, i5517)) | ||
test.S(t).ExpectTrue(IsSmallerMinorVersion(i5516, i5517)) | ||
test.S(t).ExpectFalse(IsSmallerMinorVersion(i56, i5517)) | ||
test.S(t).ExpectTrue(IsSmallerMinorVersion(i55, i56)) | ||
test.S(t).ExpectTrue(IsSmallerMinorVersion(i56, i8013)) | ||
test.S(t).ExpectFalse(IsSmallerMinorVersion(i8013, i56)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@raidivyansh074 let's allow the user to decide if they want this style of cut-over, at least for now
Could you please add a new cut-over type the command line here and here
The check for
mysql.IsSmallerMinorVersion
could move to be a check at the start of the new cut-over type only