refactor root update in merge.go

This commit is contained in:
Andy Arthur
2021-02-28 11:55:31 -08:00
parent fc3ee80ef4
commit c988f62b26

View File

@@ -763,7 +763,6 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
tableEditSession := editor.CreateTableEditSession(ourRoot, editor.TableEditSessionProps{
ForeignKeyChecksDisabled: true,
})
var unconflicted []string
// need to validate merges can be done on all tables before starting the actual merges.
for _, tblName := range tblNames {
mergedTable, stats, err := merger.MergeTable(ctx, tblName, tableEditSession)
@@ -775,10 +774,6 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
if mergedTable != nil {
tblToStats[tblName] = stats
if stats.Conflicts == 0 {
unconflicted = append(unconflicted, tblName)
}
err = tableEditSession.UpdateRoot(ctx, func(ctx context.Context, root *doltdb.RootValue) (*doltdb.RootValue, error) {
return root.PutTable(ctx, tblName, mergedTable)
})
@@ -813,10 +808,14 @@ func MergeRoots(ctx context.Context, ourRoot, theirRoot, ancRoot *doltdb.RootVal
if len(conflicts) > 0 {
return nil, fmt.Errorf("foreign key conflicts")
}
return root.PutForeignKeyCollection(ctx, mergedFKColl)
})
newRoot, err = newRoot.UpdateSuperSchemasFromOther(ctx, unconflicted, theirRoot)
root, err = root.PutForeignKeyCollection(ctx, mergedFKColl)
if err != nil {
return nil, err
}
return root.UpdateSuperSchemasFromOther(ctx, tblNames, theirRoot)
})
if err != nil {
return nil, nil, err
}