Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Ensure analyzer tasks created prior to upgrade have kind assigned. #674

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/add/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ curl -X POST ${host}/tasks -d \
'{
"name":"Test",
"locator": "app.1.test",
"addon": "test",
"addon": "analyzer",
"application": {"id": 1},
"data": {
"path": "/etc"
Expand Down
37 changes: 36 additions & 1 deletion migration/v14/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ func (r Migration) Apply(db *gorm.DB) (err error) {
if err != nil {
return
}
// add mvn:// prefix.
err = r.mavenPrefix(db)
if err != nil {
return
}
err = r.taskKind(db)
if err != nil {
return
}
return
}

// mavenPrefix ensures the Application.Binary which are maven
// coordinates have the mvn:// prefix added in 0.5.
func (r Migration) mavenPrefix(db *gorm.DB) (err error) {
prefix := "mvn://"
var list []*model.Application
err = db.Find(&list).Error
Expand All @@ -37,6 +50,28 @@ func (r Migration) Apply(db *gorm.DB) (err error) {
return
}

// taskKind ensures tasks have a kind.
// In 0.5 task (kinds) added. A task named `analyzer` is
// installed by the operator.
func (r Migration) taskKind(db *gorm.DB) (err error) {
kind := "analyzer"
var list []*model.Task
err = db.Find(&list).Error
if err != nil {
return
}
for _, m := range list {
if m.Addon == kind && m.Kind == "" {
m.Kind = kind
}
err = db.Save(m).Error
if err != nil {
return
}
}
return
}

func (r Migration) Models() []any {
return model.All()
}
Loading