DROP DATABASE db_fileupload;
DROP DATABASE db_sysdemo1;
DROP DATABASE db_sysdemo2;
CREATE DATABASE db_fileupload DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

CREATE TABLE db_fileupload.file_info (
  file_id     VARCHAR(32) NOT NULL PRIMARY KEY,
  user_id     VARCHAR(32),
  create_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
  COMMENT '创建时间',
  file_name   VARCHAR(255),
  file_size   VARCHAR(32),
  file_path   VARCHAR(128)
)
  COMMENT = '文件表'
  ENGINE = InnoDB;

CREATE DATABASE db_sysdemo1 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE TABLE db_sysdemo1.user_info (
  user_id     VARCHAR(32) NOT NULL,
  username    VARCHAR(32) NOT NULL,
  password    VARCHAR(32) NOT NULL,
  create_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
  COMMENT '创建时间',
  update_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE current_timestamp
  COMMENT '更新时间',
  PRIMARY KEY (user_id)
)
  COMMENT '系统A用户信息表';

CREATE TABLE db_sysdemo1.admin_info
(
  admin_id    VARCHAR(32) NOT NULL PRIMARY KEY ,
  user_id     VARCHAR(32) NOT NULL,
  create_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
  COMMENT '创建时间',
  update_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE current_timestamp
  COMMENT '更新时间',
  CONSTRAINT FK_adminuser FOREIGN KEY (user_id) REFERENCES user_info (user_id)
)
  COMMENT = '管理员表';

CREATE DATABASE db_sysdemo2 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE TABLE db_sysdemo2.user_info (
  user_id     VARCHAR(32) NOT NULL,
  username    VARCHAR(32) NOT NULL,
  password    VARCHAR(32) NOT NULL,
  create_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
  COMMENT '创建时间',
  update_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE current_timestamp
  COMMENT '更新时间',
  PRIMARY KEY (user_id)
)
  COMMENT '系统B用户信息表';

CREATE TABLE db_sysdemo2.admin_info
(
  admin_id    VARCHAR(32) NOT NULL PRIMARY KEY ,
  user_id     VARCHAR(32) NOT NULL,
  create_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
  COMMENT '创建时间',
  update_time TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE current_timestamp
  COMMENT '更新时间',
  CONSTRAINT FK_adminuser FOREIGN KEY (user_id) REFERENCES user_info (user_id)
)
  COMMENT = '管理员表';

GRANT ALL ON db_fileupload.* TO trs@localhost IDENTIFIED BY 'fileupload';
GRANT ALL ON db_sysdemo1.* TO trs@localhost IDENTIFIED BY 'fileupload';
GRANT ALL ON db_sysdemo2.* TO trs@localhost IDENTIFIED BY 'fileupload';
flush privileges;