-- ----------------------------
-- Table structure for system_menu_data_rule
-- ----------------------------
CREATE TABLE system_menu_data_rule (
    id bigint NOT NULL PRIMARY KEY,
    menu_id bigint NOT NULL,
    rule_name varchar(100) NOT NULL,
    rule_column varchar(100) DEFAULT NULL NULL,
    rule_conditions varchar(20) NOT NULL,
    rule_value varchar(500) NOT NULL,
    status smallint DEFAULT 1 NOT NULL,
    sort int DEFAULT 0 NOT NULL,
    remark varchar(500) DEFAULT NULL NULL,
    creator varchar(64) DEFAULT '' NULL,
    create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updater varchar(64) DEFAULT '' NULL,
    update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
    deleted bit DEFAULT '0' NOT NULL,
    tenant_id bigint DEFAULT 0 NOT NULL
);

-- CREATE INDEX idx_menu_data_rule_menu ON system_menu_data_rule (menu_id);
-- CREATE INDEX idx_menu_data_rule_tenant ON system_menu_data_rule (tenant_id);

COMMENT ON COLUMN system_menu_data_rule.id IS '规则ID';
COMMENT ON COLUMN system_menu_data_rule.menu_id IS '菜单ID';
COMMENT ON COLUMN system_menu_data_rule.rule_name IS '规则名称';
COMMENT ON COLUMN system_menu_data_rule.rule_column IS '规则字段（数据库列名）';
COMMENT ON COLUMN system_menu_data_rule.rule_conditions IS '规则条件（=、>、<、IN、LIKE等）';
COMMENT ON COLUMN system_menu_data_rule.rule_value IS '规则值（支持变量如#{userId}、#{deptId}）';
COMMENT ON COLUMN system_menu_data_rule.status IS '状态(0=禁用 1=启用)';
COMMENT ON COLUMN system_menu_data_rule.sort IS '排序';
COMMENT ON COLUMN system_menu_data_rule.remark IS '备注';
COMMENT ON COLUMN system_menu_data_rule.creator IS '创建者';
COMMENT ON COLUMN system_menu_data_rule.create_time IS '创建时间';
COMMENT ON COLUMN system_menu_data_rule.updater IS '更新者';
COMMENT ON COLUMN system_menu_data_rule.update_time IS '更新时间';
COMMENT ON COLUMN system_menu_data_rule.deleted IS '是否删除';
COMMENT ON COLUMN system_menu_data_rule.tenant_id IS '租户编号';
COMMENT ON TABLE system_menu_data_rule IS '菜单数据规则表';

-- ----------------------------
-- Table structure for system_role_menu_data_rule
-- ----------------------------
CREATE TABLE system_role_menu_data_rule (
    id bigint NOT NULL PRIMARY KEY,
    role_id bigint NOT NULL,
    menu_id bigint NOT NULL,
    data_rule_id bigint NOT NULL,
    creator varchar(64) DEFAULT '' NULL,
    create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updater varchar(64) DEFAULT '' NULL,
    update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
    deleted bit DEFAULT '0' NOT NULL,
    tenant_id bigint DEFAULT 0 NOT NULL
);

-- CREATE INDEX idx_rmdr_role ON system_role_menu_data_rule (role_id);
-- CREATE INDEX idx_rmdr_menu ON system_role_menu_data_rule (menu_id);
-- CREATE INDEX idx_rmdr_tenant ON system_role_menu_data_rule (tenant_id);
-- CREATE INDEX idx_rmdr_role_menu_rule ON system_role_menu_data_rule (role_id, menu_id, data_rule_id);

COMMENT ON COLUMN system_role_menu_data_rule.id IS '自增主键';
COMMENT ON COLUMN system_role_menu_data_rule.role_id IS '角色ID';
COMMENT ON COLUMN system_role_menu_data_rule.menu_id IS '菜单ID';
COMMENT ON COLUMN system_role_menu_data_rule.data_rule_id IS '数据规则ID';
COMMENT ON COLUMN system_role_menu_data_rule.creator IS '创建者';
COMMENT ON COLUMN system_role_menu_data_rule.create_time IS '创建时间';
COMMENT ON COLUMN system_role_menu_data_rule.updater IS '更新者';
COMMENT ON COLUMN system_role_menu_data_rule.update_time IS '更新时间';
COMMENT ON COLUMN system_role_menu_data_rule.deleted IS '是否删除';
COMMENT ON COLUMN system_role_menu_data_rule.tenant_id IS '租户编号';
COMMENT ON TABLE system_role_menu_data_rule IS '角色菜单数据规则关联表';
