Fix Column Order Bug #5

Open
tiger5226 wants to merge 2 commits from fix_column_order_bug into master

View file

@ -82,7 +82,13 @@ func deleteOneToOneConflictsBeforeMerge(tx boil.Executor, conflict conflictingUn
func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingUniqueKey, primaryID uint64, secondaryID uint64) error { func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingUniqueKey, primaryID uint64, secondaryID uint64) error {
conflictingColumns := strmangle.SetComplement(conflict.columns, []string{conflict.objectIdColumn}) conflictingColumns := strmangle.SetComplement(conflict.columns, []string{conflict.objectIdColumn})
var objectIDIndex int
for i, column := range conflict.columns {
if column == conflict.objectIdColumn {
objectIDIndex = i
break
lyoshenka commented 2019-06-12 16:24:21 +02:00 (Migrated from github.com)
Review

you can break after this

you can `break` after this
tiger5226 commented 2019-06-13 05:26:03 +02:00 (Migrated from github.com)
Review

woops..I thought I did that...like literally was thinking it and never added it lol.

woops..I thought I did that...like literally was thinking it and never added it lol.
}
}
query := fmt.Sprintf( query := fmt.Sprintf(
"SELECT %s FROM %s WHERE %s IN (%s) GROUP BY %s HAVING count(distinct %s) > 1", "SELECT %s FROM %s WHERE %s IN (%s) GROUP BY %s HAVING count(distinct %s) > 1",
strings.Join(conflictingColumns, ","), conflict.table, conflict.objectIdColumn, strings.Join(conflictingColumns, ","), conflict.table, conflict.objectIdColumn,
@ -137,7 +143,7 @@ func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingU
//There could be multiple conflicting rows between ObjectIDs. In the SELECT query we grab each row and their column //There could be multiple conflicting rows between ObjectIDs. In the SELECT query we grab each row and their column
// keys to be deleted here in a loop. // keys to be deleted here in a loop.
for _, rowToDelete := range rowsToRemove { for _, rowToDelete := range rowsToRemove {
rowToDelete = append(rowToDelete, secondaryID) rowToDelete = insert(rowToDelete, objectIDIndex, secondaryID)
_, err = tx.Exec(query, rowToDelete...) _, err = tx.Exec(query, rowToDelete...)
if err != nil { if err != nil {
return errors.Err(err) return errors.Err(err)
@ -146,6 +152,10 @@ func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingU
return nil return nil
} }
func insert(slice []interface{}, index int, value interface{}) []interface{} {
return append(slice[:index], append([]interface{}{value}, slice[index:]...)...)
}
func checkMerge(tx boil.Executor, foreignKeys []foreignKey) error { func checkMerge(tx boil.Executor, foreignKeys []foreignKey) error {
uniqueColumns := []interface{}{} uniqueColumns := []interface{}{}
uniqueColumnNames := map[string]bool{} uniqueColumnNames := map[string]bool{}