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

klesh pushed a commit to branch kw-7852-components-field-length
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 4eeca4d1fd08f3ff551dabbb55d3098170133e65
Author: Klesh Wong <[email protected]>
AuthorDate: Mon Aug 12 17:20:24 2024 +0800

    fix: change jira issue component field to text type
---
 backend/core/dal/dal.go                            |  2 ++
 backend/impls/dalgorm/dalgorm.go                   | 19 ++++++++++
 .../20240809_change_issue_component_type.go        | 40 ++++++++++++++++++++++
 .../jira/models/migrationscripts/register.go       |  1 +
 4 files changed, 62 insertions(+)

diff --git a/backend/core/dal/dal.go b/backend/core/dal/dal.go
index 48cc36010..d5f4fbfea 100644
--- a/backend/core/dal/dal.go
+++ b/backend/core/dal/dal.go
@@ -167,6 +167,8 @@ type Dal interface {
        GetPrimaryKeyFields(t reflect.Type) []reflect.StructField
        // RenameColumn renames column name for specified table
        RenameColumn(table, oldColumnName, newColumnName string) errors.Error
+       // ModifyColumnType modifies column type
+       ModifyColumnType(table, columnName, columnType string) errors.Error
        // DropIndexes drops all specified tables
        DropIndexes(table string, indexes ...string) errors.Error
        // Dialect returns the dialect of current database
diff --git a/backend/impls/dalgorm/dalgorm.go b/backend/impls/dalgorm/dalgorm.go
index ba3bcdb61..7812d94dc 100644
--- a/backend/impls/dalgorm/dalgorm.go
+++ b/backend/impls/dalgorm/dalgorm.go
@@ -372,6 +372,25 @@ func (d *Dalgorm) RenameColumn(table, oldColumnName, 
newColumnName string) error
        )
 }
 
+// ModifyColumnType modify column type
+func (d *Dalgorm) ModifyColumnType(table, columnName, columnType string) 
errors.Error {
+       // work around the error `cached plan must not change result type` for 
postgres
+       // wrap in func(){} to make the linter happy
+       defer func() {
+               _ = d.Exec("SELECT * FROM ? LIMIT 1", clause.Table{Name: table})
+       }()
+       sql := "ALTER TABLE ? MODIFY COLUMN ? ?"
+       if d.db.Dialector.Name() == "postgres" {
+               sql = "ALTER TABLE ? ALTER COLUMN ? TYPE ?"
+       }
+       return d.Exec(
+               sql,
+               clause.Table{Name: table},
+               clause.Column{Name: columnName},
+               clause.Column{Name: columnType},
+       )
+}
+
 // AllTables returns all tables in the database
 func (d *Dalgorm) AllTables() ([]string, errors.Error) {
        var tableSql string
diff --git 
a/backend/plugins/jira/models/migrationscripts/20240809_change_issue_component_type.go
 
b/backend/plugins/jira/models/migrationscripts/20240809_change_issue_component_type.go
new file mode 100644
index 000000000..30329085c
--- /dev/null
+++ 
b/backend/plugins/jira/models/migrationscripts/20240809_change_issue_component_type.go
@@ -0,0 +1,40 @@
+/*
+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/plugin"
+)
+
+var _ plugin.MigrationScript = (*changeIssueComponentType)(nil)
+
+type changeIssueComponentType struct{}
+
+func (script *changeIssueComponentType) Up(basicRes context.BasicRes) 
errors.Error {
+       return basicRes.GetDal().ModifyColumnType("_tool_jira_issues", 
"components", "text")
+}
+
+func (*changeIssueComponentType) Version() uint64 {
+       return 20240809165545
+}
+
+func (*changeIssueComponentType) Name() string {
+       return "change jira_issue.components type to text"
+}
diff --git a/backend/plugins/jira/models/migrationscripts/register.go 
b/backend/plugins/jira/models/migrationscripts/register.go
index f2764ef42..6b7b89f84 100644
--- a/backend/plugins/jira/models/migrationscripts/register.go
+++ b/backend/plugins/jira/models/migrationscripts/register.go
@@ -51,5 +51,6 @@ func All() []plugin.MigrationScript {
                new(addSubtaskToIssue),
                new(addTmpAccountIdToJiraIssueChangelogItem),
                new(addIssueFieldTable),
+               new(changeIssueComponentType),
        }
 }

Reply via email to