This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch release-v0.16
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.16 by this push:
new f13bd24fb fix: expand project key to 255 (#4744)
f13bd24fb is described below
commit f13bd24fb58915502b5f95ab14459ccec1f699b9
Author: Likyh <[email protected]>
AuthorDate: Wed Mar 22 20:42:16 2023 +0800
fix: expand project key to 255 (#4744)
---
.../20230321_expend_project_key.go | 160 +++++++++++++++++++++
.../sonarqube/models/migrationscripts/register.go | 1 +
.../plugins/sonarqube/models/sonarqube_issue.go | 2 +-
.../plugins/sonarqube/models/sonarqube_project.go | 4 +-
4 files changed, 164 insertions(+), 3 deletions(-)
diff --git
a/backend/plugins/sonarqube/models/migrationscripts/20230321_expend_project_key.go
b/backend/plugins/sonarqube/models/migrationscripts/20230321_expend_project_key.go
new file mode 100644
index 000000000..21a09e5b0
--- /dev/null
+++
b/backend/plugins/sonarqube/models/migrationscripts/20230321_expend_project_key.go
@@ -0,0 +1,160 @@
+/*
+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/errors"
+ "github.com/apache/incubator-devlake/core/models/common"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
+ "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+)
+
+type SonarqubeProject20230206Before struct {
+ common.NoPKModel `json:"-" mapstructure:"-"`
+ ConnectionId uint64 `json:"connectionId"
validate:"required" gorm:"primaryKey"`
+ ProjectKey string `json:"projectKey"
validate:"required" gorm:"type:varchar(64);primaryKey"`
+ Name string `json:"name" gorm:"type:varchar(255)"`
+ Qualifier string `json:"qualifier"
gorm:"type:varchar(255)"`
+ Visibility string `json:"visibility"
gorm:"type:varchar(64)"`
+ LastAnalysisDate *api.Iso8601Time `json:"lastAnalysisDate"`
+ Revision string `json:"revision"
gorm:"type:varchar(128)"`
+}
+
+func (SonarqubeProject20230206Before) TableName() string {
+ return "_tool_sonarqube_projects"
+}
+
+type SonarqubeProject20230206After struct {
+ common.NoPKModel `json:"-" mapstructure:"-"`
+ ConnectionId uint64 `json:"connectionId"
validate:"required" gorm:"primaryKey"`
+ ProjectKey string `json:"projectKey"
validate:"required" gorm:"type:varchar(255);primaryKey"` // expand this
+ Name string `json:"name" gorm:"type:varchar(255)"`
+ Qualifier string `json:"qualifier"
gorm:"type:varchar(255)"`
+ Visibility string `json:"visibility"
gorm:"type:varchar(64)"`
+ LastAnalysisDate *api.Iso8601Time `json:"lastAnalysisDate"`
+ Revision string `json:"revision"
gorm:"type:varchar(128)"`
+}
+
+func (SonarqubeProject20230206After) TableName() string {
+ return "_tool_sonarqube_projects"
+}
+
+type SonarqubeIssue20230206Before struct {
+ ConnectionId uint64 `gorm:"primaryKey"`
+ 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)"`
+ ProjectKey string `gorm:"index;type:varchar(100)"`
+ Line int
+ Status string `gorm:"type:varchar(20)"`
+ Message string
+ Debt int
+ Effort int
+ Author string `gorm:"type:varchar(100)"`
+ Hash string `gorm:"type:varchar(100)"`
+ Tags string
+ Type string `gorm:"type:varchar(100)"`
+ Scope string `gorm:"type:varchar(255)"`
+ StartLine int
+ EndLine int
+ StartOffset int
+ EndOffset int
+ CreationDate *api.Iso8601Time
+ UpdateDate *api.Iso8601Time
+ common.NoPKModel
+}
+
+func (SonarqubeIssue20230206Before) TableName() string {
+ return "_tool_sonarqube_issues"
+}
+
+type SonarqubeIssue20230206After struct {
+ ConnectionId uint64 `gorm:"primaryKey"`
+ 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)"`
+ ProjectKey string `gorm:"index;type:varchar(255)"` // expand this
+ Line int
+ Status string `gorm:"type:varchar(20)"`
+ Message string
+ Debt int
+ Effort int
+ Author string `gorm:"type:varchar(100)"`
+ Hash string `gorm:"type:varchar(100)"`
+ Tags string
+ Type string `gorm:"type:varchar(100)"`
+ Scope string `gorm:"type:varchar(255)"`
+ StartLine int
+ EndLine int
+ StartOffset int
+ EndOffset int
+ CreationDate *api.Iso8601Time
+ UpdateDate *api.Iso8601Time
+ common.NoPKModel
+}
+
+func (SonarqubeIssue20230206After) TableName() string {
+ return "_tool_sonarqube_issues"
+}
+
+type expandProjectKey20230206 struct{}
+
+func (script *expandProjectKey20230206) Up(basicRes context.BasicRes)
errors.Error {
+ // expand `ProjectKey` from varchar(64) to varchar(255)
+ err := migrationhelper.TransformTable(
+ basicRes,
+ script,
+ "_tool_sonarqube_projects",
+ func(s *SonarqubeProject20230206Before)
(*SonarqubeProject20230206After, errors.Error) {
+ dst := (*SonarqubeProject20230206After)(s)
+ return dst, nil
+ },
+ )
+ if err != nil {
+ return err
+ }
+
+ // expand `ProjectKey` from varchar(100) to varchar(255)
+ err = migrationhelper.TransformTable(
+ basicRes,
+ script,
+ "_tool_sonarqube_issues",
+ func(s *SonarqubeIssue20230206Before)
(*SonarqubeIssue20230206After, errors.Error) {
+ dst := (*SonarqubeIssue20230206After)(s)
+ return dst, nil
+ },
+ )
+ if err != nil {
+ return err
+ }
+
+ // also, SonarqubeFileMetrics and SonarqubeHotspot have ProjectKey.
+ // But I think varchar(191) in mysql and text in pg is enough.
+ return nil
+}
+
+func (*expandProjectKey20230206) Version() uint64 {
+ return 20230321000003
+}
+
+func (*expandProjectKey20230206) Name() string {
+ return "expend project_key"
+}
diff --git a/backend/plugins/sonarqube/models/migrationscripts/register.go
b/backend/plugins/sonarqube/models/migrationscripts/register.go
index 63e8bcc23..cbae40708 100644
--- a/backend/plugins/sonarqube/models/migrationscripts/register.go
+++ b/backend/plugins/sonarqube/models/migrationscripts/register.go
@@ -24,5 +24,6 @@ func All() []plugin.MigrationScript {
return []plugin.MigrationScript{
new(addInitTables),
new(modifyCharacterSet),
+ new(expandProjectKey20230206),
}
}
diff --git a/backend/plugins/sonarqube/models/sonarqube_issue.go
b/backend/plugins/sonarqube/models/sonarqube_issue.go
index d822a256c..7e147ecec 100644
--- a/backend/plugins/sonarqube/models/sonarqube_issue.go
+++ b/backend/plugins/sonarqube/models/sonarqube_issue.go
@@ -28,7 +28,7 @@ type SonarqubeIssue struct {
Rule string `gorm:"type:varchar(255)"`
Severity string `gorm:"type:varchar(100)"`
Component string `gorm:"type:varchar(255)"`
- ProjectKey string `gorm:"index;type:varchar(100)"` //domain project
key
+ ProjectKey string `gorm:"index;type:varchar(255)"` //domain project
key
Line int
Status string `gorm:"type:varchar(20)"`
Message string
diff --git a/backend/plugins/sonarqube/models/sonarqube_project.go
b/backend/plugins/sonarqube/models/sonarqube_project.go
index 90616b821..58b35cab2 100644
--- a/backend/plugins/sonarqube/models/sonarqube_project.go
+++ b/backend/plugins/sonarqube/models/sonarqube_project.go
@@ -24,8 +24,8 @@ import (
type SonarqubeProject struct {
common.NoPKModel `json:"-" mapstructure:"-"`
- ConnectionId uint64 `json:"connectionId"
gorm:"primaryKey"`
- ProjectKey string `json:"projectKey"
gorm:"type:varchar(64);primaryKey"`
+ ConnectionId uint64 `json:"connectionId"
validate:"required" gorm:"primaryKey"`
+ ProjectKey string `json:"projectKey"
validate:"required" gorm:"type:varchar(255);primaryKey"`
Name string `json:"name" gorm:"type:varchar(255)"`
Qualifier string `json:"qualifier"
gorm:"type:varchar(255)"`
Visibility string `json:"visibility"
gorm:"type:varchar(64)"`