diff --git a/internal/db/schema.go b/internal/db/schema.go index 391d5e515a..f1906feb54 100644 --- a/internal/db/schema.go +++ b/internal/db/schema.go @@ -376,11 +376,6 @@ func (db *db) updateSchema( return err } - oldDefs := make([]client.CollectionDefinition, 0, len(allExistingCols)) - for _, col := range allExistingCols { - oldDefs = append(oldDefs, col.Definition()) - } - for _, schema := range proposedDescriptionsByName { previousSchema := existingSchemaByName[schema.Name] @@ -498,7 +493,25 @@ func (db *db) updateSchema( return err } - err = db.validateSchemaUpdate(ctx, oldDefs, definitions) + oldDefs := make([]client.CollectionDefinition, 0, len(allExistingCols)) + for _, col := range allExistingCols { + oldDefs = append(oldDefs, col.Definition()) + } + + defNames := make(map[string]struct{}, len(definitions)) + for _, def := range definitions { + defNames[def.GetName()] = struct{}{} + } + + newDefs := make([]client.CollectionDefinition, 0, len(definitions)) + newDefs = append(newDefs, definitions...) + for _, existing := range allExistingCols { + if _, ok := defNames[existing.Definition().GetName()]; !ok { + newDefs = append(newDefs, existing.Definition()) + } + } + + err = db.validateSchemaUpdate(ctx, oldDefs, newDefs) if err != nil { return err }