drop table if exists t_users;
CREATE TABLE t_users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL
);

drop table if exists t_roles;
CREATE TABLE t_roles (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);

CREATE TABLE permissions (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);

drop table if exists t_permissions;
CREATE TABLE t_permissions (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);

drop table if exists t_user_roles;
CREATE TABLE t_user_roles (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
role_id INT
);

drop table if exists t_role_permissions;
CREATE TABLE t_role_permissions (
id INT AUTO_INCREMENT PRIMARY KEY,
role_id INT,
permission_id INT
);

drop table if exists t_actions;
create table t_actions
(
id int AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);

drop table if exists t_sessions;
create table if not exists t_sessions (
id bigint,
username varchar(255) not null default "",
refresh_token varchar(255) not null default "",
client_ip varchar(255) not null default "",
user_agent varchar(255) NOT NULL default "",
is_blocked tinyint not null default "0",
expires_at datetime not null,
created_at int not null default "0",
primary key id(id),
unique key username(username)
);
