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

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


The following commit(s) were added to refs/heads/main by this push:
     new 672adb01e fix: component length scripts are not working (#7900)
672adb01e is described below

commit 672adb01ee47ce2f3d22507b9aabd0c88e719325
Author: Klesh Wong <[email protected]>
AuthorDate: Thu Aug 15 17:10:36 2024 +0800

    fix: component length scripts are not working (#7900)
---
 backend/core/dal/dal.go                                             | 4 +++-
 backend/impls/dalgorm/dalgorm.go                                    | 6 ++++++
 .../models/migrationscripts/20240813_change_issue_component_type.go | 4 ++--
 .../models/migrationscripts/20240813_change_issue_component_type.go | 4 ++--
 .../models/migrationscripts/20240813_change_issue_component_type.go | 4 ++--
 .../models/migrationscripts/20240813_change_issue_component_type.go | 4 ++--
 .../models/migrationscripts/20240813_change_issue_component_type.go | 6 ++++--
 7 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/backend/core/dal/dal.go b/backend/core/dal/dal.go
index d5f4fbfea..6523a54e6 100644
--- a/backend/core/dal/dal.go
+++ b/backend/core/dal/dal.go
@@ -169,8 +169,10 @@ type Dal interface {
        RenameColumn(table, oldColumnName, newColumnName string) errors.Error
        // ModifyColumnType modifies column type
        ModifyColumnType(table, columnName, columnType string) errors.Error
-       // DropIndexes drops all specified tables
+       // DropIndexes drops indexes by their name
        DropIndexes(table string, indexes ...string) errors.Error
+       // DropIndex drops the index of specified column names
+       DropIndex(table string, columnNames ...string) errors.Error
        // Dialect returns the dialect of current database
        Dialect() string
        // Session creates a new manual session for special scenarios
diff --git a/backend/impls/dalgorm/dalgorm.go b/backend/impls/dalgorm/dalgorm.go
index 59e6b115f..3b11312a3 100644
--- a/backend/impls/dalgorm/dalgorm.go
+++ b/backend/impls/dalgorm/dalgorm.go
@@ -461,6 +461,12 @@ func (d *Dalgorm) DropIndexes(table string, indexNames 
...string) errors.Error {
        return nil
 }
 
+// DropIndexes drops the index of specified columns
+func (d *Dalgorm) DropIndex(table string, columnNames ...string) errors.Error {
+       indexName := fmt.Sprintf("idx_%s_%s", table, strings.Join(columnNames, 
"_"))
+       return d.DropIndexes(table, indexName)
+}
+
 // Dialect returns the dialect of the database
 func (d *Dalgorm) Dialect() string {
        return d.db.Dialector.Name()
diff --git 
a/backend/plugins/bitbucket/models/migrationscripts/20240813_change_issue_component_type.go
 
b/backend/plugins/bitbucket/models/migrationscripts/20240813_change_issue_component_type.go
index 0499d0ac2..902fa0850 100644
--- 
a/backend/plugins/bitbucket/models/migrationscripts/20240813_change_issue_component_type.go
+++ 
b/backend/plugins/bitbucket/models/migrationscripts/20240813_change_issue_component_type.go
@@ -28,7 +28,7 @@ var _ plugin.MigrationScript = 
(*changeIssueComponentType)(nil)
 type changeIssueComponentType struct{}
 
 func (script *changeIssueComponentType) Up(basicRes context.BasicRes) 
errors.Error {
-       return basicRes.GetDal().ModifyColumnType("_tool_bitbucket_issues", 
"components", "text")
+       return basicRes.GetDal().ModifyColumnType("_tool_bitbucket_issues", 
"component", "text")
 }
 
 func (*changeIssueComponentType) Version() uint64 {
@@ -36,5 +36,5 @@ func (*changeIssueComponentType) Version() uint64 {
 }
 
 func (*changeIssueComponentType) Name() string {
-       return "change _tool_bitbucket_issues.components type to text"
+       return "change _tool_bitbucket_issues.component type to text"
 }
diff --git 
a/backend/plugins/gitee/models/migrationscripts/20240813_change_issue_component_type.go
 
b/backend/plugins/gitee/models/migrationscripts/20240813_change_issue_component_type.go
index a669a31dd..47eb0a185 100644
--- 
a/backend/plugins/gitee/models/migrationscripts/20240813_change_issue_component_type.go
+++ 
b/backend/plugins/gitee/models/migrationscripts/20240813_change_issue_component_type.go
@@ -28,7 +28,7 @@ var _ plugin.MigrationScript = 
(*changeIssueComponentType)(nil)
 type changeIssueComponentType struct{}
 
 func (script *changeIssueComponentType) Up(basicRes context.BasicRes) 
errors.Error {
-       return basicRes.GetDal().ModifyColumnType("_tool_gitee_issues", 
"components", "text")
+       return basicRes.GetDal().ModifyColumnType("_tool_gitee_issues", 
"component", "text")
 }
 
 func (*changeIssueComponentType) Version() uint64 {
@@ -36,5 +36,5 @@ func (*changeIssueComponentType) Version() uint64 {
 }
 
 func (*changeIssueComponentType) Name() string {
-       return "change _tool_gitee_issues.components type to text"
+       return "change _tool_gitee_issues.component type to text"
 }
diff --git 
a/backend/plugins/github/models/migrationscripts/20240813_change_issue_component_type.go
 
b/backend/plugins/github/models/migrationscripts/20240813_change_issue_component_type.go
index be5a3be12..c31e30af9 100644
--- 
a/backend/plugins/github/models/migrationscripts/20240813_change_issue_component_type.go
+++ 
b/backend/plugins/github/models/migrationscripts/20240813_change_issue_component_type.go
@@ -28,7 +28,7 @@ var _ plugin.MigrationScript = 
(*changeIssueComponentType)(nil)
 type changeIssueComponentType struct{}
 
 func (script *changeIssueComponentType) Up(basicRes context.BasicRes) 
errors.Error {
-       return basicRes.GetDal().ModifyColumnType("_tool_github_issues", 
"components", "text")
+       return basicRes.GetDal().ModifyColumnType("_tool_github_issues", 
"component", "text")
 }
 
 func (*changeIssueComponentType) Version() uint64 {
@@ -36,5 +36,5 @@ func (*changeIssueComponentType) Version() uint64 {
 }
 
 func (*changeIssueComponentType) Name() string {
-       return "change _tool_github_issues.components type to text"
+       return "change _tool_github_issues.component type to text"
 }
diff --git 
a/backend/plugins/gitlab/models/migrationscripts/20240813_change_issue_component_type.go
 
b/backend/plugins/gitlab/models/migrationscripts/20240813_change_issue_component_type.go
index 08c88ac29..a4cb8983c 100644
--- 
a/backend/plugins/gitlab/models/migrationscripts/20240813_change_issue_component_type.go
+++ 
b/backend/plugins/gitlab/models/migrationscripts/20240813_change_issue_component_type.go
@@ -28,7 +28,7 @@ var _ plugin.MigrationScript = 
(*changeIssueComponentType)(nil)
 type changeIssueComponentType struct{}
 
 func (script *changeIssueComponentType) Up(basicRes context.BasicRes) 
errors.Error {
-       return basicRes.GetDal().ModifyColumnType("_tool_gitlab_issues", 
"components", "text")
+       return basicRes.GetDal().ModifyColumnType("_tool_gitlab_issues", 
"component", "text")
 }
 
 func (*changeIssueComponentType) Version() uint64 {
@@ -36,5 +36,5 @@ func (*changeIssueComponentType) Version() uint64 {
 }
 
 func (*changeIssueComponentType) Name() string {
-       return "change _tool_gitlab_issues.components type to text"
+       return "change _tool_gitlab_issues.component type to text"
 }
diff --git 
a/backend/plugins/sonarqube/models/migrationscripts/20240813_change_issue_component_type.go
 
b/backend/plugins/sonarqube/models/migrationscripts/20240813_change_issue_component_type.go
index eb7e713c8..45fd5c3fb 100644
--- 
a/backend/plugins/sonarqube/models/migrationscripts/20240813_change_issue_component_type.go
+++ 
b/backend/plugins/sonarqube/models/migrationscripts/20240813_change_issue_component_type.go
@@ -28,7 +28,9 @@ var _ plugin.MigrationScript = 
(*changeIssueComponentType)(nil)
 type changeIssueComponentType struct{}
 
 func (script *changeIssueComponentType) Up(basicRes context.BasicRes) 
errors.Error {
-       return basicRes.GetDal().ModifyColumnType("_tool_sonarqube_issues", 
"components", "text")
+       db := basicRes.GetDal()
+       errors.Must(db.DropIndex("_tool_sonarqube_issues", "component"))
+       return db.ModifyColumnType("_tool_sonarqube_issues", "component", 
"text")
 }
 
 func (*changeIssueComponentType) Version() uint64 {
@@ -36,5 +38,5 @@ func (*changeIssueComponentType) Version() uint64 {
 }
 
 func (*changeIssueComponentType) Name() string {
-       return "change _tool_sonarqube_issues.components type to text"
+       return "change _tool_sonarqube_issues.component type to text"
 }

Reply via email to