feat(framework): update `pluginOption` field's type in projects (#7505)
diff --git a/backend/core/models/migrationscripts/20240523_update_plugin_option_in_project_metric_settings.go b/backend/core/models/migrationscripts/20240523_update_plugin_option_in_project_metric_settings.go
new file mode 100644
index 0000000..94fb29e
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240523_update_plugin_option_in_project_metric_settings.go
@@ -0,0 +1,69 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "encoding/json"
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/dal"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+var _ plugin.MigrationScript = (*addCommitShaToCicdRelease)(nil)
+
+type projectMetricSettings20240523 struct {
+ PluginOption json.RawMessage `gorm:"type:json"`
+}
+
+func (projectMetricSettings20240523) TableName() string {
+ return "project_metric_settings"
+}
+
+type updatePluginOptionInProjectMetricSetting struct{}
+
+func (u *updatePluginOptionInProjectMetricSetting) Up(basicRes context.BasicRes) errors.Error {
+ db := basicRes.GetDal()
+ if err := migrationhelper.ChangeColumnsType[projectMetricSettings20240523](
+ basicRes,
+ u,
+ projectMetricSettings20240523{}.TableName(),
+ []string{"plugin_option"},
+ func(tmpColumnParams []interface{}) errors.Error {
+ return db.UpdateColumn(
+ &projectMetricSettings20240523{},
+ "plugin_option",
+ dal.DalClause{Expr: " ? ", Params: []interface{}{"{}"}},
+ dal.Where("? is not null", tmpColumnParams...),
+ )
+ },
+ ); err != nil {
+ return err
+
+ }
+ return nil
+}
+
+func (*updatePluginOptionInProjectMetricSetting) Version() uint64 {
+ return 20240523194205
+}
+
+func (*updatePluginOptionInProjectMetricSetting) Name() string {
+ return "update plugin_option's type in project_metric_settings"
+}
diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go
index 5e1efde..08f5c6b 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -116,5 +116,6 @@
new(addCicdRelease),
new(addCommitShaToCicdRelease),
new(updateIssueKeyType),
+ new(updatePluginOptionInProjectMetricSetting),
}
}
diff --git a/backend/core/models/project.go b/backend/core/models/project.go
index 56cd3b5..99c6178 100644
--- a/backend/core/models/project.go
+++ b/backend/core/models/project.go
@@ -39,9 +39,9 @@
}
type BaseMetric struct {
- PluginName string `json:"pluginName" mapstructure:"pluginName" gorm:"primaryKey;type:varchar(255)" validate:"required"`
- PluginOption string `json:"pluginOption" mapstructure:"pluginOption" gorm:"type:text"`
- Enable bool `json:"enable" mapstructure:"enable" gorm:"type:boolean"`
+ PluginName string `json:"pluginName" mapstructure:"pluginName" gorm:"primaryKey;type:varchar(255)" validate:"required"`
+ PluginOption json.RawMessage `json:"pluginOption" mapstructure:"pluginOption" gorm:"type:json"`
+ Enable bool `json:"enable" mapstructure:"enable" gorm:"type:boolean"`
}
type BaseProjectMetricSetting struct {
diff --git a/backend/server/services/blueprint.go b/backend/server/services/blueprint.go
index 2f7ddb5..28da221 100644
--- a/backend/server/services/blueprint.go
+++ b/backend/server/services/blueprint.go
@@ -356,7 +356,7 @@
return nil, err
}
for _, projectMetric := range projectMetrics {
- metrics[projectMetric.PluginName] = json.RawMessage(projectMetric.PluginOption)
+ metrics[projectMetric.PluginName] = projectMetric.PluginOption
}
}
skipCollectors := false
diff --git a/backend/test/helper/api.go b/backend/test/helper/api.go
index 2af718f..e07c89d 100644
--- a/backend/test/helper/api.go
+++ b/backend/test/helper/api.go
@@ -168,14 +168,14 @@
}
metrics = append(metrics, &models.BaseMetric{
PluginName: p.Name,
- PluginOption: string(ToJson(p.Options)),
+ PluginOption: ToJson(p.Options),
Enable: true,
})
}
if project.EnableDora && !doraSeen {
metrics = append(metrics, &models.BaseMetric{
PluginName: "dora",
- PluginOption: string(ToJson(nil)),
+ PluginOption: ToJson(nil),
Enable: true,
})
}