Skip to content

Commit

Permalink
fix: missing connectionId from tapd labels (apache#6350)
Browse files Browse the repository at this point in the history
  • Loading branch information
klesh authored Oct 27, 2023
1 parent 67faf2d commit 09efea7
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 36 deletions.
5 changes: 3 additions & 2 deletions backend/plugins/tapd/models/bug_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions backend/plugins/tapd/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ func All() []plugin.MigrationScript {
new(addCustomFieldValue),
new(renameTr2ScopeConfig),
new(addRawParamTableForScope),
new(addConnIdToLabels),
}
}
5 changes: 3 additions & 2 deletions backend/plugins/tapd/models/story_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions backend/plugins/tapd/models/task_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 7 additions & 6 deletions backend/plugins/tapd/tasks/bug_changelog_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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"),
}

Expand Down
12 changes: 6 additions & 6 deletions backend/plugins/tapd/tasks/bug_label_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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"
"github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
"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{
Expand All @@ -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...)
Expand Down
12 changes: 6 additions & 6 deletions backend/plugins/tapd/tasks/story_label_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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"
"github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
"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{
Expand All @@ -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...)
Expand Down
13 changes: 7 additions & 6 deletions backend/plugins/tapd/tasks/task_changelog_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down
12 changes: 6 additions & 6 deletions backend/plugins/tapd/tasks/task_label_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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"
"github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
"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{
Expand All @@ -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...)
Expand Down

0 comments on commit 09efea7

Please sign in to comment.