fix(access): repair return-match API catalog migration (#341)
This commit is contained in:
+2
-2
@@ -54,9 +54,9 @@ func migrateAfterSalesReturnMatch(db *gorm.DB, version string) error {
|
||||
if len(permission.Path) < len("/api/admin/v1/return-matches") || permission.Path[:len("/api/admin/v1/return-matches")] != "/api/admin/v1/return-matches" {
|
||||
continue
|
||||
}
|
||||
api := afterSalesReturnMatchAPI{}
|
||||
api := afterSalesReturnMatchAPI{Path: permission.Path, Action: permission.Method}
|
||||
if err := tx.Where("path = ? AND action = ?", permission.Path, permission.Method).
|
||||
Assign(afterSalesReturnMatchAPI{Title: permission.Title, Type: "BUS"}).
|
||||
Assign(afterSalesReturnMatchAPI{Title: permission.Title, Path: permission.Path, Action: permission.Method, Type: "BUS"}).
|
||||
FirstOrCreate(&api).Error; err != nil {
|
||||
return fmt.Errorf("ensure return-match API: %w", err)
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package version_local
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"go-admin/app/goauto/access"
|
||||
"go-admin/cmd/migrate/migration"
|
||||
common "go-admin/common/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Repair the API catalogue rows created by 1789801200000 before the path and
|
||||
// action fields were populated. This is idempotent and only touches the
|
||||
// return-match endpoints.
|
||||
func init() {
|
||||
_, fileName, _, _ := runtime.Caller(0)
|
||||
migration.Migrate.SetVersion(migration.GetFilename(fileName), migrateFixReturnMatchAPICatalog)
|
||||
}
|
||||
|
||||
func migrateFixReturnMatchAPICatalog(db *gorm.DB, version string) error {
|
||||
return db.Transaction(func(tx *gorm.DB) error {
|
||||
for _, permission := range access.AdminAPIs {
|
||||
if len(permission.Path) < len("/api/admin/v1/return-matches") || permission.Path[:len("/api/admin/v1/return-matches")] != "/api/admin/v1/return-matches" {
|
||||
continue
|
||||
}
|
||||
if err := tx.Table("sys_api").Where("title = ?", permission.Title).Updates(map[string]any{
|
||||
"title": permission.Title, "path": permission.Path, "action": permission.Method, "type": "BUS",
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Create(&common.Migration{Version: version}).Error
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user