-- 已有库升级：小程序用户表扩展 + 后台「微信用户」菜单
-- 在 daocheng 库执行一次即可

ALTER TABLE `dc_mp_user`
  ADD COLUMN `unionid` varchar(64) NOT NULL DEFAULT '' AFTER `openid`,
  ADD COLUMN `session_key` varchar(128) NOT NULL DEFAULT '' AFTER `unionid`,
  ADD COLUMN `status` tinyint NOT NULL DEFAULT 1 COMMENT '1正常 0禁用' AFTER `gender`;

ALTER TABLE `dc_mp_user` ADD KEY `idx_openid` (`openid`);

INSERT INTO `dc_sys_menu` (`id`, `parent_id`, `name`, `type`, `path`, `component`, `perms`, `icon`, `sort`, `status`, `create_time`, `update_time`)
SELECT 5, 1, '用户管理', 2, '/system/mp-user', 'system/mp-user/index', 'system:mp:list', 'avatar', 4, 1, NOW(), NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `dc_sys_menu` WHERE `id` = 5);

INSERT INTO `dc_sys_menu` (`id`, `parent_id`, `name`, `type`, `path`, `component`, `perms`, `icon`, `sort`, `status`, `create_time`, `update_time`)
SELECT 103, 5, '编辑用户', 3, '', NULL, 'system:mp:edit', '', 1, 1, NOW(), NOW()
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `dc_sys_menu` WHERE `id` = 103);

INSERT INTO `dc_sys_role_menu` (`role_id`, `menu_id`)
SELECT 1, 5 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `dc_sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 5);

INSERT INTO `dc_sys_role_menu` (`role_id`, `menu_id`)
SELECT 1, 103 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `dc_sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 103);
