CREATE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
    NEW.updated_at = now();
    RETURN NEW;
END;
$$ language 'plpgsql';

CREATE TABLE account (
    account_id SERIAL PRIMARY KEY,
    username VARCHAR(25) UNIQUE CONSTRAINT username_regex CHECK (username ~ '^[a-zA-Z0-9]{2,25}$') NOT NULL,
    email VARCHAR(254) NOT NULL,
    password CHAR(60) NOT NULL, -- bcrypt
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
    last_login TIMESTAMP
);

CREATE TRIGGER update_account_updated_at BEFORE UPDATE
ON account FOR EACH ROW EXECUTE PROCEDURE
update_updated_at_column();