CREATE TABLE sys_menus
(
    id         INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    name       TEXT        NOT NULL,
    path       TEXT        NOT NULL,
    component  TEXT,
    type       SMALLINT    NOT NULL,
    hidden     BOOLEAN              DEFAULT FALSE,
    sort       INTEGER              DEFAULT 0,
    status     SMALLINT    NOT NULL DEFAULT 1,
    parent_id  INTEGER,
    icon       INTEGER,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ,

    CHECK (type IN (0, 1, 2)),
    CHECK (status IN (0, 1))
);


CREATE TRIGGER update_sys_menus_updated_at
    BEFORE UPDATE
    ON sys_menus
    FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

COMMENT ON COLUMN sys_menus.id IS '主键ID';
COMMENT ON COLUMN sys_menus.name IS '菜单名称';
COMMENT ON COLUMN sys_menus.path IS '菜单路径';
COMMENT ON COLUMN sys_menus.component IS '组件路径';
COMMENT ON COLUMN sys_menus.type IS '菜单类型 0: 目录 1: 菜单 2: button';
COMMENT ON COLUMN sys_menus.sort IS '菜单排序';
COMMENT ON COLUMN sys_menus.hidden IS '是否隐藏菜单';
COMMENT ON COLUMN sys_menus.status IS '菜单状态 1: 启用 0: 禁用';
COMMENT ON COLUMN sys_menus.parent_id IS '父级id';
COMMENT ON COLUMN sys_menus.icon IS '菜单icon';
COMMENT ON COLUMN sys_menus.created_at IS '创建时间';
COMMENT ON COLUMN sys_menus.updated_at IS '更新时间';