Files
zt-dsc/sql/dm/新增用户与组织关系表并迁移.sql

42 lines
2.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
create table "RUOYI-VUE-PRO".SYSTEM_USER_DEPT (
ID BIGINT primary key,
USER_ID BIGINT not null,
DEPT_ID BIGINT not null,
TENANT_ID BIGINT default 0 not null,
REMARK VARCHAR(2000),
CREATOR VARCHAR(256) default '',
CREATE_TIME TIMESTAMP default CURRENT_TIMESTAMP not null,
UPDATER VARCHAR(256) default '',
DELETED TINYINT default 0 not null,
UPDATE_TIME TIMESTAMP default CURRENT_TIMESTAMP not null
);
comment on table "RUOYI-VUE-PRO".SYSTEM_USER_DEPT is '用户与部门关系表';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.ID is '主键ID';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.USER_ID is '用户ID';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.DEPT_ID is '部门ID';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.TENANT_ID is '租户编号';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.REMARK is '备注';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.CREATOR is '创建者';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.CREATE_TIME is '创建时间';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.UPDATER is '更新者';
comment on column "RUOYI-VUE-PRO".SYSTEM_USER_DEPT.UPDATE_TIME is '更新时间';
-- 1. 将原有用户表中的 DEPT_ID 字段数据迁移到关系表ID 自增,无需指定)
insert into "RUOYI-VUE-PRO".SYSTEM_USER_DEPT (
USER_ID, DEPT_ID, TENANT_ID, REMARK, CREATOR, CREATE_TIME, UPDATER, UPDATE_TIME
)
select
ID as USER_ID,
DEPT_ID,
TENANT_ID,
null as REMARK,
CREATOR,
CREATE_TIME,
UPDATER,
UPDATE_TIME
from "RUOYI-VUE-PRO".SYSTEM_USERS
where DEPT_ID is not null;
-- 移除用户表中的 DEPT_ID 字段
alter table "RUOYI-VUE-PRO".SYSTEM_USERS drop column DEPT_ID;