Skip to content

Commit

Permalink
feat: audits迁移脚本更新适应新数据
Browse files Browse the repository at this point in the history
  • Loading branch information
LidolLxf committed Dec 23, 2024
1 parent 06d541b commit e175325
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package migrations

import (
"fmt"

"gorm.io/gorm"

"github.com/TencentBlueKing/bk-bscp/cmd/data-service/db-migration/migrator"
Expand Down Expand Up @@ -42,6 +44,15 @@ func mig20241128111704Up(tx *gorm.DB) error {
}
}

// 数据更新适应新版本
err := tx.Exec("UPDATE audits SET res_type=\"release\", action=\"publish\", " +
"res_instance=REPLACE(res_instance,\"releases_name\",\"config_release_name\"), " +
"res_instance=REPLACE(res_instance,\"group\",\"config_release_scope\") WHERE " +
"action=\"publish_release_config\" and res_type=\"app_config\";").Error

if err != nil {
return err
}
return nil
}

Expand All @@ -58,5 +69,16 @@ func mig20241128111704Down(tx *gorm.DB) error {
}
}

// 回退数据更新适应旧版本
err := tx.Exec("UPDATE audits SET res_type=\"app_config\", action=\"publish_release_config\", " +
"res_instance=REPLACE(res_instance,\"config_release_name\",\"releases_name\"), " +
"res_instance=REPLACE(res_instance,\"config_release_scope\",\"group\") WHERE " +
"action=\"publish\" and res_type=\"release\";").Error

if err != nil {
fmt.Println("audits exec sql fail: ", err)
return err
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/data-service/service/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *Service) SubmitPublishApprove(
AppId: app.AppID(),
StrategyId: pshID,
IsCompare: req.IsCompare,
Detail: strings.Join(groupName, constant.NameSeparator),
Detail: req.Memo,
}).PreparePublish(strategy)
if err = ad.Do(tx.Query); err != nil {
return nil, err
Expand Down

0 comments on commit e175325

Please sign in to comment.