sys_user_dept.sql 804 B

123456789101112131415161718192021
  1. -- ----------------------------
  2. -- 用户与部门关联表 用户1-N部门
  3. -- ----------------------------
  4. drop table if exists sys_user_dept;
  5. create table sys_user_dept
  6. (
  7. user_id bigint(20) not null comment '用户ID',
  8. dept_id bigint(20) not null comment '部门ID',
  9. post_id bigint(20) not null comment '岗位ID',
  10. is_main char(1) not null default '0' comment '是否主岗(0否 1是)',
  11. primary key (user_id, dept_id, post_id)
  12. ) engine=innodb comment = '用户与部门关联表';
  13. -- ----------------------------
  14. -- 初始化-用户与部门关联表数据
  15. -- 将现有用户数据从sys_user.dept_id迁移过来
  16. -- ----------------------------
  17. insert into sys_user_dept (user_id, dept_id)
  18. select user_id, dept_id
  19. from sys_user
  20. where dept_id is not null and del_flag = '0';