fix: 修复使用mariadb数据库部分函数不兼容问题

This commit is contained in:
wangjiahao 2022-04-25 19:48:39 +08:00
parent bb970c3907
commit 402fddac99

View File

@ -16,3 +16,148 @@ INSERT INTO `system_parameter`(`param_key`, `param_value`, `type`, `sort`) VALUE
ALTER TABLE `my_plugin` ADD COLUMN `ds_type` VARCHAR(45) NULL COMMENT '数据源类型' AFTER `icon`;
INSERT INTO `my_plugin` (`plugin_id`, `name`, `store`, `free`, `cost`, `category`, `descript`, `version`, `creator`, `load_mybatis`, `install_time`, `module_name`, `ds_type`) VALUES ('5', 'Maxcompute 数据源插件', 'default', '0', '0', 'datasource', 'Maxcompute 插件', '1.0-SNAPSHOT', 'DATAEASE', '0', '1650765903630', 'maxcompute-backend', 'maxcompute');
DROP FUNCTION IF EXISTS `copy_auth`;
delimiter ;;
CREATE FUNCTION `copy_auth`(authSource varchar(255),authSourceType varchar(255),authUser varchar(255))
RETURNS varchar(255) CHARSET utf8mb4
READS SQL DATA
BEGIN
DECLARE authId varchar(255);
DECLARE userId varchar(255);
DECLARE copyId varchar(255);
DECLARE selectPid varchar(255);
select uuid() into authId;
select uuid() into copyId;
select max(sys_user.user_id) into userId from sys_user where username= authUser;
SELECT pid into selectPid FROM v_auth_model WHERE id = authSource AND model_type = authSourceType;
delete from sys_auth_detail where auth_id in (
select id from sys_auth where sys_auth.auth_source=authSource and sys_auth.auth_source_type=authSourceType
);
delete from sys_auth where sys_auth.auth_source=authSource and sys_auth.auth_source_type=authSourceType;
INSERT INTO sys_auth (
id,
auth_source,
auth_source_type,
auth_target,
auth_target_type,
auth_time,
auth_user
)
VALUES
(
authId,
authSource,
authSourceType,
userId,
'user',
unix_timestamp(
now())* 1000,'auto');
INSERT INTO sys_auth_detail (
id,
auth_id,
privilege_name,
privilege_type,
privilege_value,
privilege_extend,
remark,
create_user,
create_time
) SELECT
uuid() AS id,
authId AS auth_id,
sys_auth_detail.privilege_name,
sys_auth_detail.privilege_type,
1,
sys_auth_detail.privilege_extend,
sys_auth_detail.remark,
'auto' AS create_user,
unix_timestamp(now())* 1000 AS create_time
FROM
sys_auth_detail where auth_id =authSourceType;
/**继承第一父级权限**/
insert into sys_auth(
id,
auth_source,
auth_source_type,
auth_target,
auth_target_type,
auth_time,
auth_user,
copy_from,
copy_id
)
SELECT
uuid() as id,
authSource as auth_source,
authSourceType as auth_source_type,
auth_target,
auth_target_type,
NOW()* 1000 as auth_time,
'auto' as auth_user,
id as copy_from,
copyId as copy_id
FROM
sys_auth
WHERE
auth_source =selectPid
AND auth_source_type = authSourceType
and concat(auth_target,'-',auth_target_type) !=CONCAT(userId,'-','user');
INSERT INTO sys_auth_detail (
id,
auth_id,
privilege_name,
privilege_type,
privilege_value,
privilege_extend,
remark,
create_user,
create_time,
copy_from,
copy_id
) SELECT
uuid() AS id,
sa_copy.t_id AS auth_id,
sys_auth_detail.privilege_name,
sys_auth_detail.privilege_type,
sys_auth_detail.privilege_value,
sys_auth_detail.privilege_extend,
sys_auth_detail.remark,
'auto' AS create_user,
unix_timestamp(
now())* 1000 AS create_time,
id AS copy_from,
copyId AS copy_id
FROM
sys_auth_detail
INNER JOIN (
SELECT
id AS t_id,
copy_from AS s_id
FROM
sys_auth
WHERE
copy_id = copyId
) sa_copy ON sys_auth_detail.auth_id = sa_copy.s_id;
RETURN 'success';
END
;;
delimiter ;