Browse Source

[Improvement] Resource authority module database table unique index increased. (#10807)

* Resource authority module database table unique index increased.

* add unique in sql file

* rerun

* ut fix

* e2e rerun

* dao un fix
3.1.0-release
WangJPLeo 2 years ago committed by GitHub
parent
commit
b8a90d801e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql
  2. 13
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql
  3. 11
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql
  4. 13
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.0.0_schema/mysql/dolphinscheduler_ddl.sql
  5. 13
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.0.0_schema/postgresql/dolphinscheduler_ddl.sql
  6. 14
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java

13
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql

@ -638,7 +638,9 @@ CREATE TABLE t_ds_project
flag tinyint(4) DEFAULT '1', flag tinyint(4) DEFAULT '1',
create_time datetime NOT NULL, create_time datetime NOT NULL,
update_time datetime DEFAULT NULL, update_time datetime DEFAULT NULL,
PRIMARY KEY (id) PRIMARY KEY (id),
UNIQUE KEY unique_name (name),
UNIQUE KEY unique_code (code)
); );
-- ---------------------------- -- ----------------------------
@ -656,7 +658,8 @@ CREATE TABLE t_ds_queue
queue varchar(64) DEFAULT NULL, queue varchar(64) DEFAULT NULL,
create_time datetime DEFAULT NULL, create_time datetime DEFAULT NULL,
update_time datetime DEFAULT NULL, update_time datetime DEFAULT NULL,
PRIMARY KEY (id) PRIMARY KEY (id),
UNIQUE KEY unique_queue_name (queue_name)
); );
-- ---------------------------- -- ----------------------------
@ -886,7 +889,8 @@ CREATE TABLE t_ds_tenant
queue_id int(11) DEFAULT NULL, queue_id int(11) DEFAULT NULL,
create_time datetime DEFAULT NULL, create_time datetime DEFAULT NULL,
update_time datetime DEFAULT NULL, update_time datetime DEFAULT NULL,
PRIMARY KEY (id) PRIMARY KEY (id),
UNIQUE KEY unique_tenant_code (tenant_code)
); );
-- ---------------------------- -- ----------------------------
@ -911,7 +915,8 @@ CREATE TABLE t_ds_udfs
resource_name varchar(255) NOT NULL, resource_name varchar(255) NOT NULL,
create_time datetime NOT NULL, create_time datetime NOT NULL,
update_time datetime NOT NULL, update_time datetime NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id),
UNIQUE KEY unique_func_name (func_name)
); );
-- ---------------------------- -- ----------------------------

13
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql

@ -642,7 +642,9 @@ CREATE TABLE `t_ds_project` (
`create_time` datetime NOT NULL COMMENT 'create time', `create_time` datetime NOT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time', `update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `user_id_index` (`user_id`) USING BTREE KEY `user_id_index` (`user_id`) USING BTREE,
UNIQUE KEY `unique_name`(`name`),
UNIQUE KEY `unique_code`(`code`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ---------------------------- -- ----------------------------
@ -659,7 +661,8 @@ CREATE TABLE `t_ds_queue` (
`queue` varchar(64) DEFAULT NULL COMMENT 'yarn queue name', `queue` varchar(64) DEFAULT NULL COMMENT 'yarn queue name',
`create_time` datetime DEFAULT NULL COMMENT 'create time', `create_time` datetime DEFAULT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time', `update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`) PRIMARY KEY (`id`),
UNIQUE KEY `unique_queue_name`(`queue_name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ---------------------------- -- ----------------------------
@ -882,7 +885,8 @@ CREATE TABLE `t_ds_tenant` (
`queue_id` int(11) DEFAULT NULL COMMENT 'queue id', `queue_id` int(11) DEFAULT NULL COMMENT 'queue id',
`create_time` datetime DEFAULT NULL COMMENT 'create time', `create_time` datetime DEFAULT NULL COMMENT 'create time',
`update_time` datetime DEFAULT NULL COMMENT 'update time', `update_time` datetime DEFAULT NULL COMMENT 'update time',
PRIMARY KEY (`id`) PRIMARY KEY (`id`),
UNIQUE KEY `unique_tenant_code`(`tenant_code`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ---------------------------- -- ----------------------------
@ -906,7 +910,8 @@ CREATE TABLE `t_ds_udfs` (
`resource_name` varchar(255) NOT NULL COMMENT 'resource name', `resource_name` varchar(255) NOT NULL COMMENT 'resource name',
`create_time` datetime NOT NULL COMMENT 'create time', `create_time` datetime NOT NULL COMMENT 'create time',
`update_time` datetime NOT NULL COMMENT 'update time', `update_time` datetime NOT NULL COMMENT 'update time',
PRIMARY KEY (`id`) PRIMARY KEY (`id`),
UNIQUE KEY `unique_func_name`(`func_name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ---------------------------- -- ----------------------------

11
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql

@ -571,6 +571,8 @@ CREATE TABLE t_ds_project (
) ; ) ;
create index user_id_index on t_ds_project (user_id); create index user_id_index on t_ds_project (user_id);
CREATE UNIQUE INDEX unique_name on t_ds_project (name);
CREATE UNIQUE INDEX unique_code on t_ds_project (code);
-- --
-- Table structure for table t_ds_queue -- Table structure for table t_ds_queue
@ -585,7 +587,8 @@ CREATE TABLE t_ds_queue (
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL ,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
-- add unique key to t_ds_queue
CREATE UNIQUE INDEX unique_queue_name on t_ds_queue (queue_name);
-- --
-- Table structure for table t_ds_relation_datasource_user -- Table structure for table t_ds_relation_datasource_user
@ -601,7 +604,6 @@ CREATE TABLE t_ds_relation_datasource_user (
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL ,
PRIMARY KEY (id) PRIMARY KEY (id)
) ; ) ;
;
-- --
-- Table structure for table t_ds_relation_process_instance -- Table structure for table t_ds_relation_process_instance
@ -787,6 +789,8 @@ CREATE TABLE t_ds_tenant (
update_time timestamp DEFAULT NULL , update_time timestamp DEFAULT NULL ,
PRIMARY KEY (id) PRIMARY KEY (id)
) ; ) ;
-- add unique key to t_ds_tenant
CREATE UNIQUE INDEX unique_tenant_code on t_ds_tenant (tenant_code);
-- --
-- Table structure for table t_ds_udfs -- Table structure for table t_ds_udfs
@ -808,6 +812,8 @@ CREATE TABLE t_ds_udfs (
update_time timestamp NOT NULL , update_time timestamp NOT NULL ,
PRIMARY KEY (id) PRIMARY KEY (id)
) ; ) ;
-- add unique key to t_ds_udfs
CREATE UNIQUE INDEX unique_func_name on t_ds_udfs (func_name);
-- --
-- Table structure for table t_ds_user -- Table structure for table t_ds_user
@ -967,7 +973,6 @@ DROP SEQUENCE IF EXISTS t_ds_worker_server_id_sequence;
CREATE SEQUENCE t_ds_worker_server_id_sequence; CREATE SEQUENCE t_ds_worker_server_id_sequence;
ALTER TABLE t_ds_worker_server ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_server_id_sequence'); ALTER TABLE t_ds_worker_server ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_server_id_sequence');
-- Records of t_ds_user?user : admin , password : dolphinscheduler123 -- Records of t_ds_user?user : admin , password : dolphinscheduler123
INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time, time_zone) INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time, time_zone)
VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22', 'Asia/Shanghai'); VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22', 'Asia/Shanghai');

13
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.0.0_schema/mysql/dolphinscheduler_ddl.sql

@ -61,6 +61,19 @@ DROP PROCEDURE uc_dolphin_T_t_ds_alert_R_sign;
-- add unique key to t_ds_relation_project_user -- add unique key to t_ds_relation_project_user
ALTER TABLE t_ds_relation_project_user ADD UNIQUE KEY uniq_uid_pid(user_id,project_id); ALTER TABLE t_ds_relation_project_user ADD UNIQUE KEY uniq_uid_pid(user_id,project_id);
-- add unique key to t_ds_project
ALTER TABLE t_ds_project ADD UNIQUE KEY unique_name(name);
ALTER TABLE t_ds_project ADD UNIQUE KEY unique_code(code);
-- add unique key to t_ds_queue
ALTER TABLE t_ds_queue ADD UNIQUE KEY unique_queue_name(queue_name);
-- add unique key to t_ds_udfs
ALTER TABLE t_ds_udfs ADD UNIQUE KEY unique_func_name(func_name);
-- add unique key to t_ds_tenant
ALTER TABLE t_ds_tenant ADD UNIQUE KEY unique_tenant_code(tenant_code);
ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE; ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE;
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` ADD KEY `idx_code` (`project_code`, `process_definition_code`) USING BTREE;

13
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.0.0_schema/postgresql/dolphinscheduler_ddl.sql

@ -60,6 +60,19 @@ d//
CREATE UNIQUE INDEX t_ds_relation_project_user_un CREATE UNIQUE INDEX t_ds_relation_project_user_un
on t_ds_relation_project_user (user_id, project_id); on t_ds_relation_project_user (user_id, project_id);
-- add unique key to t_ds_project
CREATE UNIQUE INDEX unique_name on t_ds_project (name);
CREATE UNIQUE INDEX unique_code on t_ds_project (code);
-- add unique key to t_ds_queue
CREATE UNIQUE INDEX unique_queue_name on t_ds_queue (queue_name);
-- add unique key to t_ds_udfs
CREATE UNIQUE INDEX unique_func_name on t_ds_udfs (func_name);
-- add unique key to t_ds_tenant
CREATE UNIQUE INDEX unique_tenant_code on t_ds_tenant (tenant_code);
delimiter d// delimiter d//
CREATE OR REPLACE FUNCTION public.dolphin_update_metadata( CREATE OR REPLACE FUNCTION public.dolphin_update_metadata(
) )

14
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java

@ -54,10 +54,10 @@ public class UdfFuncMapperTest extends BaseDaoTest {
* *
* @return UdfFunc * @return UdfFunc
*/ */
private UdfFunc insertOne() { private UdfFunc insertOne(String funcName) {
UdfFunc udfFunc = new UdfFunc(); UdfFunc udfFunc = new UdfFunc();
udfFunc.setUserId(1); udfFunc.setUserId(1);
udfFunc.setFuncName("dolphin_udf_func"); udfFunc.setFuncName(funcName);
udfFunc.setClassName("org.apache.dolphinscheduler.test.mr"); udfFunc.setClassName("org.apache.dolphinscheduler.test.mr");
udfFunc.setType(UdfType.HIVE); udfFunc.setType(UdfType.HIVE);
udfFunc.setResourceId(1); udfFunc.setResourceId(1);
@ -76,7 +76,7 @@ public class UdfFuncMapperTest extends BaseDaoTest {
private UdfFunc insertOne(User user) { private UdfFunc insertOne(User user) {
UdfFunc udfFunc = new UdfFunc(); UdfFunc udfFunc = new UdfFunc();
udfFunc.setUserId(user.getId()); udfFunc.setUserId(user.getId());
udfFunc.setFuncName("dolphin_udf_func"); udfFunc.setFuncName("dolphin_udf_func" + user.getUserName());
udfFunc.setClassName("org.apache.dolphinscheduler.test.mr"); udfFunc.setClassName("org.apache.dolphinscheduler.test.mr");
udfFunc.setType(UdfType.HIVE); udfFunc.setType(UdfType.HIVE);
udfFunc.setResourceId(1); udfFunc.setResourceId(1);
@ -164,7 +164,7 @@ public class UdfFuncMapperTest extends BaseDaoTest {
@Test @Test
public void testUpdate() { public void testUpdate() {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne("func1");
udfFunc.setResourceName("dolphin_resource_update"); udfFunc.setResourceName("dolphin_resource_update");
udfFunc.setResourceId(2); udfFunc.setResourceId(2);
udfFunc.setClassName("org.apache.dolphinscheduler.test.mrUpdate"); udfFunc.setClassName("org.apache.dolphinscheduler.test.mrUpdate");
@ -181,7 +181,7 @@ public class UdfFuncMapperTest extends BaseDaoTest {
@Test @Test
public void testDelete() { public void testDelete() {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne("func2");
//delete //delete
int delete = udfFuncMapper.deleteById(udfFunc.getId()); int delete = udfFuncMapper.deleteById(udfFunc.getId());
Assert.assertEquals(delete, 1); Assert.assertEquals(delete, 1);
@ -193,9 +193,9 @@ public class UdfFuncMapperTest extends BaseDaoTest {
@Test @Test
public void testQueryUdfByIdStr() { public void testQueryUdfByIdStr() {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne("func3");
//insertOne //insertOne
UdfFunc udfFunc1 = insertOne(); UdfFunc udfFunc1 = insertOne("func4");
Integer[] idArray = new Integer[]{udfFunc.getId(), udfFunc1.getId()}; Integer[] idArray = new Integer[]{udfFunc.getId(), udfFunc1.getId()};
//queryUdfByIdStr //queryUdfByIdStr
List<UdfFunc> udfFuncList = udfFuncMapper.queryUdfByIdStr(idArray, ""); List<UdfFunc> udfFuncList = udfFuncMapper.queryUdfByIdStr(idArray, "");

Loading…
Cancel
Save