-- 角色表按渠道隔离：dept_id=0 为默认模板角色，各渠道拥有独立角色副本

ALTER TABLE `sa_system_role`
    ADD COLUMN `dept_id` bigint(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT '所属渠道ID，0=默认模板' AFTER `id`,
    ADD INDEX `idx_dept_id` (`dept_id`);

UPDATE `sa_system_role` SET `dept_id` = 0 WHERE `dept_id` IS NULL OR `id` > 1;

ALTER TABLE `sa_system_role` DROP INDEX `uk_slug`;
ALTER TABLE `sa_system_role` ADD UNIQUE KEY `uk_dept_code` (`dept_id`, `code`);
