DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS users_details;
DROP TABLE IF EXISTS emails;
DROP TABLE IF EXISTS authorities;

CREATE TABLE users (
    uid BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    email VARCHAR(320) NOT NULL UNIQUE,
    password VARCHAR(72) NOT NULL,
    account_non_expired BOOLEAN NOT NULL DEFAULT '1',
    account_non_locked BOOLEAN NOT NULL DEFAULT '1',
    credentials_non_expired BOOLEAN NOT NULL DEFAULT '1',
    enabled BOOLEAN NOT NULL DEFAULT '1',
    authorities VARCHAR(128) NOT NULL DEFAULT ''
);

CREATE TABLE persistent_logins (
    username varchar(320) not null,
    series varchar(64) primary key,
    token varchar(64) not null,
    last_used timestamp not null
);

CREATE TABLE users_details (
    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    uid BIGINT NOT NULL,
    prefixx VARCHAR(20) NOT NULL DEFAULT '',
    given VARCHAR(64) NOT NULL DEFAULT '',
    last_name VARCHAR(32) NOT NULL DEFAULT '',
    suffix VARCHAR(40) NOT NULL DEFAULT '',
    preferred VARCHAR(1024) NOT NULL DEFAULT 'unset_1024',
    birthdate VARCHAR(64) NOT NULL DEFAULT 'unset_64'
);

CREATE TABLE emails (
    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    uid BIGINT NOT NULL,
    email VARCHAR(320) NOT NULL
);

CREATE TABLE authorities (
    id BIGINT NOT NULL AUTO_INCREMENT,
    authority VARCHAR(32) NOT NULL,
    PRIMARY KEY (id)
); 


