fix: Resolve the issue of database uninstallation failure (#9361)

This commit is contained in:
CityFun 2025-07-01 15:46:21 +08:00 committed by GitHub
parent 7a45548387
commit c522295c56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 17 deletions

View file

@ -631,10 +631,14 @@ func (a *AppInstallService) DeleteCheck(installID uint) ([]dto.AppResource, erro
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID), repo.WithByFrom(constant.AppResourceLocal)) resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID), repo.WithByFrom(constant.AppResourceLocal))
for _, resource := range resources { for _, resource := range resources {
linkInstall, _ := appInstallRepo.GetFirst(repo.WithByID(resource.AppInstallId)) linkInstall, _ := appInstallRepo.GetFirst(repo.WithByID(resource.AppInstallId))
res = append(res, dto.AppResource{ if linkInstall.ID > 0 {
Type: "app", res = append(res, dto.AppResource{
Name: linkInstall.Name, Type: "app",
}) Name: linkInstall.Name,
})
} else {
_ = appInstallResourceRepo.DeleteBy(context.Background(), appInstallResourceRepo.WithAppInstallId(resource.AppInstallId))
}
} }
return res, nil return res, nil
} }

View file

@ -379,21 +379,25 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
} }
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID)) resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(install.ID))
if deleteReq.DeleteDB && len(resources) > 0 { if len(resources) > 0 {
del := dto.DelAppLink{ if deleteReq.DeleteDB {
Ctx: ctx, del := dto.DelAppLink{
Install: &install, Ctx: ctx,
ForceDelete: deleteReq.ForceDelete, Install: &install,
Task: uninstallTask, ForceDelete: deleteReq.ForceDelete,
} Task: uninstallTask,
t.LogWithOps(task.TaskDelete, i18n.GetMsgByKey("Database"))
if err = deleteLink(del); err != nil {
t.LogFailedWithOps(task.TaskDelete, i18n.GetMsgByKey("Database"), err)
if !deleteReq.ForceDelete {
return err
} }
t.LogWithOps(task.TaskDelete, i18n.GetMsgByKey("Database"))
if err = deleteLink(del); err != nil {
t.LogFailedWithOps(task.TaskDelete, i18n.GetMsgByKey("Database"), err)
if !deleteReq.ForceDelete {
return err
}
}
t.LogSuccessWithOps(task.TaskDelete, i18n.GetMsgByKey("Database"))
} else {
_ = appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
} }
t.LogSuccessWithOps(task.TaskDelete, i18n.GetMsgByKey("Database"))
} }
if DatabaseKeys[install.App.Key] > 0 { if DatabaseKeys[install.App.Key] > 0 {