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 2024/04/26 08:28:11 UTC

(incubator-devlake) branch fix-customize-not-update-data updated: fix: customize plugin can not update old data

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

abeizn pushed a commit to branch fix-customize-not-update-data
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/fix-customize-not-update-data by this push:
     new 146a88351 fix: customize plugin can not update old data
146a88351 is described below

commit 146a883511b40f2481e7a3197858028e789e5dce
Author: abeizn <zi...@merico.dev>
AuthorDate: Fri Apr 26 16:27:54 2024 +0800

    fix: customize plugin can not update old data
---
 backend/helpers/pluginhelper/api/pipeline_plan.go | 85 -----------------------
 backend/impls/dalgorm/dalgorm.go                  |  9 ++-
 2 files changed, 8 insertions(+), 86 deletions(-)

diff --git a/backend/helpers/pluginhelper/api/pipeline_plan.go b/backend/helpers/pluginhelper/api/pipeline_plan.go
deleted file mode 100644
index 4c11f6ef3..000000000
--- a/backend/helpers/pluginhelper/api/pipeline_plan.go
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-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 api
-
-import (
-	"fmt"
-
-	"github.com/apache/incubator-devlake/core/errors"
-	"github.com/apache/incubator-devlake/core/models"
-	plugin "github.com/apache/incubator-devlake/core/plugin"
-	"github.com/apache/incubator-devlake/core/utils"
-)
-
-// MakePipelinePlanSubtasks generates subtasks list based on sub-task meta information and entities wanted by user
-func MakePipelinePlanSubtasks(subtaskMetas []plugin.SubTaskMeta, entities []string) ([]string, errors.Error) {
-	subtasks := make([]string, 0)
-	// if no entities specified, use all entities enabled by default
-	if len(entities) == 0 {
-		entities = plugin.DOMAIN_TYPES
-	}
-	wanted := make(map[string]bool, len(entities))
-	for _, entity := range entities {
-		if !utils.StringsContains(plugin.DOMAIN_TYPES, entity) {
-			return nil, errors.Default.New(fmt.Sprintf("invalid entity(domain type): %s", entity))
-		}
-		wanted[entity] = true
-	}
-	for _, subtaskMeta := range subtaskMetas {
-		if !subtaskMeta.EnabledByDefault {
-			continue
-		}
-		for _, neededBy := range subtaskMeta.DomainTypes {
-			if wanted[neededBy] {
-				subtasks = append(subtasks, subtaskMeta.Name)
-				break
-			}
-		}
-	}
-	return subtasks, nil
-}
-
-func MakePipelinePlanTask(
-	pluginName string,
-	subtaskMetas []plugin.SubTaskMeta,
-	entities []string,
-	options interface{},
-) (*models.PipelineTask, errors.Error) {
-	subtasks, err := MakePipelinePlanSubtasks(subtaskMetas, entities)
-	if err != nil {
-		return nil, err
-	}
-	op, err := encodeTaskOptions(options)
-	if err != nil {
-		return nil, err
-	}
-	return &models.PipelineTask{
-		Plugin:   pluginName,
-		Subtasks: subtasks,
-		Options:  op,
-	}, nil
-}
-
-func encodeTaskOptions(op interface{}) (map[string]interface{}, errors.Error) {
-	var result map[string]interface{}
-	err := Decode(op, &result, nil)
-	if err != nil {
-		return nil, err
-	}
-	return result, nil
-}
diff --git a/backend/impls/dalgorm/dalgorm.go b/backend/impls/dalgorm/dalgorm.go
index a3de41123..b18134809 100644
--- a/backend/impls/dalgorm/dalgorm.go
+++ b/backend/impls/dalgorm/dalgorm.go
@@ -236,7 +236,14 @@ func (d *Dalgorm) Create(entity interface{}, clauses ...dal.Clause) errors.Error
 // CreateWithMap insert record to database
 func (d *Dalgorm) CreateWithMap(entity interface{}, record map[string]interface{}) errors.Error {
 	d.unwrapDynamic(&entity, nil)
-	return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{UpdateAll: true}).Create(record).Error)
+	var columns []string
+	for column := range record {
+		columns = append(columns, column)
+	}
+	return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{
+		Columns:   []clause.Column{{Name: "id"}},
+		DoUpdates: clause.AssignmentColumns(columns),
+	}).Create(record).Error)
 }
 
 // Update updates record