Added objectID position tracking. When the template is generated the ordering of conflicting unique columns is alphabetical. This means we cannot assume the objectID can always be appended. It might need to be inserted at a specific position. This adds support for tracking the position and inserting it at the correct position so the delete query correctly deletes the conflicts.
This commit is contained in:
parent
6b4e052bed
commit
ac3623bb52
1 changed files with 11 additions and 2 deletions
|
@ -82,7 +82,12 @@ func deleteOneToOneConflictsBeforeMerge(tx boil.Executor, conflict conflictingUn
|
|||
|
||||
func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingUniqueKey, primaryID uint64, secondaryID uint64) error {
|
||||
conflictingColumns := strmangle.SetComplement(conflict.columns, []string{conflict.objectIdColumn})
|
||||
|
||||
var objectIDIndex int
|
||||
for i, column := range conflict.columns {
|
||||
if column == conflict.objectIdColumn {
|
||||
objectIDIndex = i
|
||||
}
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"SELECT %s FROM %s WHERE %s IN (%s) GROUP BY %s HAVING count(distinct %s) > 1",
|
||||
strings.Join(conflictingColumns, ","), conflict.table, conflict.objectIdColumn,
|
||||
|
@ -137,7 +142,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
|
||||
// keys to be deleted here in a loop.
|
||||
for _, rowToDelete := range rowsToRemove {
|
||||
rowToDelete = append(rowToDelete, secondaryID)
|
||||
rowToDelete = insert(rowToDelete, objectIDIndex, secondaryID)
|
||||
_, err = tx.Exec(query, rowToDelete...)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
|
@ -146,6 +151,10 @@ func deleteOneToManyConflictsBeforeMerge(tx boil.Executor, conflict conflictingU
|
|||
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 {
|
||||
uniqueColumns := []interface{}{}
|
||||
uniqueColumnNames := map[string]bool{}
|
||||
|
|
Loading…
Add table
Reference in a new issue