[fix](dolphinscheduler-dao) fix upgrade to 3.1.0 sql missing field (#12314) (#12315)

This commit is contained in:
Hengdong Gong 2022-10-26 12:32:05 +08:00 committed by GitHub
parent 04aa125ba2
commit 3030419ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -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;

View File

@ -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);