jojo/services/asymkey/deploy_key.go
Gusted c07ea09050 fix: cleanup data before migration retry (#12370)
In the case you hit some API error (Github ratelimit was often a problem) or the instance restarted in the middle of your migration, you would be left with data on the disk and/or database. Upon retrying the migration the migration code would (rightfully) fail because it's trying to migrate stuff that already exists.

This was hit so often on Codeberg it was better to force people to delete and start whole migration process again: 28ee60c91f

Delete the repository data before retrying to solve this.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12370
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
2026-05-05 12:41:42 +02:00

23 lines
575 B
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package asymkey
import (
"context"
"forgejo.org/models"
asymkey_model "forgejo.org/models/asymkey"
"forgejo.org/models/db"
)
// DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed.
func DeleteDeployKey(ctx context.Context, id, repoID int64) error {
if err := db.WithTx(ctx, func(ctx context.Context) error {
return models.DeleteDeployKey(ctx, id, repoID)
}); err != nil {
return err
}
return asymkey_model.RewriteAllPublicKeys(ctx)
}