Files
mayfly-go/server/migration/migrations/v1_10.go
zongyangleo 142bbd265d !134 feat: 新增支持es和连接池
* feat: 各连接,支持连接池
* feat:支持es
2025-05-21 04:42:30 +00:00

148 lines
4.2 KiB
Go

package migrations
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
esentity "mayfly-go/internal/es/domain/entity"
flowentity "mayfly-go/internal/flow/domain/entity"
sysentity "mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/model"
"time"
)
func V1_10() []*gormigrate.Migration {
var migrations []*gormigrate.Migration
migrations = append(migrations, V1_10_0()...)
migrations = append(migrations, V1_10_1()...)
return migrations
}
func V1_10_0() []*gormigrate.Migration {
return []*gormigrate.Migration{
{
ID: "20250213-v1.10.0-flow-recode",
Migrate: func(tx *gorm.DB) error {
err := tx.AutoMigrate(&flowentity.Procdef{},
&flowentity.Procinst{},
&flowentity.Execution{},
&flowentity.ProcinstTask{},
&flowentity.ProcinstTaskCandidate{},
&flowentity.HisProcinstOp{})
if err != nil {
return err
}
return nil
},
Rollback: func(tx *gorm.DB) error {
return nil
},
},
}
}
func V1_10_1() []*gormigrate.Migration {
return []*gormigrate.Migration{
{
ID: "20250422-v1.10.1-es",
Migrate: func(tx *gorm.DB) error {
// 添加实例表
entities := [...]any{
new(esentity.EsInstance),
}
for _, e := range entities {
if err := tx.AutoMigrate(e); err != nil {
return err
}
}
// 添加菜单资源
resources := []*sysentity.Resource{
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745292787}}}},
Pid: 0,
UiPath: "lbOU73qg/",
Name: "Elasticsearch",
Code: "/es",
Type: 1,
Meta: `{"icon":"icon es/es-color","isKeepAlive":true,"routeName":"ES"}`,
Weight: 7,
},
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745319348}}}},
Pid: 1745292787,
UiPath: "lbOU73qg/gZ2MHF0b/",
Name: "es.instance",
Code: "EsInstance ",
Type: 1,
Meta: `{"component":"ops/es/InstanceList","icon":"icon es/es-color","isKeepAlive":true,"routeName":"EsInstanceList"}`,
Weight: 1745319348,
},
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745319410}}}},
Pid: 1745319348,
UiPath: "lbOU73qg/gZ2MHF0b/rcKBdxB5/",
Name: "es.instanceSave",
Code: "es:instance:save",
Type: 2,
Weight: 1745319410,
},
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745319424}}}},
Pid: 1745319348,
UiPath: "lbOU73qg/gZ2MHF0b/IMGhLSJK/",
Name: "es.instanceDel",
Code: "es:instance:del",
Type: 2,
Weight: 1745319424,
},
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745494931}}}},
Pid: 1745292787,
UiPath: "lbOU73qg/2sDi4isw/",
Name: "es.operation",
Code: "EsOperation",
Type: 1,
Meta: `{"component":"ops/es/EsOperation","icon":"icon es/es-color","isKeepAlive":true,"routeName":"EsOperation"}`,
Weight: 1745319347,
},
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745659240}}}},
Pid: 1745494931,
UiPath: "lbOU73qg/2sDi4isw/SQNFhhhn/",
Name: "es.dataSave",
Code: "es:data:save",
Type: 2,
Weight: 1745659240,
},
{
Model: model.Model{CreateModel: model.CreateModel{DeletedModel: model.DeletedModel{IdModel: model.IdModel{Id: 1745659315}}}},
Pid: 1745494931,
UiPath: "lbOU73qg/2sDi4isw/XAgy5Uvp/",
Name: "es.dataDel",
Code: "es:data:del",
Type: 2,
Weight: 1745659315,
},
}
now := time.Now()
for _, res := range resources {
res.Status = 1
res.CreateTime = &now
res.CreatorId = 1
res.Creator = "admin"
res.UpdateTime = &now
res.ModifierId = 1
res.Modifier = "admin"
tx.Create(res)
}
// 给超管授权
return nil
},
Rollback: func(tx *gorm.DB) error {
return nil
},
},
}
}