-- ec_promotion_fee → ec_ad_fee:去掉推广费类型、类目,并删除类型表 -- 1) 去掉对类型 / 类目的外键与索引、列 ALTER TABLE `ec_promotion_fee` DROP FOREIGN KEY `fk_ec_promotion_fee_type`, DROP FOREIGN KEY `fk_ec_promotion_fee_category`; ALTER TABLE `ec_promotion_fee` DROP INDEX `idx_fee_type_id`, DROP INDEX `idx_category_id`; ALTER TABLE `ec_promotion_fee` DROP COLUMN `fee_type_id`, DROP COLUMN `category_id`; -- 2) 重命名表 RENAME TABLE `ec_promotion_fee` TO `ec_ad_fee`; -- 3) 外键 / 索引名对齐新表(先删旧约束再重建) ALTER TABLE `ec_ad_fee` DROP FOREIGN KEY `fk_ec_promotion_fee_company`, DROP FOREIGN KEY `fk_ec_promotion_fee_creator`, DROP FOREIGN KEY `fk_ec_promotion_fee_shop`, DROP FOREIGN KEY `fk_ec_promotion_fee_product`, DROP FOREIGN KEY `fk_ec_promotion_fee_updater`; ALTER TABLE `ec_ad_fee` DROP INDEX `fk_ec_promotion_fee_creator`, DROP INDEX `fk_ec_promotion_fee_updater`; ALTER TABLE `ec_ad_fee` ADD INDEX `fk_ec_ad_fee_creator`(`create_by` ASC) USING BTREE, ADD INDEX `fk_ec_ad_fee_updater`(`update_by` ASC) USING BTREE, ADD CONSTRAINT `fk_ec_ad_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `fk_ec_ad_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, ADD CONSTRAINT `fk_ec_ad_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `fk_ec_ad_fee_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, ADD CONSTRAINT `fk_ec_ad_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE; ALTER TABLE `ec_ad_fee` COMMENT = '电商-广告推广费记录表'; -- 4) 删除推广费类型表 DROP TABLE IF EXISTS `ec_promotion_fee_type`; -- 5) 下线「推广费用类型」菜单(若存在) UPDATE `sys_menu` SET `status` = 0, `update_time` = CURRENT_TIMESTAMP WHERE `name` IN ('推广费用类型', 'PromotionFeeType') OR `path` IN ('/promotion-fee-type', 'promotion-fee-type') OR `component` LIKE '%promotion-fee-type%';