CREATE SCHEMA Stats;

CREATE TABLE Stats.Log (
    id SERIAL PRIMARY KEY,
    userId INT NOT NULL REFERENCES Accounts.Users(id),
    logType LogType NOT NULL DEFAULT 'Weight',
    value DECIMAL NOT NULL,
    recordedTs TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE INDEX log_logType ON Stats.Log USING btree (logType);

CREATE TABLE Stats.LogGoal (
    id SERIAL PRIMARY KEY,
    userId INT NOT NULL REFERENCES Accounts.Users(id),
    logType LogType NOT NULL,
    value DECIMAL NOT NULL,
    startTs TIMESTAMP NOT NULL DEFAULT NOW(),
    endTs TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE INDEX log_userId ON Stats.LogGoal USING btree (userId);
