CREATE TABLE sys_permissions
(
    id         INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    code       TEXT UNIQUE,
    type       SMALLINT  NOT NULL,
    created_at TIMESTAMPTZtz NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ,

    CONSTRAINT unique_type_code UNIQUE (type, code)
);

CREATE TRIGGER update_sys_permissions_updated_at
    BEFORE UPDATE
    ON sys_permissions
    FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

COMMENT ON COLUMN sys_permissions.id IS '主键ID';
COMMENT ON COLUMN sys_permissions.code IS '权限字符，唯一';
COMMENT ON COLUMN sys_permissions.code IS '权限类型，0: 菜单 1: api';
COMMENT ON COLUMN sys_permissions.created_at IS '创建时间';
COMMENT ON COLUMN sys_permissions.updated_at IS '更新时间';