fix: Fixed the issue of database transfer failure to child nodes (#10906)

This commit is contained in:
CityFun 2025-11-10 18:09:39 +08:00 committed by GitHub
parent ec4533e7de
commit c6fe487e46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -134,17 +134,7 @@ var ToolKeys = map[string]uint{
"minio": 9001, "minio": 9001,
} }
func createLink(ctx context.Context, installTask *task.Task, app model.App, appInstall *model.AppInstall, params map[string]interface{}) error { func CreateDB(ctx context.Context, app model.App, appInstall *model.AppInstall, params map[string]interface{}) error {
deleteAppLink := func(t *task.Task) {
del := dto.DelAppLink{
Ctx: ctx,
Install: appInstall,
ForceDelete: true,
}
_ = deleteLink(del)
}
if DatabaseKeys[app.Key] > 0 {
handleDataBaseApp := func(task *task.Task) error {
database := &model.Database{ database := &model.Database{
AppInstallID: appInstall.ID, AppInstallID: appInstall.ID,
Name: appInstall.Name, Name: appInstall.Name,
@ -158,7 +148,6 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
if err != nil { if err != nil {
return err return err
} }
formFields := &dto.AppForm{} formFields := &dto.AppForm{}
if err := json.Unmarshal([]byte(detail.Params), formFields); err != nil { if err := json.Unmarshal([]byte(detail.Params), formFields); err != nil {
return err return err
@ -213,6 +202,20 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
} }
} }
return databaseRepo.Create(ctx, database) return databaseRepo.Create(ctx, database)
}
func createLink(ctx context.Context, installTask *task.Task, app model.App, appInstall *model.AppInstall, params map[string]interface{}) error {
deleteAppLink := func(t *task.Task) {
del := dto.DelAppLink{
Ctx: ctx,
Install: appInstall,
ForceDelete: true,
}
_ = deleteLink(del)
}
if DatabaseKeys[app.Key] > 0 {
handleDataBaseApp := func(task *task.Task) error {
return CreateDB(ctx, app, appInstall, params)
} }
installTask.AddSubTask(i18n.GetMsgByKey("HandleDatabaseApp"), handleDataBaseApp, deleteAppLink) installTask.AddSubTask(i18n.GetMsgByKey("HandleDatabaseApp"), handleDataBaseApp, deleteAppLink)
} }
@ -2135,16 +2138,18 @@ func needsUpdate(localTag *model.Tag, remoteTag dto.Tag, translations string) bo
func hasLinkDB(installID uint) bool { func hasLinkDB(installID uint) bool {
resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(installID)) resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(installID))
hasDB := false
if len(resources) > 0 { if len(resources) > 0 {
for _, resource := range resources { for _, resource := range resources {
if resource.Key == constant.AppPostgres || resource.Key == constant.AppMysql || if resource.Key == constant.AppPostgres || resource.Key == constant.AppMysql ||
resource.Key == constant.AppMariaDB || resource.Key == constant.AppMysqlCluster || resource.Key == constant.AppMariaDB || resource.Key == constant.AppMysqlCluster ||
resource.Key == constant.AppPostgresql || resource.Key == constant.AppPostgresqlCluster { resource.Key == constant.AppPostgresql || resource.Key == constant.AppPostgresqlCluster {
return true hasDB = true
break
} }
} }
} }
return false return hasDB
} }
func isEditCompose(installed model.AppInstall) bool { func isEditCompose(installed model.AppInstall) bool {