-
Notifications
You must be signed in to change notification settings - Fork 432
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
fix(api): fix hooks with empty UUID #5098
Merged
+81
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,3 +135,80 @@ func cleanDuplicateHooks(ctx context.Context, db *gorp.DbMap, store cache.Store, | |
|
||
return nil | ||
} | ||
|
||
func FixEmptyUUIDHooks(ctx context.Context, db *gorp.DbMap, store cache.Store) error { | ||
q := "select distinct(workflow.id) from w_node_hook join w_node on w_node.id = w_node_hook.node_id join workflow on workflow.id = w_node.workflow_id where uuid = ''" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. request must check workflow_data->node->hooks uuid that is the right data |
||
var ids []int64 | ||
|
||
if _, err := db.Select(&ids, q); err != nil { | ||
return sdk.WrapError(err, "unable to select workflow") | ||
} | ||
|
||
var mError = new(sdk.MultiError) | ||
for _, id := range ids { | ||
if err := fixEmptyUUIDHooks(ctx, db, store, id); err != nil { | ||
mError.Append(err) | ||
log.Error(ctx, "migrate.FixEmptyUUIDHooks> unable to clean workflow %d: %v", id, err) | ||
} | ||
} | ||
|
||
if mError.IsEmpty() { | ||
return nil | ||
} | ||
return mError | ||
} | ||
|
||
func fixEmptyUUIDHooks(ctx context.Context, db *gorp.DbMap, store cache.Store, workflowID int64) error { | ||
tx, err := db.Begin() | ||
if err != nil { | ||
return sdk.WithStack(err) | ||
} | ||
|
||
defer tx.Rollback() // nolint | ||
|
||
projectID, err := tx.SelectInt("SELECT project_id FROM workflow WHERE id = $1", workflowID) | ||
if err != nil { | ||
if err == sql.ErrNoRows { | ||
return nil | ||
} | ||
return sdk.WithStack(err) | ||
} | ||
|
||
if projectID == 0 { | ||
return nil | ||
} | ||
|
||
proj, err := project.LoadByID(tx, store, projectID, | ||
project.LoadOptions.WithApplicationWithDeploymentStrategies, | ||
project.LoadOptions.WithPipelines, | ||
project.LoadOptions.WithEnvironments, | ||
project.LoadOptions.WithIntegrations) | ||
if err != nil { | ||
return sdk.WrapError(err, "unable to load project %d", projectID) | ||
} | ||
|
||
w, err := workflow.LoadAndLockByID(ctx, tx, store, *proj, workflowID, workflow.LoadOptions{}) | ||
if err != nil { | ||
if sdk.ErrorIs(err, sdk.ErrNotFound) { | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
for i, h := range w.WorkflowData.Node.Hooks { | ||
if h.UUID == "" { | ||
w.WorkflowData.Node.Hooks[i].UUID = sdk.UUID() | ||
} | ||
} | ||
|
||
if err := workflow.Update(ctx, tx, store, *proj, w, workflow.UpdateOptions{}); err != nil { | ||
return err | ||
} | ||
|
||
if err := tx.Commit(); err != nil { | ||
return err | ||
} | ||
log.Info(ctx, "migrate.fixEmptyUUIDHooks> workflow %s/%s (%d) has been cleaned", proj.Name, w.Name, w.ID) | ||
|
||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not delete these hooks?