Skip to content

Commit

Permalink
Dont duplicate expression module references in migration tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Nemere committed Oct 3, 2023
1 parent d89b7af commit 78ef37a
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions internal/cmd-line-tools/v3-importer/expressionsDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,24 @@ func migrateExpressionsDBExpressions(src *mongo.Database, dest *mongo.Database,
tags = []string{}
}

// Added duplicate module checks because it appeared there's a bug in data, but turns out this importer was appending the list twice!
// Left the checking code just in case but it shouldn't happen...
refs := []*protos.ModuleReference{}
existingRefs := map[string]bool{}
existingRefModules := map[string]bool{}
if expr.ModuleReferences != nil {
for _, ref := range expr.ModuleReferences {
refstr := ref.ModuleID + "_" + ref.Version
if _, exists := existingRefs[refstr]; exists {
fmt.Printf(" IGNORING duplicate module+version reference: %v on expression %v\n", refstr, expr.ID)
continue
}

if _, exists := existingRefModules[ref.ModuleID]; exists {
fmt.Printf(" IGNORING duplicate module reference: %v on expression %v\n", ref.ModuleID, expr.ID)
continue
}

ver, err := semanticversion.SemanticVersionFromString(ref.Version)
if err != nil {
return err
Expand All @@ -154,6 +169,8 @@ func migrateExpressionsDBExpressions(src *mongo.Database, dest *mongo.Database,
ModuleId: ref.ModuleID,
Version: ver,
})
existingRefs[refstr] = true
existingRefModules[ref.ModuleID] = true
}
}

Expand Down Expand Up @@ -188,18 +205,6 @@ func migrateExpressionsDBExpressions(src *mongo.Database, dest *mongo.Database,
}
}

for _, modRef := range expr.ModuleReferences {
ver, err := semanticversion.SemanticVersionFromString(modRef.Version)
if err != nil {
return err
}

destExpr.ModuleReferences = append(destExpr.ModuleReferences, &protos.ModuleReference{
ModuleId: modRef.ModuleID,
Version: ver,
})
}

// TODO: zenodo

destExprs = append(destExprs, destExpr)
Expand Down

0 comments on commit 78ef37a

Please sign in to comment.