This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.19
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.19 by this push:
     new c024544d7 fix: data too long for column component (#6187)
c024544d7 is described below

commit c024544d7e932a31316a25ccbb7d463f709d7e2f
Author: abeizn <[email protected]>
AuthorDate: Sat Oct 7 16:59:33 2023 +0800

    fix: data too long for column component (#6187)
---
 .../20231007_modify_component_length.go            | 121 +++++++++++++++++++++
 .../sonarqube/models/migrationscripts/register.go  |   1 +
 .../plugins/sonarqube/models/sonarqube_hotspot.go  |   2 +-
 .../plugins/sonarqube/models/sonarqube_issue.go    |   2 +-
 .../sonarqube/models/sonarqube_issue_code_block.go |   2 +-
 5 files changed, 125 insertions(+), 3 deletions(-)

diff --git 
a/backend/plugins/sonarqube/models/migrationscripts/20231007_modify_component_length.go
 
b/backend/plugins/sonarqube/models/migrationscripts/20231007_modify_component_length.go
new file mode 100644
index 000000000..e47ed7202
--- /dev/null
+++ 
b/backend/plugins/sonarqube/models/migrationscripts/20231007_modify_component_length.go
@@ -0,0 +1,121 @@
+/*
+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 (
+       "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 = (*modifyComponentLength)(nil)
+
+type modifyComponentLength struct{}
+
+type sonarqubeHotspot20231007 struct {
+       Component string `gorm:"index;type:varchar(500)"`
+}
+
+func (sonarqubeHotspot20231007) TableName() string {
+       return "_tool_sonarqube_hotspots"
+}
+
+type sonarqubeIssueCodeBlock20231007 struct {
+       Component string `gorm:"index;type:varchar(500)"`
+}
+
+func (sonarqubeIssueCodeBlock20231007) TableName() string {
+       return "_tool_sonarqube_issue_code_blocks"
+}
+
+type sonarqubeIssue20231007 struct {
+       Component string `gorm:"index;type:varchar(500)"`
+}
+
+func (sonarqubeIssue20231007) TableName() string {
+       return "_tool_sonarqube_issues"
+}
+
+func (script *modifyComponentLength) Up(basicRes context.BasicRes) 
errors.Error {
+       db := basicRes.GetDal()
+       err := migrationhelper.ChangeColumnsType[sonarqubeHotspot20231007](
+               basicRes,
+               script,
+               sonarqubeHotspot20231007{}.TableName(),
+               []string{"component"},
+               func(tmpColumnParams []interface{}) errors.Error {
+                       return db.UpdateColumn(
+                               &sonarqubeHotspot20231007{},
+                               "component",
+                               dal.DalClause{Expr: " ? ", Params: 
tmpColumnParams},
+                               dal.Where("? != '' ", tmpColumnParams...),
+                       )
+               },
+       )
+       if err != nil {
+               return err
+       }
+
+       err = 
migrationhelper.ChangeColumnsType[sonarqubeIssueCodeBlock20231007](
+               basicRes,
+               script,
+               sonarqubeIssueCodeBlock20231007{}.TableName(),
+               []string{"component"},
+               func(tmpColumnParams []interface{}) errors.Error {
+                       return db.UpdateColumn(
+                               &sonarqubeIssueCodeBlock20231007{},
+                               "component",
+                               dal.DalClause{Expr: " ? ", Params: 
tmpColumnParams},
+                               dal.Where("? != '' ", tmpColumnParams...),
+                       )
+               },
+       )
+       if err != nil {
+               return err
+       }
+
+       err = migrationhelper.ChangeColumnsType[sonarqubeIssue20231007](
+               basicRes,
+               script,
+               sonarqubeIssue20231007{}.TableName(),
+               []string{"component"},
+               func(tmpColumnParams []interface{}) errors.Error {
+                       return db.UpdateColumn(
+                               &sonarqubeIssue20231007{},
+                               "component",
+                               dal.DalClause{Expr: " ? ", Params: 
tmpColumnParams},
+                               dal.Where("? != '' ", tmpColumnParams...),
+                       )
+               },
+       )
+       if err != nil {
+               return err
+       }
+
+       return nil
+}
+
+func (*modifyComponentLength) Version() uint64 {
+       return 20231007145127
+}
+
+func (*modifyComponentLength) Name() string {
+       return "modify component type to varchar(500)"
+}
diff --git a/backend/plugins/sonarqube/models/migrationscripts/register.go 
b/backend/plugins/sonarqube/models/migrationscripts/register.go
index 1f2200763..d1f70cf34 100644
--- a/backend/plugins/sonarqube/models/migrationscripts/register.go
+++ b/backend/plugins/sonarqube/models/migrationscripts/register.go
@@ -26,5 +26,6 @@ func All() []plugin.MigrationScript {
                new(modifyCharacterSet),
                new(expandProjectKey20230206),
                new(addRawParamTableForScope),
+               new(modifyComponentLength),
        }
 }
diff --git a/backend/plugins/sonarqube/models/sonarqube_hotspot.go 
b/backend/plugins/sonarqube/models/sonarqube_hotspot.go
index ce335ffcf..28e7b0b7f 100644
--- a/backend/plugins/sonarqube/models/sonarqube_hotspot.go
+++ b/backend/plugins/sonarqube/models/sonarqube_hotspot.go
@@ -25,7 +25,7 @@ type SonarqubeHotspot struct {
        ConnectionId             uint64 `gorm:"primaryKey"`
        HotspotKey               string `gorm:"primaryKey"`
        RuleKey                  string `gorm:"type:varchar(255)"`
-       Component                string `gorm:"index"`
+       Component                string `gorm:"index;type:varchar(500)"`
        ProjectKey               string `gorm:"index"`
        Line                     int
        Status                   string `gorm:"type:varchar(100)"`
diff --git a/backend/plugins/sonarqube/models/sonarqube_issue.go 
b/backend/plugins/sonarqube/models/sonarqube_issue.go
index 14cc934ed..3bc8a2b13 100644
--- a/backend/plugins/sonarqube/models/sonarqube_issue.go
+++ b/backend/plugins/sonarqube/models/sonarqube_issue.go
@@ -26,7 +26,7 @@ type SonarqubeIssue struct {
        IssueKey     string `gorm:"primaryKey;type:varchar(100)"`
        Rule         string `gorm:"type:varchar(255)"`
        Severity     string `gorm:"type:varchar(100)"`
-       Component    string `gorm:"type:varchar(255)"`
+       Component    string `gorm:"type:varchar(500)"`
        ProjectKey   string `gorm:"index;type:varchar(255)"` //domain project 
key
        Line         int
        Status       string `gorm:"type:varchar(20)"`
diff --git a/backend/plugins/sonarqube/models/sonarqube_issue_code_block.go 
b/backend/plugins/sonarqube/models/sonarqube_issue_code_block.go
index 31236a16b..b5bb58bdd 100644
--- a/backend/plugins/sonarqube/models/sonarqube_issue_code_block.go
+++ b/backend/plugins/sonarqube/models/sonarqube_issue_code_block.go
@@ -23,7 +23,7 @@ type SonarqubeIssueCodeBlock struct {
        ConnectionId uint64 `gorm:"primaryKey"`
        Id           string `gorm:"primaryKey"`
        IssueKey     string `gorm:"index"`
-       Component    string `gorm:"index"`
+       Component    string `gorm:"index;type:varchar(500)"`
        StartLine    int
        EndLine      int
        StartOffset  int

Reply via email to