You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/10/27 05:48:50 UTC

[incubator-devlake] branch main updated: fix: missing connectionId from tapd labels (#6350)

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 09efea7f1 fix: missing connectionId from tapd labels (#6350)
09efea7f1 is described below

commit 09efea7f1de5d255d7b7faacfb179a2d7f2bedb7
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Fri Oct 27 13:48:46 2023 +0800

    fix: missing connectionId from tapd labels (#6350)
---
 backend/plugins/tapd/models/bug_label.go           |  5 +-
 .../20231026_add_connection_id_to_labels.go        | 81 ++++++++++++++++++++++
 .../tapd/models/migrationscripts/register.go       |  1 +
 backend/plugins/tapd/models/story_label.go         |  5 +-
 backend/plugins/tapd/models/task_label.go          |  5 +-
 .../plugins/tapd/tasks/bug_changelog_converter.go  | 13 ++--
 backend/plugins/tapd/tasks/bug_label_convertor.go  | 12 ++--
 .../plugins/tapd/tasks/story_label_convertor.go    | 12 ++--
 .../plugins/tapd/tasks/task_changelog_converter.go | 13 ++--
 backend/plugins/tapd/tasks/task_label_convertor.go | 12 ++--
 10 files changed, 123 insertions(+), 36 deletions(-)

diff --git a/backend/plugins/tapd/models/bug_label.go b/backend/plugins/tapd/models/bug_label.go
index b866eee14..4cd61654c 100644
--- a/backend/plugins/tapd/models/bug_label.go
+++ b/backend/plugins/tapd/models/bug_label.go
@@ -22,8 +22,9 @@ import (
 )
 
 type TapdBugLabel struct {
-	BugId     uint64 `gorm:"primaryKey;autoIncrement:false"`
-	LabelName string `gorm:"primaryKey;type:varchar(255)"`
+	ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"`
+	BugId        uint64 `gorm:"primaryKey;autoIncrement:false"`
+	LabelName    string `gorm:"primaryKey;type:varchar(255)"`
 	common.NoPKModel
 }
 
diff --git a/backend/plugins/tapd/models/migrationscripts/20231026_add_connection_id_to_labels.go b/backend/plugins/tapd/models/migrationscripts/20231026_add_connection_id_to_labels.go
new file mode 100644
index 000000000..834305109
--- /dev/null
+++ b/backend/plugins/tapd/models/migrationscripts/20231026_add_connection_id_to_labels.go
@@ -0,0 +1,81 @@
+/*
+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/migrationscripts/archived"
+	"github.com/apache/incubator-devlake/core/plugin"
+	"github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+var _ plugin.MigrationScript = (*addConnIdToLabels)(nil)
+
+type buglabel20231026 struct {
+	ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"`
+	BugId        uint64 `gorm:"primaryKey;autoIncrement:false"`
+	LabelName    string `gorm:"primaryKey;type:varchar(255)"`
+	archived.NoPKModel
+}
+
+type storylabel20231026 struct {
+	ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"`
+	StoryId      uint64 `gorm:"primaryKey;autoIncrement:false"`
+	LabelName    string `gorm:"primaryKey;type:varchar(255)"`
+	archived.NoPKModel
+}
+
+type tasklabel20231026 struct {
+	ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"`
+	TaskId       uint64 `gorm:"primaryKey;autoIncrement:false"`
+	LabelName    string `gorm:"primaryKey;type:varchar(255)"`
+	archived.NoPKModel
+}
+
+func (buglabel20231026) TableName() string {
+	return "_tool_tapd_bug_labels"
+}
+
+func (storylabel20231026) TableName() string {
+	return "_tool_tapd_story_labels"
+}
+
+func (tasklabel20231026) TableName() string {
+	return "_tool_tapd_task_labels"
+}
+
+type addConnIdToLabels struct{}
+
+func (script *addConnIdToLabels) Up(basicRes context.BasicRes) errors.Error {
+	tables := []interface{}{&buglabel20231026{}, &storylabel20231026{}, &tasklabel20231026{}}
+	db := basicRes.GetDal()
+	err := db.DropTables(tables...)
+	if err != nil {
+		return err
+	}
+	return migrationhelper.AutoMigrateTables(basicRes, tables...)
+}
+
+func (*addConnIdToLabels) Version() uint64 {
+	return 20231026000002
+}
+
+func (script *addConnIdToLabels) Name() string {
+	return "add ConnectionId to Labels tables"
+}
diff --git a/backend/plugins/tapd/models/migrationscripts/register.go b/backend/plugins/tapd/models/migrationscripts/register.go
index c2a99a547..cd4f5d3a5 100644
--- a/backend/plugins/tapd/models/migrationscripts/register.go
+++ b/backend/plugins/tapd/models/migrationscripts/register.go
@@ -32,5 +32,6 @@ func All() []plugin.MigrationScript {
 		new(addCustomFieldValue),
 		new(renameTr2ScopeConfig),
 		new(addRawParamTableForScope),
+		new(addConnIdToLabels),
 	}
 }
diff --git a/backend/plugins/tapd/models/story_label.go b/backend/plugins/tapd/models/story_label.go
index 566b5682a..e8ff80f12 100644
--- a/backend/plugins/tapd/models/story_label.go
+++ b/backend/plugins/tapd/models/story_label.go
@@ -22,8 +22,9 @@ import (
 )
 
 type TapdStoryLabel struct {
-	StoryId   uint64 `gorm:"primaryKey;autoIncrement:false"`
-	LabelName string `gorm:"primaryKey;type:varchar(255)"`
+	ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"`
+	StoryId      uint64 `gorm:"primaryKey;autoIncrement:false"`
+	LabelName    string `gorm:"primaryKey;type:varchar(255)"`
 	common.NoPKModel
 }
 
diff --git a/backend/plugins/tapd/models/task_label.go b/backend/plugins/tapd/models/task_label.go
index 404dad7fc..337c7c92b 100644
--- a/backend/plugins/tapd/models/task_label.go
+++ b/backend/plugins/tapd/models/task_label.go
@@ -22,8 +22,9 @@ import (
 )
 
 type TapdTaskLabel struct {
-	TaskId    uint64 `gorm:"primaryKey;autoIncrement:false"`
-	LabelName string `gorm:"primaryKey;type:varchar(255)"`
+	ConnectionId uint64 `gorm:"primaryKey;autoIncrement:false"`
+	TaskId       uint64 `gorm:"primaryKey;autoIncrement:false"`
+	LabelName    string `gorm:"primaryKey;type:varchar(255)"`
 	common.NoPKModel
 }
 
diff --git a/backend/plugins/tapd/tasks/bug_changelog_converter.go b/backend/plugins/tapd/tasks/bug_changelog_converter.go
index 89f537314..3d87497b3 100644
--- a/backend/plugins/tapd/tasks/bug_changelog_converter.go
+++ b/backend/plugins/tapd/tasks/bug_changelog_converter.go
@@ -18,6 +18,9 @@ limitations under the License.
 package tasks
 
 import (
+	"reflect"
+	"time"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/common"
@@ -27,8 +30,6 @@ import (
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/tapd/models"
-	"reflect"
-	"time"
 )
 
 type BugChangelogItemResult struct {
@@ -65,10 +66,10 @@ func ConvertBugChangelog(taskCtx plugin.SubTaskContext) errors.Error {
 	clIterIdGen := didgen.NewDomainIdGenerator(&models.TapdIteration{})
 	clIdGen := didgen.NewDomainIdGenerator(&models.TapdBugChangelog{})
 	clauses := []dal.Clause{
-		dal.Select("tc.created, tc.id, tc.workspace_id, tc.bug_id, tc.author, _tool_tapd_bug_changelog_items.*"),
-		dal.From(&models.TapdBugChangelogItem{}),
-		dal.Join("left join _tool_tapd_bug_changelogs tc on tc.id = _tool_tapd_bug_changelog_items.changelog_id "),
-		dal.Where("tc.connection_id = ? AND tc.workspace_id = ?", data.Options.ConnectionId, data.Options.WorkspaceId),
+		dal.Select("c.created, c.id, c.workspace_id, c.bug_id, c.author, i.*"),
+		dal.From("_tool_tapd_bug_changelog_items i"),
+		dal.Join("left join _tool_tapd_bug_changelogs c on c.id = i.changelog_id AND c.connection_id = i.connection_id"),
+		dal.Where("c.connection_id = ? AND c.workspace_id = ?", data.Options.ConnectionId, data.Options.WorkspaceId),
 		dal.Orderby("created DESC"),
 	}
 
diff --git a/backend/plugins/tapd/tasks/bug_label_convertor.go b/backend/plugins/tapd/tasks/bug_label_convertor.go
index d41aef91c..6c6f65b94 100644
--- a/backend/plugins/tapd/tasks/bug_label_convertor.go
+++ b/backend/plugins/tapd/tasks/bug_label_convertor.go
@@ -18,6 +18,8 @@ limitations under the License.
 package tasks
 
 import (
+	"reflect"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
@@ -25,7 +27,6 @@ import (
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/tapd/models"
-	"reflect"
 )
 
 var ConvertBugLabelsMeta = plugin.SubTaskMeta{
@@ -40,11 +41,10 @@ func ConvertBugLabels(taskCtx plugin.SubTaskContext) errors.Error {
 	db := taskCtx.GetDal()
 	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_BUG_TABLE)
 	clauses := []dal.Clause{
-		dal.From(&models.TapdBugLabel{}),
-		dal.Join("left join _tool_tapd_workspace_bugs on _tool_tapd_workspace_bugs.bug_id = _tool_tapd_bug_labels.bug_id"),
-		dal.Where("_tool_tapd_workspace_bugs.workspace_id = ? and _tool_tapd_workspace_bugs.connection_id = ?",
-			data.Options.WorkspaceId, data.Options.ConnectionId),
-		dal.Orderby("bug_id ASC"),
+		dal.From("_tool_tapd_bug_labels l"),
+		dal.Join("left join _tool_tapd_workspace_bugs b on b.bug_id = l.bug_id AND b.connection_id = l.connection_id"),
+		dal.Where("b.workspace_id = ? and b.connection_id = ?", data.Options.WorkspaceId, data.Options.ConnectionId),
+		dal.Orderby("b.bug_id ASC"),
 	}
 
 	cursor, err := db.Cursor(clauses...)
diff --git a/backend/plugins/tapd/tasks/story_label_convertor.go b/backend/plugins/tapd/tasks/story_label_convertor.go
index 197416e89..33c4e5d2c 100644
--- a/backend/plugins/tapd/tasks/story_label_convertor.go
+++ b/backend/plugins/tapd/tasks/story_label_convertor.go
@@ -18,6 +18,8 @@ limitations under the License.
 package tasks
 
 import (
+	"reflect"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
@@ -25,7 +27,6 @@ import (
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/tapd/models"
-	"reflect"
 )
 
 var ConvertStoryLabelsMeta = plugin.SubTaskMeta{
@@ -41,11 +42,10 @@ func ConvertStoryLabels(taskCtx plugin.SubTaskContext) errors.Error {
 	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_STORY_TABLE)
 
 	clauses := []dal.Clause{
-		dal.From(&models.TapdStoryLabel{}),
-		dal.Join("left join _tool_tapd_workspace_stories on _tool_tapd_workspace_stories.story_id = _tool_tapd_story_labels.story_id"),
-		dal.Where("_tool_tapd_workspace_stories.workspace_id = ? and _tool_tapd_workspace_stories.connection_id = ?",
-			data.Options.WorkspaceId, data.Options.ConnectionId),
-		dal.Orderby("story_id ASC"),
+		dal.From("_tool_tapd_story_labels l"),
+		dal.Join("left join _tool_tapd_workspace_stories s on s.story_id = l.story_id AND s.connection_id = l.connection_id"),
+		dal.Where("s.workspace_id = ? and s.connection_id = ?", data.Options.WorkspaceId, data.Options.ConnectionId),
+		dal.Orderby("s.story_id ASC"),
 	}
 
 	cursor, err := db.Cursor(clauses...)
diff --git a/backend/plugins/tapd/tasks/task_changelog_converter.go b/backend/plugins/tapd/tasks/task_changelog_converter.go
index 979b38390..d92c8c991 100644
--- a/backend/plugins/tapd/tasks/task_changelog_converter.go
+++ b/backend/plugins/tapd/tasks/task_changelog_converter.go
@@ -19,6 +19,9 @@ package tasks
 
 import (
 	"fmt"
+	"reflect"
+	"time"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/common"
@@ -28,8 +31,6 @@ import (
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/tapd/models"
-	"reflect"
-	"time"
 )
 
 type TaskChangelogItemResult struct {
@@ -73,10 +74,10 @@ func ConvertTaskChangelog(taskCtx plugin.SubTaskContext) errors.Error {
 	issueIdGen := didgen.NewDomainIdGenerator(&models.TapdTask{})
 	clIterIdGen := didgen.NewDomainIdGenerator(&models.TapdIteration{})
 	clauses := []dal.Clause{
-		dal.Select("tc.created, tc.id, tc.workspace_id, tc.task_id, tc.creator, _tool_tapd_task_changelog_items.*"),
-		dal.From(&models.TapdTaskChangelogItem{}),
-		dal.Join("left join _tool_tapd_task_changelogs tc on tc.id = _tool_tapd_task_changelog_items.changelog_id "),
-		dal.Where("tc.connection_id = ? AND tc.workspace_id = ?", data.Options.ConnectionId, data.Options.WorkspaceId),
+		dal.Select("c.created, c.id, c.workspace_id, c.task_id, c.creator, i.*"),
+		dal.From("_tool_tapd_task_changelog_items i"),
+		dal.Join("left join _tool_tapd_task_changelogs c on c.id = i.changelog_id AND c.connection_id = i.connection_id"),
+		dal.Where("c.connection_id = ? AND c.workspace_id = ?", data.Options.ConnectionId, data.Options.WorkspaceId),
 		dal.Orderby("created DESC"),
 	}
 	cursor, err := db.Cursor(clauses...)
diff --git a/backend/plugins/tapd/tasks/task_label_convertor.go b/backend/plugins/tapd/tasks/task_label_convertor.go
index 5ac06d38d..2c801f5fa 100644
--- a/backend/plugins/tapd/tasks/task_label_convertor.go
+++ b/backend/plugins/tapd/tasks/task_label_convertor.go
@@ -18,6 +18,8 @@ limitations under the License.
 package tasks
 
 import (
+	"reflect"
+
 	"github.com/apache/incubator-devlake/core/dal"
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
@@ -25,7 +27,6 @@ import (
 	"github.com/apache/incubator-devlake/core/plugin"
 	helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
 	"github.com/apache/incubator-devlake/plugins/tapd/models"
-	"reflect"
 )
 
 var ConvertTaskLabelsMeta = plugin.SubTaskMeta{
@@ -41,11 +42,10 @@ func ConvertTaskLabels(taskCtx plugin.SubTaskContext) errors.Error {
 	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_TASK_TABLE)
 
 	clauses := []dal.Clause{
-		dal.From(&models.TapdTaskLabel{}),
-		dal.Join("left join _tool_tapd_workspace_tasks on _tool_tapd_workspace_tasks.task_id = _tool_tapd_task_labels.task_id"),
-		dal.Where("_tool_tapd_workspace_tasks.workspace_id = ? and _tool_tapd_workspace_tasks.connection_id = ?",
-			data.Options.WorkspaceId, data.Options.ConnectionId),
-		dal.Orderby("task_id ASC"),
+		dal.From("_tool_tapd_task_labels l"),
+		dal.Join("left join _tool_tapd_workspace_tasks t on t.task_id = l.task_id AND t.connection_id = l.connection_id"),
+		dal.Where("t.workspace_id = ? and t.connection_id = ?", data.Options.WorkspaceId, data.Options.ConnectionId),
+		dal.Orderby("t.task_id ASC"),
 	}
 
 	cursor, err := db.Cursor(clauses...)