You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2022/11/15 05:01:06 UTC
[incubator-devlake] branch main updated: fix(framework): modify scripts (#3728)
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 859539f04 fix(framework): modify scripts (#3728)
859539f04 is described below
commit 859539f045349b533eb4d5e7ae98ccd6021d5e3c
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Tue Nov 15 13:01:01 2022 +0800
fix(framework): modify scripts (#3728)
---
.../20220722_commitfile_component.go | 6 +--
.../migrationscripts/20220903_encrypt_blueprint.go | 56 ++++++--------------
.../migrationscripts/20220904_encrypt_pipeline.go | 61 ++++------------------
.../20220729_modify_all_entities.go | 8 +--
4 files changed, 33 insertions(+), 98 deletions(-)
diff --git a/models/migrationscripts/20220722_commitfile_component.go b/models/migrationscripts/20220722_commitfile_component.go
index db22158d6..305fe0ea0 100644
--- a/models/migrationscripts/20220722_commitfile_component.go
+++ b/models/migrationscripts/20220722_commitfile_component.go
@@ -69,9 +69,9 @@ func (addCommitFileComponent) Up(basicRes core.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(
basicRes,
- component20220722{},
- commitFile20220722{},
- commitFileComponent20220722{},
+ &component20220722{},
+ &commitFile20220722{},
+ &commitFileComponent20220722{},
)
}
diff --git a/models/migrationscripts/20220903_encrypt_blueprint.go b/models/migrationscripts/20220903_encrypt_blueprint.go
index d1ca7af7c..ffcec6fff 100644
--- a/models/migrationscripts/20220903_encrypt_blueprint.go
+++ b/models/migrationscripts/20220903_encrypt_blueprint.go
@@ -18,8 +18,6 @@ limitations under the License.
package migrationscripts
import (
- "encoding/json"
-
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
"github.com/apache/incubator-devlake/models/migrationscripts/archived"
@@ -30,28 +28,10 @@ var _ core.MigrationScript = (*encryptBlueprint)(nil)
type encryptBlueprint struct{}
-type blueprint20220903Before struct {
- Name string `json:"name" validate:"required"`
- Mode string `json:"mode" gorm:"varchar(20)" validate:"required,oneof=NORMAL ADVANCED"`
- Plan json.RawMessage `json:"plan"`
- Enable bool `json:"enable"`
- CronConfig string `json:"cronConfig" format:"* * * * *" example:"0 0 * * 1"`
- IsManual bool `json:"isManual"`
- Settings json.RawMessage `json:"settings" swaggertype:"array,string" example:"please check api: /blueprints/<PLUGIN_NAME>/blueprint-setting"`
- archived.Model `swaggerignore:"true"`
-}
-
-type blueprint20220903After struct {
- /* unchanged part */
- Name string `json:"name" validate:"required"`
- Mode string `json:"mode" gorm:"varchar(20)" validate:"required,oneof=NORMAL ADVANCED"`
- Enable bool `json:"enable"`
- CronConfig string `json:"cronConfig" format:"* * * * *" example:"0 0 * * 1"`
- IsManual bool `json:"isManual"`
- archived.Model `swaggerignore:"true"`
- /* changed part */
- Plan string `json:"plan"`
- Settings string `json:"settings"`
+type BlueprintEncryption0904 struct {
+ archived.Model
+ Plan string
+ Settings string
}
func (script *encryptBlueprint) Up(basicRes core.BasicRes) errors.Error {
@@ -59,34 +39,28 @@ func (script *encryptBlueprint) Up(basicRes core.BasicRes) errors.Error {
if encKey == "" {
return errors.BadInput.New("invalid encKey")
}
-
- return migrationhelper.TransformTable(
+ err := migrationhelper.TransformColumns(
basicRes,
script,
"_devlake_blueprints",
- func(s *blueprint20220903Before) (*blueprint20220903After, errors.Error) {
- encryptedPlan, err := core.Encrypt(encKey, string(s.Plan))
+ []string{"plan", "settings"},
+ func(src *BlueprintEncryption0904) (*BlueprintEncryption0904, errors.Error) {
+ plan, err := core.Encrypt(encKey, src.Plan)
if err != nil {
return nil, err
}
- encryptedSettings, err := core.Encrypt(encKey, string(s.Settings))
+ settings, err := core.Encrypt(encKey, src.Settings)
if err != nil {
return nil, err
}
-
- dst := &blueprint20220903After{
- Name: s.Name,
- Mode: s.Mode,
- Enable: s.Enable,
- CronConfig: s.CronConfig,
- IsManual: s.IsManual,
- Model: archived.Model{ID: s.ID},
- Plan: encryptedPlan,
- Settings: encryptedSettings,
- }
- return dst, nil
+ return &BlueprintEncryption0904{
+ Model: src.Model,
+ Plan: plan,
+ Settings: settings,
+ }, nil
},
)
+ return err
}
func (*encryptBlueprint) Version() uint64 {
diff --git a/models/migrationscripts/20220904_encrypt_pipeline.go b/models/migrationscripts/20220904_encrypt_pipeline.go
index 343919758..df93a5735 100644
--- a/models/migrationscripts/20220904_encrypt_pipeline.go
+++ b/models/migrationscripts/20220904_encrypt_pipeline.go
@@ -18,48 +18,19 @@ limitations under the License.
package migrationscripts
import (
- "time"
-
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
- "github.com/apache/incubator-devlake/models/common"
"github.com/apache/incubator-devlake/models/migrationscripts/archived"
"github.com/apache/incubator-devlake/plugins/core"
- "gorm.io/datatypes"
)
var _ core.MigrationScript = (*encryptPipeline)(nil)
type encryptPipeline struct{}
-type pipeline20220904Before struct {
+type PipelineEncryption0904 struct {
archived.Model
- Name string `json:"name" gorm:"index"`
- BlueprintId uint64 `json:"blueprintId"`
- Plan datatypes.JSON `json:"plan"` // target field
- TotalTasks int `json:"totalTasks"`
- FinishedTasks int `json:"finishedTasks"`
- BeganAt *time.Time `json:"beganAt"`
- FinishedAt *time.Time `json:"finishedAt" gorm:"index"`
- Status string `json:"status"`
- Message string `json:"message"`
- SpentSeconds int `json:"spentSeconds"`
- Stage int `json:"stage"`
-}
-
-type pipeline0904After struct {
- common.Model
- Name string `json:"name" gorm:"index"`
- BlueprintId uint64 `json:"blueprintId"`
- Plan string `json:"plan" encrypt:"yes"` // target field
- TotalTasks int `json:"totalTasks"`
- FinishedTasks int `json:"finishedTasks"`
- BeganAt *time.Time `json:"beganAt"`
- FinishedAt *time.Time `json:"finishedAt" gorm:"index"`
- Status string `json:"status"`
- Message string `json:"message"`
- SpentSeconds int `json:"spentSeconds"`
- Stage int `json:"stage"`
+ Plan string
}
func (script *encryptPipeline) Up(basicRes core.BasicRes) errors.Error {
@@ -67,33 +38,23 @@ func (script *encryptPipeline) Up(basicRes core.BasicRes) errors.Error {
if encKey == "" {
return errors.BadInput.New("invalid encKey")
}
-
- return migrationhelper.TransformTable(
+ err := migrationhelper.TransformColumns(
basicRes,
script,
"_devlake_pipelines",
- func(s *pipeline20220904Before) (*pipeline0904After, errors.Error) {
- encryptedPlan, err := core.Encrypt(encKey, string(s.Plan))
+ []string{"plan"},
+ func(src *PipelineEncryption0904) (*PipelineEncryption0904, errors.Error) {
+ plan, err := core.Encrypt(encKey, src.Plan)
if err != nil {
return nil, err
}
-
- dst := &pipeline0904After{
- Name: s.Name,
- BlueprintId: s.BlueprintId,
- FinishedTasks: s.FinishedTasks,
- BeganAt: s.BeganAt,
- FinishedAt: s.FinishedAt,
- Status: s.Status,
- Message: s.Message,
- SpentSeconds: s.SpentSeconds,
- Stage: s.Stage,
- Plan: encryptedPlan,
- }
- return dst, nil
+ return &PipelineEncryption0904{
+ Model: src.Model,
+ Plan: plan,
+ }, nil
},
)
-
+ return err
}
func (*encryptPipeline) Version() uint64 {
diff --git a/plugins/jenkins/models/migrationscripts/20220729_modify_all_entities.go b/plugins/jenkins/models/migrationscripts/20220729_modify_all_entities.go
index dba0726ac..e803190bb 100644
--- a/plugins/jenkins/models/migrationscripts/20220729_modify_all_entities.go
+++ b/plugins/jenkins/models/migrationscripts/20220729_modify_all_entities.go
@@ -85,10 +85,10 @@ func (*modifyAllEntities) Up(basicRes core.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(
basicRes,
- jenkinsBuild20220729{},
- jenkinsJobDag20220729{},
- jenkinsBuildRepo20220729{},
- jenkinsStage20200729{},
+ &jenkinsBuild20220729{},
+ &jenkinsJobDag20220729{},
+ &jenkinsBuildRepo20220729{},
+ &jenkinsStage20200729{},
)
}