#注释行以'#'或'--'开头,语句以';'结束,不支持逻辑块(过程、函数、匿名块等)
#建表:单位授权表
drop table if exists mobile_auth_org2;
create table if not exists mobile_auth_org2 (
org_id bigint(20) not null comment '单位ID',
org_name varchar(255) comment '单位名称',
auth_num smallint(8) comment '授权数',
bind_max smallint(2) default 5 comment '最大绑定数,上限10',
bind_right char(1) default '1' comment '绑定权限:0管理员设置,1用户可以设置',
primary key(org_id)
) comment='单位授权表,记录集团移动授权给单位的数量、设备最大绑定数和绑定权限';
insert into mobile_auth_org2(org_id, org_name, auth_num) select org_id, org_name, auth_num from mobile_auth_org;
drop table mobile_auth_org;
alter table mobile_auth_org2 rename to mobile_auth_org;
#建表:用户授权表
drop table if exists mobile_auth_user2;
create table if not exists mobile_auth_user2 (
user_id bigint(20) not null comment '用户ID',
org_id bigint(20) comment '单位ID',
user_name varchar(255) comment '用户名称',
safe_level char(1) default '1' comment '安全级别:1低,2中,3高',
primary key(user_id,org_id)
) comment='用户授权表,记录单位移动授权的用户及用户安全级别';
insert into mobile_auth_user2(user_id, user_name, org_id) select user_id, user_name, org_id from mobile_auth_user;
drop table mobile_auth_user;
alter table mobile_auth_user2 rename to mobile_auth_user;
#建表:用户设备绑定表
drop table if exists mobile_bind_user_client;
create table if not exists mobile_bind_user_client (
org_id bigint(20) not null comment '单位ID',
user_id bigint(20) not null comment '用户ID',
client_id varchar(80) not null comment '设备ID',
client_name varchar(80) comment '设备名称',
client_status char(1) default '1' comment '设备状态:0未绑定,1绑定,2禁用',
primary key(client_id)
) comment='用户设备绑定表,记录用户和设备的绑定关系';
#建表:非安全登录表
drop table if exists mobile_bind_unsafe_login;
create table if not exists mobile_bind_unsafe_login (
user_id bigint(20) not null comment '用户ID',
client_id varchar(80) not null comment '设备ID',
client_name varchar(80) comment '设备名称',
login_time char(19) comment '登录时间',
primary key(user_id,client_id)
) comment='非安全登录表,记录用户安全级别中、未绑定设备登录日志';
#建表:绑定申请表(安全级别高,未绑定设备登录时申请)
drop table if exists mobile_bind_apply;
create table if not exists mobile_bind_apply (
org_id bigint(20) not null comment '单位ID',
user_id bigint(20) not null comment '用户ID',
client_id varchar(80) not null comment '设备ID',
client_name varchar(80) comment '设备名称',
apply_time char(19) not null comment '申请时间',
primary key(user_id,client_id)
) comment='绑定申请表,记录用户安全级别高,未绑定设备登录时的申请';
#建表:用户常用设备表
drop table if exists mobile_bind_commonuse_client;
create table if not exists mobile_bind_commonuse_client (
user_id bigint(20) not null comment '用户ID',
client_id varchar(80) not null comment '设备ID',
client_name varchar(80) comment '设备名称',
primary key(user_id,client_id)
) comment='用户常用设备表,记录用户常用登录设备';
#建表:M1版本表
drop table if exists mobile_m1_version;
create table if not exists mobile_m1_version (
m1_version varchar(16) not null comment 'M1版本号',
primary key(m1_version)
) comment='M1版本表,标识M1版本号';
insert into mobile_m1_version(m1_version) values('1.5.2');