Skip to content

Commit abfab8b

Browse files
committed
refactor(codequality): extend field size for CQ and SonarQube
- Increase CqFileMetrics.FileName to varchar(2000) - Increase CqProject.Name to varchar(2000) - Increase CqFileMetrics.Id to varchar(3000) - Increase SonarqubeFileMetrics.FileMetricsKey to varchar(3000) - Increase SonarqubeFileMetrics.FileName to varchar(2000) These changes accommodate longer file names and identifiers in modern projects.
1 parent 111a687 commit abfab8b

8 files changed

Lines changed: 109 additions & 10 deletions

File tree

backend/core/models/domainlayer/codequality/cq_file_metrics.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ limitations under the License.
1818
package codequality
1919

2020
import (
21-
"github.com/apache/incubator-devlake/core/models/domainlayer"
21+
"github.com/apache/incubator-devlake/core/models/common"
2222
)
2323

2424
type CqFileMetrics struct {
25-
domainlayer.DomainEntity
26-
ProjectKey string `gorm:"index;type:varchar(255)"` //domain project key
27-
FileName string `gorm:"type:varchar(255)"`
25+
common.NoPKModel
26+
Id string `json:"id" gorm:"primaryKey;type:varchar(767);comment:This key is generated based on details from the original plugin"` // format: <Plugin>:<Entity>:<PK0>:<PK1>
27+
ProjectKey string `gorm:"index;type:varchar(255)"` //domain project key
28+
FileName string `gorm:"type:varchar(2000)"`
2829
FilePath string
2930
FileLanguage string `gorm:"type:varchar(20)"`
3031
CodeSmells int

backend/core/models/domainlayer/codequality/cq_projects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var _ plugin.Scope = (*CqProject)(nil)
2727

2828
type CqProject struct {
2929
domainlayer.DomainEntityExtended
30-
Name string `gorm:"type:varchar(255)"`
30+
Name string `gorm:"type:varchar(2000)"`
3131
Qualifier string `gorm:"type:varchar(255)"`
3232
Visibility string `gorm:"type:varchar(64)"`
3333
LastAnalysisDate *common.Iso8601Time
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
)
25+
26+
var _ plugin.MigrationScript = (*extendFieldSizeForCq)(nil)
27+
28+
type extendFieldSizeForCq struct{}
29+
30+
func (script *extendFieldSizeForCq) Up(basicRes context.BasicRes) errors.Error {
31+
err := basicRes.GetDal().ModifyColumnType("cq_projects", "name", "varchar(2000)")
32+
if err != nil {
33+
return err
34+
}
35+
err = basicRes.GetDal().ModifyColumnType("cq_file_metrics", "file_name", "varchar(2000)")
36+
if err != nil {
37+
return err
38+
}
39+
return basicRes.GetDal().ModifyColumnType("cq_file_metrics", "id", "varchar(767)")
40+
}
41+
42+
func (*extendFieldSizeForCq) Version() uint64 {
43+
return 20250527000000
44+
}
45+
46+
func (*extendFieldSizeForCq) Name() string {
47+
return "extend field size for cq"
48+
}

backend/core/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,6 @@ func All() []plugin.MigrationScript {
137137
new(addDueDateToIssues),
138138
new(createQaTables),
139139
new(increaseCqIssueComponentLength),
140+
new(extendFieldSizeForCq),
140141
}
141142
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
)
25+
26+
var _ plugin.MigrationScript = (*extendSonarqubeFieldSize)(nil)
27+
28+
type extendSonarqubeFieldSize struct{}
29+
30+
func (script *extendSonarqubeFieldSize) Up(basicRes context.BasicRes) errors.Error {
31+
db := basicRes.GetDal()
32+
33+
err := db.ModifyColumnType("_tool_sonarqube_file_metrics", "file_metrics_key", "varchar(3000)")
34+
if err != nil {
35+
return err
36+
}
37+
38+
err = db.ModifyColumnType("_tool_sonarqube_file_metrics", "file_name", "varchar(2000)")
39+
return err
40+
}
41+
42+
func (*extendSonarqubeFieldSize) Version() uint64 {
43+
return 20250527000000
44+
}
45+
46+
func (*extendSonarqubeFieldSize) Name() string {
47+
return "extend field size for sonarqube file metrics"
48+
}

backend/plugins/sonarqube/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ func All() []plugin.MigrationScript {
3838
new(increaseProjectKeyLength),
3939
new(addOrgToConn),
4040
new(addIssueImpacts),
41+
new(extendSonarqubeFieldSize),
4142
}
4243
}

backend/plugins/sonarqube/models/sonarqube_file_metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323

2424
type SonarqubeFileMetrics struct {
2525
ConnectionId uint64 `gorm:"primaryKey"`
26-
FileMetricsKey string `gorm:"primaryKey;type:varchar(500)"`
26+
FileMetricsKey string `gorm:"primaryKey;type:varchar(3000)"`
2727
ProjectKey string `gorm:"index"`
28-
FileName string
28+
FileName string `gorm:"type:varchar(2000)"`
2929
FilePath string
3030
FileLanguage string
3131
CodeSmells int

backend/plugins/sonarqube/tasks/filemetrics_convertor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ limitations under the License.
1818
package tasks
1919

2020
import (
21+
"reflect"
22+
2123
"github.com/apache/incubator-devlake/core/dal"
2224
"github.com/apache/incubator-devlake/core/errors"
23-
"github.com/apache/incubator-devlake/core/models/domainlayer"
2425
"github.com/apache/incubator-devlake/core/models/domainlayer/codequality"
2526
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
2627
"github.com/apache/incubator-devlake/core/plugin"
2728
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
2829
sonarqubeModels "github.com/apache/incubator-devlake/plugins/sonarqube/models"
29-
"reflect"
3030
)
3131

3232
var ConvertFileMetricsMeta = plugin.SubTaskMeta{
@@ -56,7 +56,7 @@ func ConvertFileMetrics(taskCtx plugin.SubTaskContext) errors.Error {
5656
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
5757
sonarqubeFileMetric := inputRow.(*sonarqubeModels.SonarqubeWholeFileMetrics)
5858
domainFileMetric := &codequality.CqFileMetrics{
59-
DomainEntity: domainlayer.DomainEntity{Id: issueIdGen.Generate(data.Options.ConnectionId, sonarqubeFileMetric.FileMetricsKey)},
59+
Id: issueIdGen.Generate(data.Options.ConnectionId, sonarqubeFileMetric.FileMetricsKey),
6060
ProjectKey: projectIdGen.Generate(data.Options.ConnectionId, sonarqubeFileMetric.ProjectKey),
6161
FileName: sonarqubeFileMetric.FileName,
6262
FilePath: sonarqubeFileMetric.FilePath,

0 commit comments

Comments
 (0)