Skip to content

Commit

Permalink
WIP - Fix second issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Sep 26, 2024
1 parent c5ce8d0 commit 7ab2666
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/db/definition_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func validateSingleSidePrimary(
}

for _, field := range definition.GetFields() {
if !field.Kind.IsObject() {
if field.Kind == nil || !field.Kind.IsObject() {
continue
}

Expand Down
25 changes: 19 additions & 6 deletions internal/db/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7ab2666

Please sign in to comment.