From 151c2d2c70c652a72b864d9007b239c22706b94d Mon Sep 17 00:00:00 2001 From: caishunfeng Date: Mon, 26 Sep 2022 15:21:52 +0800 Subject: [PATCH] fix upgrade sql (#12141) --- .../mysql/dolphinscheduler_ddl.sql | 37 ++++++++++++ .../postgresql/dolphinscheduler_ddl.sql | 6 +- .../mysql/dolphinscheduler_ddl.sql | 52 ----------------- .../mysql/dolphinscheduler_dml.sql | 16 ------ .../postgresql/dolphinscheduler_ddl.sql | 56 ------------------- .../postgresql/dolphinscheduler_dml.sql | 30 ---------- 6 files changed, 41 insertions(+), 156 deletions(-) delete mode 100644 dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_ddl.sql delete mode 100644 dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_dml.sql delete mode 100644 dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_ddl.sql delete mode 100644 dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_dml.sql diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/mysql/dolphinscheduler_ddl.sql index 0d05800e33..059f0d27ef 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/mysql/dolphinscheduler_ddl.sql @@ -391,6 +391,43 @@ delimiter ; CALL modify_t_ds_task_group_col_description; DROP PROCEDURE modify_t_ds_task_group_col_description; +-- alter table `t_ds_worker_group` add `other_params_json` text; +-- alter table `t_ds_process_instance` add `state_history` text; +drop procedure if exists add_column_safety; +delimiter d// +create procedure add_column_safety(target_table_name varchar(256), target_column varchar(256), + target_column_type varchar(256), sths_else varchar(256)) +begin + declare target_database varchar(256); +select database() into target_database; +IF EXISTS(SELECT * + FROM information_schema.COLUMNS + WHERE COLUMN_NAME = target_column + AND TABLE_NAME = target_table_name + ) + THEN + set @statement = + concat('alter table ', target_table_name, ' change column ', target_column, ' ', target_column, ' ', + target_column_type, ' ', + sths_else); +PREPARE STMT_c FROM @statement; +EXECUTE STMT_c; +ELSE + set @statement = + concat('alter table ', target_table_name, ' add column ', target_column, ' ', target_column_type, ' ', + sths_else); +PREPARE STMT_a FROM @statement; +EXECUTE STMT_a; +END IF; +end; +d// +delimiter ; + +call add_column_safety('t_ds_worker_group','other_params_json', 'text' , "DEFAULT NULL COMMENT 'other params json'"); +call add_column_safety('t_ds_process_instance','state_history', 'text' , "DEFAULT NULL COMMENT 'state history desc' AFTER `state`"); + +drop procedure if exists add_column_safety; + alter table t_ds_process_instance alter column process_instance_priority set default 2; alter table t_ds_schedules alter column process_instance_priority set default 2; alter table t_ds_command alter column process_instance_priority set default 2; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/postgresql/dolphinscheduler_ddl.sql index 0ce3722bec..564f192f74 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/postgresql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -19,8 +19,8 @@ ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS online_job_num; ALTER TABLE t_ds_k8s_namespace DROP COLUMN IF EXISTS k8s; ALTER TABLE t_ds_k8s_namespace DROP CONSTRAINT IF EXISTS k8s_namespace_unique; -ALTER TABLE t_ds_k8s_namespace ADD COLUMN IF NOT EXISTS code bigint(20) NOT NULL DEFAULT '0'; -ALTER TABLE t_ds_k8s_namespace ADD COLUMN IF NOT EXISTS cluster_code bigint(20) NOT NULL DEFAULT '0'; +ALTER TABLE t_ds_k8s_namespace ADD COLUMN IF NOT EXISTS code bigint NOT NULL DEFAULT '0'; +ALTER TABLE t_ds_k8s_namespace ADD COLUMN IF NOT EXISTS cluster_code bigint NOT NULL DEFAULT '0'; ALTER TABLE t_ds_k8s_namespace DROP CONSTRAINT IF EXISTS k8s_namespace_unique; ALTER TABLE t_ds_k8s_namespace ADD CONSTRAINT k8s_namespace_unique UNIQUE (namespace, cluster_code); @@ -72,3 +72,5 @@ ALTER TABLE t_ds_task_instance ADD COLUMN IF NOT EXISTS task_execute_type int DE ALTER TABLE t_ds_task_instance DROP CONSTRAINT IF EXISTS foreign_key_instance_id; ALTER TABLE t_ds_project alter COLUMN description type varchar(255); ALTER TABLE t_ds_task_group alter COLUMN description type varchar(255); +ALTER TABLE t_ds_worker_group ADD COLUMN IF NOT EXISTS other_params_json text DEFAULT NULL; +ALTER TABLE t_ds_process_instance ADD COLUMN IF NOT EXISTS state_history text DEFAULT NULL; \ No newline at end of file diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_ddl.sql deleted file mode 100644 index e3fdefe870..0000000000 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_ddl.sql +++ /dev/null @@ -1,52 +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. -*/ - - -drop procedure if exists add_column_safety; -delimiter d// -create procedure add_column_safety(target_table_name varchar(256), target_column varchar(256), - target_column_type varchar(256), sths_else varchar(256)) -begin - declare target_database varchar(256); - select database() into target_database; - IF EXISTS(SELECT * - FROM information_schema.COLUMNS - WHERE COLUMN_NAME = target_column - AND TABLE_NAME = target_table_name - ) - THEN - set @statement = - concat('alter table ', target_table_name, ' change column ', target_column, ' ', target_column, ' ', - target_column_type, ' ', - sths_else); - PREPARE STMT_c FROM @statement; - EXECUTE STMT_c; - ELSE - set @statement = - concat('alter table ', target_table_name, ' add column ', target_column, ' ', target_column_type, ' ', - sths_else); - PREPARE STMT_a FROM @statement; - EXECUTE STMT_a; - END IF; -end; -d// -delimiter ; - -call add_column_safety('t_ds_worker_group','other_params_json_test', 'text' , "DEFAULT NULL COMMENT 'other params json'"); -call add_column_safety('t_ds_process_instance','state_history', 'text' , "DEFAULT NULL COMMENT 'state history desc' AFTER `state`"); - -drop procedure if exists add_column_safety; \ No newline at end of file diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_dml.sql deleted file mode 100644 index 4a14f326b9..0000000000 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_dml.sql +++ /dev/null @@ -1,16 +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. -*/ diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_ddl.sql deleted file mode 100644 index 5d30a95eec..0000000000 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_ddl.sql +++ /dev/null @@ -1,56 +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. -*/ - -delimiter d// - - - -CREATE OR REPLACE FUNCTION public.dolphin_update_metadata( - ) - RETURNS character varying - LANGUAGE 'plpgsql' - COST 100 - VOLATILE PARALLEL UNSAFE -AS $BODY$ -DECLARE -v_schema varchar; -BEGIN - ---get schema name - v_schema =current_schema(); - - - ---- add column -EXECUTE 'ALTER TABLE ' || quote_ident(v_schema) ||'.t_ds_worker_group ADD COLUMN IF NOT EXISTS other_params_json text DEFAULT NULL '; - -EXECUTE 'ALTER TABLE ' || quote_ident(v_schema) ||'.t_ds_process_isntance ADD COLUMN IF NOT EXISTS state_history text DEFAULT NULL '; - - - -return 'Success!'; -exception when others then - ---Raise EXCEPTION '(%)',SQLERRM; - - return SQLERRM; -END; -$BODY$; - -select dolphin_update_metadata(); - - -d// - diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_dml.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_dml.sql deleted file mode 100644 index 4d7327f767..0000000000 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_dml.sql +++ /dev/null @@ -1,30 +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. -*/ - -delimiter d// - -return 'Success!'; -exception when others then - ---Raise EXCEPTION '(%)',SQLERRM; - return SQLERRM; -END; -$BODY$; - -select dolphin_insert_dq_initial_data(); - -d// -