Merge pull request #183 from github/fix-rename-insert

fix INSERT DML handling on renamed column
This commit is contained in:
Shlomi Noach 2016-08-23 07:17:22 +02:00 committed by GitHub
commit 0228498b70
4 changed files with 17 additions and 17 deletions

View File

@ -2,7 +2,7 @@
# #
# #
RELEASE_VERSION="1.0.12" RELEASE_VERSION="1.0.13"
function build { function build {
osname=$1 osname=$1

View File

@ -832,7 +832,7 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (query
} }
case binlog.InsertDML: case binlog.InsertDML:
{ {
query, sharedArgs, err := sql.BuildDMLInsertQuery(dmlEvent.DatabaseName, this.migrationContext.GetGhostTableName(), this.migrationContext.OriginalTableColumns, this.migrationContext.MappedSharedColumns, dmlEvent.NewColumnValues.AbstractValues()) query, sharedArgs, err := sql.BuildDMLInsertQuery(dmlEvent.DatabaseName, this.migrationContext.GetGhostTableName(), this.migrationContext.OriginalTableColumns, this.migrationContext.SharedColumns, this.migrationContext.MappedSharedColumns, dmlEvent.NewColumnValues.AbstractValues())
return query, sharedArgs, 1, err return query, sharedArgs, 1, err
} }
case binlog.UpdateDML: case binlog.UpdateDML:

View File

@ -354,7 +354,7 @@ func BuildDMLDeleteQuery(databaseName, tableName string, tableColumns, uniqueKey
return result, uniqueKeyArgs, nil return result, uniqueKeyArgs, nil
} }
func BuildDMLInsertQuery(databaseName, tableName string, tableColumns, sharedColumns *ColumnList, args []interface{}) (result string, sharedArgs []interface{}, err error) { func BuildDMLInsertQuery(databaseName, tableName string, tableColumns, sharedColumns, mappedSharedColumns *ColumnList, args []interface{}) (result string, sharedArgs []interface{}, err error) {
if len(args) != tableColumns.Len() { if len(args) != tableColumns.Len() {
return result, args, fmt.Errorf("args count differs from table column count in BuildDMLInsertQuery") return result, args, fmt.Errorf("args count differs from table column count in BuildDMLInsertQuery")
} }
@ -367,17 +367,17 @@ func BuildDMLInsertQuery(databaseName, tableName string, tableColumns, sharedCol
databaseName = EscapeName(databaseName) databaseName = EscapeName(databaseName)
tableName = EscapeName(tableName) tableName = EscapeName(tableName)
for _, column := range sharedColumns.Names { for _, column := range mappedSharedColumns.Names {
tableOrdinal := tableColumns.Ordinals[column] tableOrdinal := tableColumns.Ordinals[column]
arg := fixArgType(args[tableOrdinal], sharedColumns.IsUnsigned(column)) arg := fixArgType(args[tableOrdinal], mappedSharedColumns.IsUnsigned(column))
sharedArgs = append(sharedArgs, arg) sharedArgs = append(sharedArgs, arg)
} }
sharedColumnNames := duplicateNames(sharedColumns.Names) mappedSharedColumnNames := duplicateNames(mappedSharedColumns.Names)
for i := range sharedColumnNames { for i := range mappedSharedColumnNames {
sharedColumnNames[i] = EscapeName(sharedColumnNames[i]) mappedSharedColumnNames[i] = EscapeName(mappedSharedColumnNames[i])
} }
preparedValues := buildPreparedValues(sharedColumns.Len()) preparedValues := buildPreparedValues(mappedSharedColumns.Len())
result = fmt.Sprintf(` result = fmt.Sprintf(`
replace /* gh-ost %s.%s */ into replace /* gh-ost %s.%s */ into
@ -387,7 +387,7 @@ func BuildDMLInsertQuery(databaseName, tableName string, tableColumns, sharedCol
(%s) (%s)
`, databaseName, tableName, `, databaseName, tableName,
databaseName, tableName, databaseName, tableName,
strings.Join(sharedColumnNames, ", "), strings.Join(mappedSharedColumnNames, ", "),
strings.Join(preparedValues, ", "), strings.Join(preparedValues, ", "),
) )
return result, sharedArgs, nil return result, sharedArgs, nil

View File

@ -442,7 +442,7 @@ func TestBuildDMLInsertQuery(t *testing.T) {
args := []interface{}{3, "testname", "first", 17, 23} args := []interface{}{3, "testname", "first", 17, 23}
{ {
sharedColumns := NewColumnList([]string{"id", "name", "position", "age"}) sharedColumns := NewColumnList([]string{"id", "name", "position", "age"})
query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNil(err) test.S(t).ExpectNil(err)
expected := ` expected := `
replace /* gh-ost mydb.tbl */ replace /* gh-ost mydb.tbl */
@ -456,7 +456,7 @@ func TestBuildDMLInsertQuery(t *testing.T) {
} }
{ {
sharedColumns := NewColumnList([]string{"position", "name", "age", "id"}) sharedColumns := NewColumnList([]string{"position", "name", "age", "id"})
query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNil(err) test.S(t).ExpectNil(err)
expected := ` expected := `
replace /* gh-ost mydb.tbl */ replace /* gh-ost mydb.tbl */
@ -470,12 +470,12 @@ func TestBuildDMLInsertQuery(t *testing.T) {
} }
{ {
sharedColumns := NewColumnList([]string{"position", "name", "surprise", "id"}) sharedColumns := NewColumnList([]string{"position", "name", "surprise", "id"})
_, _, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) _, _, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNotNil(err) test.S(t).ExpectNotNil(err)
} }
{ {
sharedColumns := NewColumnList([]string{}) sharedColumns := NewColumnList([]string{})
_, _, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) _, _, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNotNil(err) test.S(t).ExpectNotNil(err)
} }
} }
@ -489,7 +489,7 @@ func TestBuildDMLInsertQuerySignedUnsigned(t *testing.T) {
// testing signed // testing signed
args := []interface{}{3, "testname", "first", int8(-1), 23} args := []interface{}{3, "testname", "first", int8(-1), 23}
sharedColumns := NewColumnList([]string{"id", "name", "position", "age"}) sharedColumns := NewColumnList([]string{"id", "name", "position", "age"})
query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNil(err) test.S(t).ExpectNil(err)
expected := ` expected := `
replace /* gh-ost mydb.tbl */ replace /* gh-ost mydb.tbl */
@ -505,7 +505,7 @@ func TestBuildDMLInsertQuerySignedUnsigned(t *testing.T) {
// testing unsigned // testing unsigned
args := []interface{}{3, "testname", "first", int8(-1), 23} args := []interface{}{3, "testname", "first", int8(-1), 23}
sharedColumns.SetUnsigned("position") sharedColumns.SetUnsigned("position")
query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNil(err) test.S(t).ExpectNil(err)
expected := ` expected := `
replace /* gh-ost mydb.tbl */ replace /* gh-ost mydb.tbl */
@ -521,7 +521,7 @@ func TestBuildDMLInsertQuerySignedUnsigned(t *testing.T) {
// testing unsigned // testing unsigned
args := []interface{}{3, "testname", "first", int32(-1), 23} args := []interface{}{3, "testname", "first", int32(-1), 23}
sharedColumns.SetUnsigned("position") sharedColumns.SetUnsigned("position")
query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, args) query, sharedArgs, err := BuildDMLInsertQuery(databaseName, tableName, tableColumns, sharedColumns, sharedColumns, args)
test.S(t).ExpectNil(err) test.S(t).ExpectNil(err)
expected := ` expected := `
replace /* gh-ost mydb.tbl */ replace /* gh-ost mydb.tbl */