mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-02 12:17:43 +08:00
[bug][db] Table relation_project_user have duplicate record (#9536)
* update sql ddl * fix syntax err
This commit is contained in:
parent
8fab44cb93
commit
c837580c68
@ -73,6 +73,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -526,7 +527,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
|
||||
userMapper.queryTenantCodeByUserId(id);
|
||||
|
||||
|
||||
|
||||
accessTokenMapper.deleteAccessTokenByUserId(id);
|
||||
|
||||
userMapper.deleteById(id);
|
||||
@ -562,10 +562,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
|
||||
if (check(result, StringUtils.isEmpty(projectIds), Status.SUCCESS)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String[] projectIdArr = projectIds.split(",");
|
||||
|
||||
for (String projectId : projectIdArr) {
|
||||
Arrays.stream(projectIds.split(",")).distinct().forEach(projectId -> {
|
||||
Date now = new Date();
|
||||
ProjectUser projectUser = new ProjectUser();
|
||||
projectUser.setUserId(userId);
|
||||
@ -574,8 +571,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
|
||||
projectUser.setCreateTime(now);
|
||||
projectUser.setUpdateTime(now);
|
||||
projectUserMapper.insert(projectUser);
|
||||
}
|
||||
|
||||
});
|
||||
putMsg(result, Status.SUCCESS);
|
||||
|
||||
return result;
|
||||
@ -614,15 +610,18 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 4. maintain the relationship between project and user
|
||||
final Date today = new Date();
|
||||
ProjectUser projectUser = new ProjectUser();
|
||||
projectUser.setUserId(userId);
|
||||
projectUser.setProjectId(project.getId());
|
||||
projectUser.setPerm(7);
|
||||
projectUser.setCreateTime(today);
|
||||
projectUser.setUpdateTime(today);
|
||||
this.projectUserMapper.insert(projectUser);
|
||||
// 4. maintain the relationship between project and user if not exists
|
||||
ProjectUser projectUser = projectUserMapper.queryProjectRelation(project.getId(), userId);
|
||||
if (projectUser == null) {
|
||||
Date today = new Date();
|
||||
projectUser = new ProjectUser();
|
||||
projectUser.setUserId(userId);
|
||||
projectUser.setProjectId(project.getId());
|
||||
projectUser.setPerm(7);
|
||||
projectUser.setCreateTime(today);
|
||||
projectUser.setUpdateTime(today);
|
||||
this.projectUserMapper.insert(projectUser);
|
||||
}
|
||||
|
||||
this.putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
|
@ -709,7 +709,8 @@ CREATE TABLE t_ds_relation_project_user
|
||||
perm int(11) DEFAULT '1',
|
||||
create_time datetime DEFAULT NULL,
|
||||
update_time datetime DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uniq_uid_pid(user_id,project_id)
|
||||
);
|
||||
|
||||
-- ----------------------------
|
||||
|
@ -709,7 +709,7 @@ CREATE TABLE `t_ds_relation_project_user` (
|
||||
`create_time` datetime DEFAULT NULL COMMENT 'create time',
|
||||
`update_time` datetime DEFAULT NULL COMMENT 'update time',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user_id_index` (`user_id`) USING BTREE
|
||||
UNIQUE KEY uniq_uid_pid(user_id,project_id)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
|
@ -625,7 +625,8 @@ CREATE TABLE t_ds_relation_project_user (
|
||||
perm int DEFAULT '1' ,
|
||||
create_time timestamp DEFAULT NULL ,
|
||||
update_time timestamp DEFAULT NULL ,
|
||||
PRIMARY KEY (id)
|
||||
PRIMARY KEY (id),
|
||||
CONSTRAINT t_ds_relation_project_user_un UNIQUE (user_id, project_id)
|
||||
) ;
|
||||
create index relation_project_user_id_index on t_ds_relation_project_user (user_id);
|
||||
|
||||
|
@ -57,3 +57,8 @@ d//
|
||||
delimiter ;
|
||||
CALL uc_dolphin_T_t_ds_alert_R_sign;
|
||||
DROP PROCEDURE uc_dolphin_T_t_ds_alert_R_sign;
|
||||
|
||||
-- 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);
|
||||
|
||||
|
||||
|
@ -45,4 +45,8 @@ $BODY$;
|
||||
|
||||
select dolphin_update_metadata();
|
||||
|
||||
d//
|
||||
d//
|
||||
|
||||
-- add unique key to t_ds_relation_project_user
|
||||
CREATE UNIQUE INDEX t_ds_relation_project_user_un
|
||||
on t_ds_relation_project_user (user_id, project_id);
|
Loading…
Reference in New Issue
Block a user