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

lgcareer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new f109a75  [Bug][PGSQL] Delete the stopped workflow without deleting the 
correspon… (#5066)
f109a75 is described below

commit f109a758f8388a0499391f5a87ccd6d1e17db3aa
Author: Kirs <[email protected]>
AuthorDate: Tue Mar 23 11:26:11 2021 +0800

    [Bug][PGSQL] Delete the stopped workflow without deleting the correspon… 
(#5066)
    
    * [Bug][Api] Delete the stopped workflow without deleting the corresponding 
sub process, the workflow instance name is not displayed in the sub process
    
    * fix ut
    
    * fix ut err
    
    * sql style
    
    * fix error
---
 .../dao/mapper/TaskInstanceMapperTest.java         | 43 ++++++++++++----------
 sql/dolphinscheduler_postgre.sql                   |  3 +-
 .../postgresql/dolphinscheduler_ddl.sql            | 18 +++++++++
 .../postgresql/dolphinscheduler_dml.sql            | 16 ++++++++
 4 files changed, 60 insertions(+), 20 deletions(-)

diff --git 
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
 
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
index 4bef7f1..9ad8677 100644
--- 
a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
+++ 
b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.dao.mapper;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
 import org.apache.dolphinscheduler.common.enums.CommandType;
 import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
 import org.apache.dolphinscheduler.common.enums.Flag;
@@ -32,6 +33,7 @@ import java.util.Date;
 import java.util.List;
 
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +45,7 @@ import 
org.springframework.transaction.annotation.Transactional;
 @RunWith(SpringRunner.class)
 @SpringBootTest
 @Transactional
-@Rollback(true)
+@Rollback
 public class TaskInstanceMapperTest {
 
 
@@ -59,6 +61,17 @@ public class TaskInstanceMapperTest {
     @Autowired
     ProcessInstanceMapMapper processInstanceMapMapper;
 
+    private int processInstanceId;
+
+    @Before
+    public void before() {
+        ProcessInstance processInstance = new ProcessInstance();
+        processInstance.setWarningGroupId(0);
+        processInstance.setCommandParam("");
+        processInstanceMapper.insert(processInstance);
+        processInstanceId = processInstance.getId();
+    }
+
     /**
      * insert
      *
@@ -66,19 +79,13 @@ public class TaskInstanceMapperTest {
      */
     private TaskInstance insertOne() {
         //insertOne
-        return insertOne("us task", 1, ExecutionStatus.RUNNING_EXECUTION, 
TaskType.SHELL.toString());
+        return insertOne("us task", processInstanceId, 
ExecutionStatus.RUNNING_EXECUTION, TaskType.SHELL.toString(),1);
     }
 
     /**
      * construct a task instance and then insert
-     *
-     * @param taskName
-     * @param processInstanceId
-     * @param state
-     * @param taskType
-     * @return
      */
-    private TaskInstance insertOne(String taskName, int processInstanceId, 
ExecutionStatus state, String taskType) {
+    private TaskInstance insertOne(String taskName, int processInstanceId, 
ExecutionStatus state, String taskType,int processDefinitionId) {
         TaskInstance taskInstance = new TaskInstance();
         taskInstance.setFlag(Flag.YES);
         taskInstance.setName(taskName);
@@ -88,6 +95,7 @@ public class TaskInstanceMapperTest {
         taskInstance.setTaskJson("{}");
         taskInstance.setProcessInstanceId(processInstanceId);
         taskInstance.setTaskType(taskType);
+        taskInstance.setProcessDefinitionId(processDefinitionId);
         taskInstanceMapper.insert(taskInstance);
         return taskInstance;
     }
@@ -96,7 +104,7 @@ public class TaskInstanceMapperTest {
      * test update
      */
     @Test
-    public void testUpdate(){
+    public void testUpdate() {
         //insertOne
         TaskInstance taskInstance = insertOne();
         //update
@@ -133,7 +141,7 @@ public class TaskInstanceMapperTest {
     @Test
     public void testQueryTaskByProcessIdAndState() {
         TaskInstance task = insertOne();
-        task.setProcessInstanceId(110);
+        task.setProcessInstanceId(processInstanceId);
         taskInstanceMapper.updateById(task);
         List<Integer> taskInstances = 
taskInstanceMapper.queryTaskByProcessIdAndState(
                 task.getProcessInstanceId(),
@@ -150,8 +158,8 @@ public class TaskInstanceMapperTest {
     public void testFindValidTaskListByProcessId() {
         TaskInstance task = insertOne();
         TaskInstance task2 = insertOne();
-        task.setProcessInstanceId(110);
-        task2.setProcessInstanceId(110);
+        task.setProcessInstanceId(processInstanceId);
+        task2.setProcessInstanceId(processInstanceId);
         taskInstanceMapper.updateById(task);
         taskInstanceMapper.updateById(task2);
 
@@ -279,7 +287,6 @@ public class TaskInstanceMapperTest {
      */
     @Test
     public void testQueryTaskInstanceListPaging() {
-        TaskInstance task = insertOne();
 
         ProcessDefinition definition = new ProcessDefinition();
         definition.setProjectId(1111);
@@ -294,11 +301,9 @@ public class TaskInstanceMapperTest {
         processInstance.setCommandType(CommandType.START_PROCESS);
         processInstanceMapper.insert(processInstance);
 
-        task.setProcessDefinitionId(definition.getId());
-        task.setProcessInstanceId(processInstance.getId());
-        taskInstanceMapper.updateById(task);
+        TaskInstance task = insertOne("us task", processInstance.getId(), 
ExecutionStatus.RUNNING_EXECUTION, 
TaskType.SHELL.toString(),definition.getId());
 
-        Page<TaskInstance> page = new Page(1,3);
+        Page<TaskInstance> page = new Page(1, 3);
         IPage<TaskInstance> taskInstanceIPage = 
taskInstanceMapper.queryTaskInstanceListPaging(
                 page,
                 definition.getProjectId(),
@@ -309,7 +314,7 @@ public class TaskInstanceMapperTest {
                 0,
                 new int[0],
                 "",
-                null,null
+                null, null
         );
         processInstanceMapper.deleteById(processInstance.getId());
         taskInstanceMapper.deleteById(task.getId());
diff --git a/sql/dolphinscheduler_postgre.sql b/sql/dolphinscheduler_postgre.sql
index 97b2e94..a3853fb 100644
--- a/sql/dolphinscheduler_postgre.sql
+++ b/sql/dolphinscheduler_postgre.sql
@@ -578,7 +578,8 @@ CREATE TABLE t_ds_task_instance (
   first_submit_time timestamp DEFAULT NULL ,
   delay_time int DEFAULT '0' ,
   var_pool text ,
-  PRIMARY KEY (id)
+  PRIMARY KEY (id),
+  CONSTRAINT foreign_key_instance_id FOREIGN KEY(process_instance_id) 
REFERENCES t_ds_process_instance(id) ON DELETE CASCADE
 ) ;
 
 --
diff --git a/sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_ddl.sql 
b/sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_ddl.sql
new file mode 100644
index 0000000..752e684
--- /dev/null
+++ b/sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_ddl.sql
@@ -0,0 +1,18 @@
+/*
+ * 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.
+*/
+-- Add foreign key constraints for t_ds_task_instance --
+ALTER TABLE t_ds_task_instance ADD CONSTRAINT foreign_key_instance_id  FOREIGN 
KEY(process_instance_id) REFERENCES t_ds_process_instance(id) ON DELETE CASCADE;
\ No newline at end of file
diff --git a/sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_dml.sql 
b/sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_dml.sql
new file mode 100644
index 0000000..38964cc
--- /dev/null
+++ b/sql/upgrade/1.3.6_schema/postgresql/dolphinscheduler_dml.sql
@@ -0,0 +1,16 @@
+/*
+ * 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.
+*/
\ No newline at end of file

Reply via email to