-- 修复会员分销字段漏合并导致的后台用户中心查询报错。
-- 适用于已存在 xxk_distribution_relation / xxk_distribution_commission 老结构的数据库。

ALTER TABLE `xxk_distribution_relation`
    ADD COLUMN `member_user_id` BIGINT NULL COMMENT '当前会员ID' AFTER `grand_parent_user_id`,
    ADD COLUMN `parent_member_user_id` BIGINT NULL COMMENT '一级上级会员ID' AFTER `member_user_id`,
    ADD COLUMN `grand_parent_member_user_id` BIGINT NULL COMMENT '二级上级会员ID' AFTER `parent_member_user_id`,
    ADD UNIQUE INDEX `uk_xxk_distribution_relation_member_user_id` (`member_user_id`),
    ADD KEY `idx_xxk_distribution_relation_parent_member_user_id` (`parent_member_user_id`);

ALTER TABLE `xxk_distribution_commission`
    ADD COLUMN `member_user_id` BIGINT NULL COMMENT '佣金归属会员ID' AFTER `from_user_id`,
    ADD COLUMN `from_member_user_id` BIGINT NULL COMMENT '消费会员ID' AFTER `member_user_id`,
    ADD KEY `idx_xxk_distribution_commission_member_user_id` (`member_user_id`),
    ADD KEY `idx_xxk_distribution_commission_from_member_user_id` (`from_member_user_id`);
