CREATE SCHEMA Accounts;

CREATE TABLE Accounts.Users (
    id SERIAL PRIMARY KEY,
    email VARCHAR(128) NOT NULL UNIQUE,
    emailVerificationTs TIMESTAMP DEFAULT NULL,
    passwordHash VARCHAR(512) NOT NULL
);



CREATE TABLE Accounts.Profile (
    userId INT NOT NULL REFERENCES Accounts.Users(id),
    username VARCHAR(64) NOT NULL,
    birthdate TIMESTAMP NOT NULL,
    height DECIMAL NOT NULL,
    displayUnit UNIT NOT NULL
);


CREATE TABLE Accounts.UsersAuth (
    userId INT NOT NULL REFERENCES Accounts.Users(id),
    tokenHash VARCHAR(512) NOT NULL,
    device VARCHAR(64) NOT NULL,
    createdTs TIMESTAMP DEFAULT NOW(),
    sourceIp VARCHAR(32) DEFAULT NULL
);



