From 891df6d5e29ce9c3a09aaf11cdf96ab31f64ff31 Mon Sep 17 00:00:00 2001 From: zhuangchong <37063904+zhuangchong@users.noreply.github.com> Date: Mon, 25 Jan 2021 19:38:53 +0800 Subject: [PATCH] fix schema 1.4.0 (#4564) --- .../mysql/dolphinscheduler_ddl.sql | 111 +++++++++++++++--- .../postgresql/dolphinscheduler_ddl.sql | 96 ++++++++++++--- 2 files changed, 177 insertions(+), 30 deletions(-) diff --git a/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql b/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql index 60b354fdf7..b92b5cf87f 100644 --- a/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql +++ b/sql/upgrade/1.4.0_schema/mysql/dolphinscheduler_ddl.sql @@ -16,6 +16,10 @@ */ SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); + +-- ---------------------------- +-- Table structure for t_ds_plugin_define +-- ---------------------------- DROP TABLE IF EXISTS `t_ds_plugin_define`; CREATE TABLE `t_ds_plugin_define` ( `id` int NOT NULL AUTO_INCREMENT, @@ -28,6 +32,13 @@ CREATE TABLE `t_ds_plugin_define` ( UNIQUE KEY `t_ds_plugin_define_UN` (`plugin_name`,`plugin_type`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +-- ---------------------------- +-- Records of t_ds_plugin_define +-- ---------------------------- + +-- ---------------------------- +-- Table structure for t_ds_alert_plugin_instance +-- ---------------------------- DROP TABLE IF EXISTS `t_ds_alert_plugin_instance`; CREATE TABLE `t_ds_alert_plugin_instance` ( `id` int NOT NULL AUTO_INCREMENT, @@ -39,31 +50,101 @@ CREATE TABLE `t_ds_alert_plugin_instance` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -ALTER TABLE t_ds_process_definition - ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; +-- ---------------------------- +-- Records of t_ds_alert_plugin_instance +-- ---------------------------- + +-- uc_dolphin_T_t_ds_process_definition_A_warning_group_id +drop PROCEDURE if EXISTS uc_dolphin_T_t_ds_process_definition_A_warning_group_id; +delimiter d// +CREATE PROCEDURE uc_dolphin_T_t_ds_process_definition_A_warning_group_id() + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_process_definition' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='warning_group_id') + THEN + ALTER TABLE t_ds_process_definition ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + END IF; + END; -ALTER TABLE t_ds_process_definition_version - ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; +d// -ALTER TABLE t_ds_alertgroup - ADD COLUMN `alert_instance_ids` varchar (255) DEFAULT NULL COMMENT 'alert instance ids' AFTER `id`, - ADD COLUMN `create_user_id` int(11) DEFAULT NULL COMMENT 'create user id' AFTER `alert_instance_ids`; +delimiter ; +CALL uc_dolphin_T_t_ds_process_definition_A_warning_group_id(); +DROP PROCEDURE uc_dolphin_T_t_ds_process_definition_A_warning_group_id; +-- uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id +drop PROCEDURE if EXISTS uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id; +delimiter d// +CREATE PROCEDURE uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id() + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_process_definition_version' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='warning_group_id') + THEN + ALTER TABLE t_ds_process_definition_version ADD COLUMN `warning_group_id` int(11) DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + END IF; + END; + +d// + +delimiter ; +CALL uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id(); +DROP PROCEDURE uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id; + +-- uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids +drop PROCEDURE if EXISTS uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids; +delimiter d// +CREATE PROCEDURE uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids() + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_alertgroup' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='alert_instance_ids') + THEN + ALTER TABLE t_ds_alertgroup ADD COLUMN `alert_instance_ids` varchar (255) DEFAULT NULL COMMENT 'alert instance ids' AFTER `id`; + END IF; + END; + +d// + +delimiter ; +CALL uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids(); +DROP PROCEDURE uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids; + +-- uc_dolphin_T_t_ds_alertgroup_A_create_user_id +drop PROCEDURE if EXISTS uc_dolphin_T_t_ds_alertgroup_A_create_user_id; +delimiter d// +CREATE PROCEDURE uc_dolphin_T_t_ds_alertgroup_A_create_user_id() + BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_alertgroup' + AND TABLE_SCHEMA=(SELECT DATABASE()) + AND COLUMN_NAME ='create_user_id') + THEN + ALTER TABLE t_ds_alertgroup ADD COLUMN `create_user_id` int(11) DEFAULT NULL COMMENT 'create user id' AFTER `alert_instance_ids`; + END IF; + END; + +d// + +delimiter ; +CALL uc_dolphin_T_t_ds_alertgroup_A_create_user_id(); +DROP PROCEDURE uc_dolphin_T_t_ds_alertgroup_A_create_user_id; -- ---------------------------- -- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below -- ---------------------------- -/* -ALTER TABLE t_ds_process_definition DROP receivers, DROP receivers_cc; -ALTER TABLE t_ds_process_definition_version DROP receivers, DROP receivers_cc; +-- ALTER TABLE t_ds_process_definition DROP receivers, DROP receivers_cc; -ALTER TABLE t_ds_alert DROP show_type,DROP alert_type,DROP receivers,DROP receivers_cc; +-- ALTER TABLE t_ds_process_definition_version DROP receivers, DROP receivers_cc; -ALTER TABLE t_ds_alertgroup DROP group_type; - -DROP TABLE IF EXISTS t_ds_relation_user_alertgroup; -*/ +-- ALTER TABLE t_ds_alert DROP show_type,DROP alert_type,DROP receivers,DROP receivers_cc; +-- ALTER TABLE t_ds_alertgroup DROP group_type; +-- DROP TABLE IF EXISTS t_ds_relation_user_alertgroup; diff --git a/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql b/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql index d7fa51d840..53a8c47d03 100644 --- a/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql +++ b/sql/upgrade/1.4.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -14,6 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +-- ---------------------------- +-- Table structure for t_ds_plugin_define +-- ---------------------------- DROP TABLE IF EXISTS t_ds_plugin_define; CREATE TABLE t_ds_plugin_define ( id serial NOT NULL, @@ -26,7 +30,9 @@ CREATE TABLE t_ds_plugin_define ( CONSTRAINT t_ds_plugin_define_un UNIQUE (plugin_name, plugin_type) ); - +-- ---------------------------- +-- Table structure for t_ds_alert_plugin_instance +-- ---------------------------- DROP TABLE IF EXISTS t_ds_alert_plugin_instance; CREATE TABLE t_ds_alert_plugin_instance ( id serial NOT NULL, @@ -38,28 +44,88 @@ CREATE TABLE t_ds_alert_plugin_instance ( CONSTRAINT t_ds_alert_plugin_instance_pk PRIMARY KEY (id) ); -ALTER TABLE t_ds_process_definition - ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; +-- uc_dolphin_T_t_ds_process_definition_A_warning_group_id +delimiter d// +CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_A_warning_group_id() RETURNS void AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_process_definition' + AND COLUMN_NAME ='warning_group_id') + THEN + ALTER TABLE t_ds_process_definition ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + END IF; +END; +$$ LANGUAGE plpgsql; +d// + +delimiter ; +SELECT uc_dolphin_T_t_ds_process_definition_A_warning_group_id(); +DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_A_warning_group_id(); -ALTER TABLE t_ds_process_definition_version - ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; +-- uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id +delimiter d// +CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id() RETURNS void AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_process_definition_version' + AND COLUMN_NAME ='warning_group_id') + THEN + ALTER TABLE t_ds_process_definition_version ADD COLUMN `warning_group_id` int4 DEFAULT NULL COMMENT 'alert group id' AFTER `connects`; + END IF; +END; +$$ LANGUAGE plpgsql; +d// -ALTER TABLE t_ds_alertgroup - ADD COLUMN `alert_instance_ids` int4 DEFAULT NULL COMMENT 'alert instance ids' AFTER `id`; - ADD COLUMN `create_user_id` varchar(255) DEFAULT NULL COMMENT 'create user id' AFTER `alert_instance_ids`, +delimiter ; +SELECT uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id(); +DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_process_definition_version_A_warning_group_id(); +-- uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids +delimiter d// +CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids() RETURNS void AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_alertgroup' + AND COLUMN_NAME ='alert_instance_ids') + THEN + ALTER TABLE t_ds_alertgroup ADD COLUMN `alert_instance_ids` varchar (255) DEFAULT NULL COMMENT 'alert instance ids' AFTER `id`; + END IF; +END; +$$ LANGUAGE plpgsql; +d// + +delimiter ; +SELECT uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids(); +DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_alert_instance_ids(); + +-- uc_dolphin_T_t_ds_alertgroup_A_create_user_id +delimiter d// +CREATE OR REPLACE FUNCTION uc_dolphin_T_t_ds_alertgroup_A_create_user_id() RETURNS void AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_NAME='t_ds_alertgroup' + AND COLUMN_NAME ='create_user_id') + THEN + ALTER TABLE t_ds_alertgroup ADD COLUMN `create_user_id` int4 DEFAULT NULL COMMENT 'create user id' AFTER `alert_instance_ids`; + END IF; +END; +$$ LANGUAGE plpgsql; +d// + +delimiter ; +SELECT uc_dolphin_T_t_ds_alertgroup_A_create_user_id(); +DROP FUNCTION IF EXISTS uc_dolphin_T_t_ds_alertgroup_A_create_user_id(); -- ---------------------------- -- These columns will not be used in the new version,if you determine that the historical data is useless, you can delete it using the sql below -- ---------------------------- -/* -ALTER TABLE t_ds_process_definition DROP COLUMN "receivers", DROP COLUMN "receivers_cc"; -ALTER TABLE t_ds_process_definition_version DROP COLUMN "receivers", DROP COLUMN "receivers_cc"; +-- ALTER TABLE t_ds_process_definition DROP COLUMN "receivers", DROP COLUMN "receivers_cc"; -ALTER TABLE t_ds_alert DROP COLUMN "show_type",DROP COLUMN "alert_type",DROP COLUMN "receivers",DROP COLUMN "receivers_cc"; +-- ALTER TABLE t_ds_process_definition_version DROP COLUMN "receivers", DROP COLUMN "receivers_cc"; -ALTER TABLE t_ds_alertgroup DROP COLUMN "group_type"; +-- ALTER TABLE t_ds_alert DROP COLUMN "show_type",DROP COLUMN "alert_type",DROP COLUMN "receivers",DROP COLUMN "receivers_cc"; -DROP TABLE IF EXISTS t_ds_relation_user_alertgroup; -*/ +-- ALTER TABLE t_ds_alertgroup DROP COLUMN "group_type"; + +-- DROP TABLE IF EXISTS t_ds_relation_user_alertgroup;