Skip to content

Commit 18e7d30

Browse files
authored
Merge branch 'apache:main' into main
2 parents 8576667 + 27c771a commit 18e7d30

18 files changed

Lines changed: 514 additions & 2 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import "github.com/apache/incubator-devlake/core/models/domainlayer"
2222
type CqIssueCodeBlock struct {
2323
domainlayer.DomainEntity
2424
IssueKey string `json:"key" gorm:"index"`
25-
Component string `gorm:"index"`
25+
Component string `gorm:"type:text"`
2626
StartLine int
2727
EndLine int
2828
StartOffset int
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 = (*changeIssueComponentToText)(nil)
27+
28+
type changeIssueComponentToText struct{}
29+
30+
func (*changeIssueComponentToText) Up(basicRes context.BasicRes) errors.Error {
31+
// The 20240813 migration targeted the non-existent plural "components" column.
32+
return basicRes.GetDal().ModifyColumnType("issues", "component", "text")
33+
}
34+
35+
func (*changeIssueComponentToText) Version() uint64 {
36+
return 20260629120000
37+
}
38+
39+
func (*changeIssueComponentToText) Name() string {
40+
return "change issues.component type to text"
41+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
"testing"
22+
23+
"github.com/apache/incubator-devlake/core/context"
24+
"github.com/apache/incubator-devlake/core/dal"
25+
"github.com/apache/incubator-devlake/core/errors"
26+
)
27+
28+
type modifyColumnTypeCall struct {
29+
tableName string
30+
columnName string
31+
columnType string
32+
}
33+
34+
type recordingDal struct {
35+
dal.Dal
36+
call *modifyColumnTypeCall
37+
}
38+
39+
func (d *recordingDal) ModifyColumnType(tableName string, columnName string, columnType string) errors.Error {
40+
d.call = &modifyColumnTypeCall{tableName, columnName, columnType}
41+
return nil
42+
}
43+
44+
type basicResWithDal struct {
45+
context.BasicRes
46+
database dal.Dal
47+
}
48+
49+
func (r *basicResWithDal) GetDal() dal.Dal {
50+
return r.database
51+
}
52+
53+
func TestChangeIssueComponentToText(t *testing.T) {
54+
database := new(recordingDal)
55+
script := new(changeIssueComponentToText)
56+
57+
if err := script.Up(&basicResWithDal{database: database}); err != nil {
58+
t.Fatalf("migration failed: %v", err)
59+
}
60+
61+
want := &modifyColumnTypeCall{"issues", "component", "text"}
62+
if database.call == nil || *database.call != *want {
63+
t.Fatalf("ModifyColumnType call = %#v, want %#v", database.call, want)
64+
}
65+
if script.Version() != 20260629120000 {
66+
t.Fatalf("Version() = %d, want 20260629120000", script.Version())
67+
}
68+
if script.Name() != "change issues.component type to text" {
69+
t.Fatalf("Name() = %q, want %q", script.Name(), "change issues.component type to text")
70+
}
71+
72+
found := false
73+
for _, registeredScript := range All() {
74+
if registeredScript.Version() == script.Version() {
75+
found = true
76+
break
77+
}
78+
}
79+
if !found {
80+
t.Fatalf("migration version %d is not registered", script.Version())
81+
}
82+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 = (*changeCqIssueCodeBlocksComponentToText)(nil)
27+
28+
type changeCqIssueCodeBlocksComponentToText struct{}
29+
30+
func (script *changeCqIssueCodeBlocksComponentToText) Up(basicRes context.BasicRes) errors.Error {
31+
db := basicRes.GetDal()
32+
if err := db.DropIndexes("cq_issue_code_blocks", "idx_cq_issue_code_blocks_component"); err != nil {
33+
return err
34+
}
35+
return db.ModifyColumnType("cq_issue_code_blocks", "component", "text")
36+
}
37+
38+
func (*changeCqIssueCodeBlocksComponentToText) Version() uint64 {
39+
return 20260701000000
40+
}
41+
42+
func (*changeCqIssueCodeBlocksComponentToText) Name() string {
43+
return "change cq_issue_code_blocks.component type to text"
44+
}

backend/core/models/migrationscripts/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func All() []plugin.MigrationScript {
145145
new(modifyCicdDeploymentsToText),
146146
new(increaseCqIssuesProjectKeyLength),
147147
new(addAuthSessions),
148+
new(changeIssueComponentToText),
149+
new(changeCqIssueCodeBlocksComponentToText),
148150
new(addCqProjectMetricsHistory),
149151
}
150152
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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/helpers/migrationhelper"
24+
)
25+
26+
type jiraIssue20260707 struct {
27+
FixVersions string `gorm:"type:text;column:fix_versions"`
28+
}
29+
30+
func (jiraIssue20260707) TableName() string {
31+
return "_tool_jira_issues"
32+
}
33+
34+
type changeFixVersionsToText20260707 struct{}
35+
36+
func (script *changeFixVersionsToText20260707) Up(basicRes context.BasicRes) errors.Error {
37+
return migrationhelper.AutoMigrateTables(basicRes, &jiraIssue20260707{})
38+
}
39+
40+
func (*changeFixVersionsToText20260707) Version() uint64 {
41+
return 20260707140000
42+
}
43+
44+
func (*changeFixVersionsToText20260707) Name() string {
45+
return "change fix_versions type to text in _tool_jira_issues"
46+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func All() []plugin.MigrationScript {
5656
new(updateScopeConfig),
5757
new(addFixVersions20250619),
5858
new(addSubQueryToBoards),
59+
new(changeFixVersionsToText20260707),
5960
new(addExtraJQLToScopeConfig),
6061
}
6162
}

0 commit comments

Comments
 (0)