CREATE DATABASE IF NOT EXISTS porter_user_db;

USE porter_user_db;

DROP TABLE IF EXISTS T_USER;

CREATE TABLE `T_USER` (
  `ID`  INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'user id',
  `USER_NAME`  VARCHAR(64) NOT NULL COMMENT 'user name',
  `PASSWORD`  VARCHAR(64) NOT NULL COMMENT 'user password',
  `ROLE_NAME`  VARCHAR(64) NOT NULL COMMENT 'user role',
  PRIMARY KEY (`ID`)
);

#### password is encrypted for test
insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("admin", "n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", "<PASSWORD>");
insert into T_USER(USER_NAME, PASSWORD, ROLE_NAME) values("guest", "<KEY>=", "guest");

DROP TABLE IF EXISTS T_SESSION;

CREATE TABLE `T_SESSION` (
  `ID`  INTEGER(8) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `SESSION_ID`  VARCHAR(64) NOT NULL COMMENT 'session id',
  `USER_NAME`  VARCHAR(64) NOT NULL COMMENT 'user name',
  `ROLE_NAME`  VARCHAR(64) NOT NULL COMMENT 'user role',
  `CREATION_TIME`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'creation time',
  `ACTIVE_TIME`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'last active time',
  PRIMARY KEY (`ID`)
);
