CREATE TABLE sys_users
(
    id            INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    account       TEXT      NOT NULL UNIQUE,
    username      TEXT      NOT NULL,
    password_hash TEXT      NOT NULL,
    avatar_id     INTEGER,
    created_at    TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at    TIMESTAMPTZ
);

CREATE INDEX idx_sys_users_account ON sys_users (account);

CREATE TRIGGER update_sys_users_updated_at
    BEFORE UPDATE
    ON sys_users
    FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();


COMMENT ON COLUMN sys_users.id IS '主键ID';
COMMENT ON COLUMN sys_users.account IS '用户账号';
COMMENT ON COLUMN sys_users.username IS '用户名称';
COMMENT ON COLUMN sys_users.password_hash IS 'hash密码';
COMMENT ON COLUMN sys_users.avatar_id IS '头像文件id';
COMMENT ON COLUMN sys_users.created_at IS '创建时间';
COMMENT ON COLUMN sys_users.updated_at IS '更新时间';