Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/plugins/q_dev/api/blueprint_v200.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func makeDataSourcePipelinePlanV200(
op := &tasks.QDevOptions{
ConnectionId: s3Slice.ConnectionId,
S3Prefix: s3Slice.Prefix,
ScopeId: s3Slice.Id,
}

// Pass empty entities array to enable all subtasks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
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 = (*addScopeIdFields)(nil)

type addScopeIdFields struct{}

func (*addScopeIdFields) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()

// Add scope_id column to _tool_q_dev_user_data table
// This field links user data to QDevS3Slice scope, which can then be mapped to projects via project_mapping
err := db.Exec(`
ALTER TABLE _tool_q_dev_user_data
ADD COLUMN IF NOT EXISTS scope_id VARCHAR(255) DEFAULT NULL
`)
if err != nil {
// Try alternative syntax for databases that don't support IF NOT EXISTS
_ = db.Exec(`ALTER TABLE _tool_q_dev_user_data ADD COLUMN scope_id VARCHAR(255) DEFAULT NULL`)
}

// Add index on scope_id for better query performance
_ = db.Exec(`CREATE INDEX IF NOT EXISTS idx_q_dev_user_data_scope_id ON _tool_q_dev_user_data(scope_id)`)

// Add scope_id column to _tool_q_dev_s3_file_meta table
err = db.Exec(`
ALTER TABLE _tool_q_dev_s3_file_meta
ADD COLUMN IF NOT EXISTS scope_id VARCHAR(255) DEFAULT NULL
`)
if err != nil {
_ = db.Exec(`ALTER TABLE _tool_q_dev_s3_file_meta ADD COLUMN scope_id VARCHAR(255) DEFAULT NULL`)
}

// Add index on scope_id
_ = db.Exec(`CREATE INDEX IF NOT EXISTS idx_q_dev_s3_file_meta_scope_id ON _tool_q_dev_s3_file_meta(scope_id)`)

return nil
}

func (*addScopeIdFields) Version() uint64 {
return 20251209000001
}

func (*addScopeIdFields) Name() string {
return "add scope_id field to QDevUserData and QDevS3FileMeta for project association"
}
1 change: 1 addition & 0 deletions backend/plugins/q_dev/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ func All() []plugin.MigrationScript {
new(addMissingMetrics),
new(addS3SliceTable),
new(addScopeConfigIdToS3Slice),
new(addScopeIdFields),
}
}
1 change: 1 addition & 0 deletions backend/plugins/q_dev/models/s3_file_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type QDevS3FileMeta struct {
ConnectionId uint64 `gorm:"primaryKey"`
FileName string `gorm:"primaryKey;type:varchar(255)"`
S3Path string `gorm:"type:varchar(512)" json:"s3Path"`
ScopeId string `gorm:"type:varchar(255);index" json:"scopeId"`
Processed bool `gorm:"default:false"`
ProcessedTime *time.Time `gorm:"default:null"`
}
Expand Down
1 change: 1 addition & 0 deletions backend/plugins/q_dev/models/user_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type QDevUserData struct {
UserId string `gorm:"index" json:"userId"`
Date time.Time `gorm:"index" json:"date"`
DisplayName string `gorm:"type:varchar(255)" json:"displayName"` // New field for user display name
ScopeId string `gorm:"index;type:varchar(255)" json:"scopeId"`

CodeReview_FindingsCount int
CodeReview_SucceededEventCount int
Expand Down
1 change: 1 addition & 0 deletions backend/plugins/q_dev/tasks/s3_data_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func createUserDataWithDisplayName(logger interface {
}, headers []string, record []string, fileMeta *models.QDevS3FileMeta, identityClient UserDisplayNameResolver) (*models.QDevUserData, errors.Error) {
userData := &models.QDevUserData{
ConnectionId: fileMeta.ConnectionId,
ScopeId: fileMeta.ScopeId,
}

// 创建字段映射
Expand Down
1 change: 1 addition & 0 deletions backend/plugins/q_dev/tasks/s3_file_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func CollectQDevS3Files(taskCtx plugin.SubTaskContext) errors.Error {
ConnectionId: data.Options.ConnectionId,
FileName: *object.Key,
S3Path: *object.Key,
ScopeId: data.Options.ScopeId,
Processed: false,
}

Expand Down
1 change: 1 addition & 0 deletions backend/plugins/q_dev/tasks/task_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type QDevApiParams struct {
type QDevOptions struct {
ConnectionId uint64 `json:"connectionId"`
S3Prefix string `json:"s3Prefix"`
ScopeId string `json:"scopeId"`
}

type QDevTaskData struct {
Expand Down
Loading