From 149553c52b1818d624dd5348f160ed808ae4155f Mon Sep 17 00:00:00 2001 From: Hengdong Gong Date: Wed, 26 Oct 2022 12:32:05 +0800 Subject: [PATCH] [fix](dolphinscheduler-dao) fix upgrade to 3.1.0 sql missing field (#12314) (#12315) --- .../mysql/dolphinscheduler_ddl.sql | 34 +++++++++++++++++++ .../postgresql/dolphinscheduler_ddl.sql | 2 ++ 2 files changed, 36 insertions(+) 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 index 4a14f326b9..0008af69c7 100644 --- 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 @@ -14,3 +14,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +-- alter table `t_ds_worker_group` add `description` varchar(256); +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 ; + +-- ALTER TABLE t_ds_worker_group ADD COLUMN description varchar(255) DEFAULT NULL COMMENT 'ds worker group description'; +call add_column_safety('t_ds_worker_group','description', 'varchar(255)' , "DEFAULT NULL COMMENT 'ds worker group description'"); +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/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/postgresql/dolphinscheduler_ddl.sql index 4a14f326b9..1d10ad01d0 100644 --- 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 @@ -14,3 +14,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +--- add column +ALTER TABLE t_ds_task_group alter COLUMN description type varchar(255); \ No newline at end of file