Browse Source

[Fix][db] fix init&upgrade mysql-meta-schema bugs (#11887)

3.2.0-release
wendongdi 2 years ago committed by GitHub
parent
commit
e70c501f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      dolphinscheduler-dao/src/main/resources/sql/upgrade/2.0.3_schema/mysql/dolphinscheduler_ddl.sql
  2. 33
      dolphinscheduler-dao/src/main/resources/sql/upgrade/2.0.4_schema/mysql/dolphinscheduler_ddl.sql
  3. 2
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/mysql/dolphinscheduler_ddl.sql
  4. 34
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_ddl.sql

36
dolphinscheduler-dao/src/main/resources/sql/upgrade/2.0.3_schema/mysql/dolphinscheduler_ddl.sql

@ -15,7 +15,37 @@
* limitations under the License. * limitations under the License.
*/ */
drop procedure if exists re_add_index;
delimiter d//
create procedure re_add_index(target_table_name varchar(256),
target_index_type varchar(8), target_index_name varchar(256),
target_columns varchar(512), using_str varchar(256))
begin
declare target_database varchar(256);
select database() into target_database;
IF EXISTS(SELECT *
FROM information_schema.statistics
WHERE table_schema = target_database
AND table_name = target_table_name
AND index_name = target_index_name) THEN
set @statement = concat('drop index ', target_index_name, ' on ', target_table_name);
PREPARE STMT FROM @statement;
EXECUTE STMT;
END IF;
set @statement =
concat('alter table ', target_table_name, ' add ', target_index_type, ' ', target_index_name,
'(', target_columns,
') ', using_str);
PREPARE STMT FROM @statement;
EXECUTE STMT;
end;
d//
delimiter ;
ALTER TABLE `t_ds_task_instance` MODIFY COLUMN `task_params` longtext COMMENT 'job custom parameters' AFTER `app_link`; ALTER TABLE `t_ds_task_instance` MODIFY COLUMN `task_params` longtext COMMENT 'job custom parameters' AFTER `app_link`;
ALTER TABLE `t_ds_process_task_relation` ADD KEY `idx_code` (`project_code`, `process_definition_code`) USING BTREE;
ALTER TABLE `t_ds_process_task_relation_log` ADD KEY `idx_process_code_version` (`process_definition_code`,`process_definition_version`) USING BTREE; call re_add_index('t_ds_process_task_relation','KEY','idx_code', '`project_code`, `process_definition_code`', 'USING BTREE');
ALTER TABLE `t_ds_task_definition_log` ADD INDEX `idx_code_version` (`code`,`version`) USING BTREE; call re_add_index('t_ds_process_task_relation_log','KEY','idx_process_code_version','`process_definition_code`,`process_definition_version`', 'USING BTREE');
call re_add_index('t_ds_task_definition_log','INDEX','idx_code_version','`code`,`version`', 'USING BTREE');
drop procedure if exists re_add_index;

33
dolphinscheduler-dao/src/main/resources/sql/upgrade/2.0.4_schema/mysql/dolphinscheduler_ddl.sql

@ -15,5 +15,34 @@
* limitations under the License. * limitations under the License.
*/ */
ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE; drop procedure if exists re_add_index;
ALTER TABLE `t_ds_task_definition_log` ADD INDEX `idx_project_code` (`project_code`) USING BTREE; delimiter d//
create procedure re_add_index(target_table_name varchar(256),
target_index_type varchar(8), target_index_name varchar(256),
target_columns varchar(512), using_str varchar(256))
begin
declare target_database varchar(256);
select database() into target_database;
IF EXISTS(SELECT *
FROM information_schema.statistics
WHERE table_schema = target_database
AND table_name = target_table_name
AND index_name = target_index_name) THEN
set @statement = concat('drop index ', target_index_name, ' on ', target_table_name);
PREPARE STMT FROM @statement;
EXECUTE STMT;
END IF;
set @statement =
concat('alter table ', target_table_name, ' add ', target_index_type, ' ', target_index_name,
'(', target_columns,
') ', using_str);
PREPARE STMT FROM @statement;
EXECUTE STMT;
end;
d//
delimiter ;
call re_add_index('t_ds_task_instance','INDEX','idx_code_version','`task_code`, `task_definition_version`', 'USING BTREE');
call re_add_index('t_ds_task_definition_log','INDEX','idx_project_code','`project_code`', 'USING BTREE');
drop procedure if exists re_add_index;

2
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.0_schema/mysql/dolphinscheduler_ddl.sql

@ -340,7 +340,7 @@ drop PROCEDURE if EXISTS drop_t_ds_task_instance_key_foreign_key_instance_id;
delimiter d// delimiter d//
CREATE PROCEDURE drop_t_ds_task_instance_key_foreign_key_instance_id() CREATE PROCEDURE drop_t_ds_task_instance_key_foreign_key_instance_id()
BEGIN BEGIN
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_NAME='t_ds_task_instance' WHERE TABLE_NAME='t_ds_task_instance'
AND TABLE_SCHEMA=(SELECT DATABASE()) AND TABLE_SCHEMA=(SELECT DATABASE())
AND INDEX_NAME='foreign_key_instance_id') AND INDEX_NAME='foreign_key_instance_id')

34
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.1.1_schema/mysql/dolphinscheduler_ddl.sql

@ -16,7 +16,37 @@
*/ */
ALTER TABLE `t_ds_worker_group` ADD COLUMN `other_params_json` text DEFAULT NULL COMMENT 'other params json'; 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_process_instance` ADD COLUMN `state_history` text DEFAULT NULL COMMENT 'state history desc' AFTER `state`; 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;
Loading…
Cancel
Save