CREATE TABLE IF NOT EXISTS users (
id BIGINT NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NOT NULL UNIQUE ,
password VARCHAR(255) NOT NULL ,
enabled BOOLEAN NOT NULL DEFAULT TRUE ,
accountNonExpired BOOLEAN NOT NULL DEFAULT TRUE ,
accountNonLocked BOOLEAN NOT NULL DEFAULT TRUE ,
credentialsNonExpired BOOLEAN NOT NULL DEFAULT TRUE ,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS user_authorites (
uid BIGINT NOT NULL,
authority VARCHAR(255) NOT NULL ,
PRIMARY KEY (uid,authority),
FOREIGN KEY uid(uid) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS persistent_logins (
username varchar(64) not null,
series varchar(64) not null,
token varchar(64) not null,
last_used timestamp not null,
PRIMARY KEY (series)
);
CREATE TABLE IF NOT EXISTS usercards (
id BIGINT NOT NULL UNIQUE ,
username VARCHAR(255) NOT NULL UNIQUE ,
pay_password VARCHAR(255) NOT NULL ,
onDate TIMESTAMP ,
amount DOUBLE DEFAULT 0 NOT NULL ,
level INT DEFAULT 0 NOT NULL ,
grades INT DEFAULT 0 NOT NULL ,
cost DOUBLE DEFAULT 0 NOT NULL ,
PRIMARY KEY (id),
FOREIGN KEY uuid(id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE ,
FOREIGN KEY uname(username) REFERENCES users(username) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE INDEX cards ON usercards (id,username,pay_password);
CREATE TABLE IF NOT EXISTS bankcard (
id BIGINT NOT NULL ,
bankid VARCHAR(255) NOT NULL ,
PRIMARY KEY (id,bankid),
FOREIGN KEY bcid(id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS hotels (
id BIGINT AUTO_INCREMENT,
name VARCHAR(255) NOT NULL ,
city VARCHAR(255) NOT NULL ,
locationX DOUBLE NOT NULL ,
locationY DOUBLE NOT NULL ,
passed BOOLEAN DEFAULT NULL ,
manager VARCHAR(255) NOT NULL ,
manager_id BIGINT NOT NULL ,
manager_identity VARCHAR(255) NOT NULL ,
description TEXT NOT NULL ,
PRIMARY KEY (id),
FOREIGN KEY hotelmanager(manager_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS plans (
id BIGINT AUTO_INCREMENT,
hid BIGINT NOT NULL ,
mid BIGINT NOT NULL ,
date TIMESTAMP NOT NULL ,
city VARCHAR(255) NOT NULL ,
room VARCHAR(255) NOT NULL ,
people INT NOT NULL DEFAULT 1,
price DOUBLE NOT NULL DEFAULT 1,
confirmed BOOLEAN NOT NULL DEFAULT FALSE ,
description TEXT NOT NULL ,
PRIMARY KEY (id),
FOREIGN KEY p_hid(hid) REFERENCES hotels(id) ON UPDATE CASCADE ON DELETE CASCADE ,
FOREIGN KEY p_mid(mid) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS bookrecords (
id BIGINT AUTO_INCREMENT,
hid BIGINT NOT NULL ,
mid BIGINT NOT NULL ,
cid BIGINT DEFAULT NULL ,
start TIMESTAMP NOT NULL ,
end TIMESTAMP NOT NULL ,
room VARCHAR(255) NOT NULL ,
passed BOOLEAN DEFAULT NULL ,
faceChecked BOOLEAN DEFAULT FALSE ,
price DOUBLE NOT NULL DEFAULT 0,
total DOUBLE NOT NULL DEFAULT 0,
inCash BOOLEAN DEFAULT FALSE NOT NULL ,
payed BOOLEAN DEFAULT TRUE NOT NULL ,
rooted BOOLEAN DEFAULT FALSE NOT NULL ,
PRIMARY KEY (id),
FOREIGN KEY b_hid(hid) REFERENCES hotels(id) ON DELETE CASCADE ON UPDATE CASCADE ,
FOREIGN KEY b_mid(mid) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE ,
FOREIGN KEY b_cid(cid) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS payrecords (
id BIGINT AUTO_INCREMENT,
uid BIGINT NOT NULL ,
username VARCHAR(255) NOT NULL ,
amount DOUBLE NOT NULL DEFAULT 0,
date TIMESTAMP NOT NULL ,
PRIMARY KEY (id),
FOREIGN KEY pr_uid(uid) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS people (
id BIGINT NOT NULL AUTO_INCREMENT,
bid BIGINT NOT NULL ,
cid BIGINT NOT NULL,
PRIMARY KEY (id)
);