@@ -1155,6 +1155,115 @@ var AddUserManagementMenu = &gormigrate.Migration{
11551155 },
11561156}
11571157
1158+ var AddOpsReportMenu = & gormigrate.Migration {
1159+ ID : "20260512-add-ops-report-menu" ,
1160+ Migrate : func (tx * gorm.DB ) error {
1161+ if ! global .CONF .Base .IsEnterprise {
1162+ return nil
1163+ }
1164+ var menuJSON string
1165+ if err := tx .Model (& model.Setting {}).Where ("key = ?" , "HideMenu" ).Pluck ("value" , & menuJSON ).Error ; err != nil {
1166+ return err
1167+ }
1168+ if menuJSON == "" {
1169+ menuJSON = helper .LoadMenus ()
1170+ }
1171+
1172+ var menus []dto.ShowMenu
1173+ if err := json .Unmarshal ([]byte (menuJSON ), & menus ); err != nil {
1174+ return tx .Model (& model.Setting {}).
1175+ Where ("key = ?" , "HideMenu" ).
1176+ Update ("value" , helper .LoadMenus ()).Error
1177+ }
1178+
1179+ newItem := dto.ShowMenu {
1180+ ID : "122" ,
1181+ Disabled : false ,
1182+ Title : "xpack.opsReport.name" ,
1183+ IsShow : true ,
1184+ Label : "OpsReport" ,
1185+ Path : "/enterprise/ops-report" ,
1186+ Sort : 360 ,
1187+ }
1188+
1189+ for i := range menus {
1190+ if menus [i ].Label != "Xpack-Menu" {
1191+ continue
1192+ }
1193+ menus [i ].Children = helper .UpsertMenuByLabel (menus [i ].Children , newItem , "UserManagement" )
1194+ break
1195+ }
1196+
1197+ updatedJSON , err := json .Marshal (menus )
1198+ if err != nil {
1199+ return tx .Model (& model.Setting {}).
1200+ Where ("key = ?" , "HideMenu" ).
1201+ Update ("value" , helper .LoadMenus ()).Error
1202+ }
1203+ return tx .Model (& model.Setting {}).Where ("key = ?" , "HideMenu" ).Update ("value" , string (updatedJSON )).Error
1204+ },
1205+ }
1206+
1207+ var AddOpsReportSetting = & gormigrate.Migration {
1208+ ID : "20260512-add-ops-report-setting" ,
1209+ Migrate : func (tx * gorm.DB ) error {
1210+ if ! global .CONF .Base .IsEnterprise {
1211+ return nil
1212+ }
1213+ var count int64
1214+ if err := tx .Model (& model.Setting {}).Where ("key = ?" , "OpsReportExportFormat" ).Count (& count ).Error ; err != nil {
1215+ return err
1216+ }
1217+ if count > 0 {
1218+ return nil
1219+ }
1220+ return tx .Create (& model.Setting {Key : "OpsReportExportFormat" , Value : constant .OpsReportExportFormatPDF }).Error
1221+ },
1222+ }
1223+
1224+ var AddOpsReportScheduleSetting = & gormigrate.Migration {
1225+ ID : "20260513-add-ops-report-schedule-setting" ,
1226+ Migrate : func (tx * gorm.DB ) error {
1227+ if ! global .CONF .Base .IsEnterprise {
1228+ return nil
1229+ }
1230+ settings := []model.Setting {
1231+ {Key : "OpsReportSchedule" , Value : constant .OpsReportScheduleWeekly },
1232+ {Key : "OpsReportSavePath" , Value : path .Join (global .CONF .Base .InstallDir , constant .OpsReportDefaultSaveSubDir )},
1233+ }
1234+ for _ , item := range settings {
1235+ var count int64
1236+ if err := tx .Model (& model.Setting {}).Where ("key = ?" , item .Key ).Count (& count ).Error ; err != nil {
1237+ return err
1238+ }
1239+ if count > 0 {
1240+ continue
1241+ }
1242+ if err := tx .Create (& item ).Error ; err != nil {
1243+ return err
1244+ }
1245+ }
1246+ return nil
1247+ },
1248+ }
1249+
1250+ var AddOpsReportThresholdSetting = & gormigrate.Migration {
1251+ ID : "20260513-add-ops-report-threshold-setting" ,
1252+ Migrate : func (tx * gorm.DB ) error {
1253+ if ! global .CONF .Base .IsEnterprise {
1254+ return nil
1255+ }
1256+ var count int64
1257+ if err := tx .Model (& model.Setting {}).Where ("key = ?" , "OpsReportThreshold" ).Count (& count ).Error ; err != nil {
1258+ return err
1259+ }
1260+ if count > 0 {
1261+ return nil
1262+ }
1263+ return tx .Create (& model.Setting {Key : "OpsReportThreshold" , Value : constant .OpsReportDefaultThreshold }).Error
1264+ },
1265+ }
1266+
11581267var AddOperationLogUser = & gormigrate.Migration {
11591268 ID : "20260424-add-operation-log-user" ,
11601269 Migrate : func (tx * gorm.DB ) error {
0 commit comments