Skip to content

Commit

Permalink
fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
yk-eukarya committed Mar 6, 2024
1 parent 7734417 commit 5767ed6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/cmd/db-migrations/ref_field_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type TypeProperty struct {
}

type Reference struct {
Model string `bson:"model"`
Schema string `bson:"schema"`
Model string `bson:"model"`
Schema string `bson:"schema"`
CorrespondingSchema *string `bson:"correspondingschema"`
}

func (r *Reference) SetSchema(s string) {
Expand Down Expand Up @@ -86,10 +87,15 @@ func RefFieldSchema(ctx context.Context, dbURL, dbName string, wetRun bool) erro
return
}

Check warning on line 88 in server/cmd/db-migrations/ref_field_schema.go

View check run for this annotation

Codecov / codecov/patch

server/cmd/db-migrations/ref_field_schema.go#L87-L88

Added lines #L87 - L88 were not covered by tests
m, ok := models[f.TypeProperty.Reference.Model]
if !ok {
fmt.Printf("no model found for schema '%s' model id '%s'\n", s.ID, f.TypeProperty.Reference.Model)
if ok {
f.TypeProperty.Reference.SetSchema(m.Schema)
return
}
if f.TypeProperty.Reference.CorrespondingSchema != nil {
f.TypeProperty.Reference.SetSchema(*f.TypeProperty.Reference.CorrespondingSchema)
return
}
f.TypeProperty.Reference.SetSchema(m.Schema)
fmt.Printf("no model found for schema '%s' model id '%s'\n", s.ID, f.TypeProperty.Reference.Model)

Check warning on line 98 in server/cmd/db-migrations/ref_field_schema.go

View check run for this annotation

Codecov / codecov/patch

server/cmd/db-migrations/ref_field_schema.go#L94-L98

Added lines #L94 - L98 were not covered by tests
})
})

Expand All @@ -99,6 +105,7 @@ func RefFieldSchema(ctx context.Context, dbURL, dbName string, wetRun bool) erro
if f.TypeProperty.Type != "reference" {
return nil, false
}

Check warning on line 107 in server/cmd/db-migrations/ref_field_schema.go

View check run for this annotation

Codecov / codecov/patch

server/cmd/db-migrations/ref_field_schema.go#L106-L107

Added lines #L106 - L107 were not covered by tests
fmt.Printf("updating schema '%s' field '%s' referenced schema '%s'\n", s.ID, f.ID, f.TypeProperty.Reference.Schema)
return mongo.NewUpdateOneModel().
SetFilter(bson.M{
"id": s.ID,
Expand Down

0 comments on commit 5767ed6

Please sign in to comment.