refactor: 去掉订单明细/SKU成本/影响面冗余 product_id,归属经 sku 关联

This commit is contained in:
2026-08-31 14:29:46 +08:00
parent c5de3499c0
commit 32c4788176
21 changed files with 142 additions and 72 deletions
@@ -7,8 +7,7 @@
CREATE TABLE IF NOT EXISTS `ec_product_sku_cost_impact` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
`product_id` bigint UNSIGNED NOT NULL COMMENT '商品ID',
`sku_id` bigint UNSIGNED NOT NULL COMMENT 'SKU ID',
`sku_id` bigint UNSIGNED NOT NULL COMMENT 'SKU ID(商品归属经 ec_product_sku.product_id)',
`date_from` date NOT NULL COMMENT '影响订单日起(含,order_time)',
`date_to` date NOT NULL COMMENT '影响订单日止(含,默认调价时的今天)',
`status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING/APPLIED/DISCARDED',
@@ -0,0 +1,32 @@
-- 去掉冗余 product_id:归属一律经 sku → ec_product_sku.product_id
-- 权威设计稿:
-- · sql/design/ec/ec_order_design.sql(ec_order_item)
-- · sql/design/ec/ec_product_design.sql(ec_product_sku_cost)
-- · sql/design/ec/ec_order_cost_sync_design.sql(ec_product_sku_cost_impact)
-- 说明:若 V20260833 已按旧稿建出 impact.product_id,本脚本会条件删除;全新装机无该列则跳过。
-- ========== ec_order_item ==========
ALTER TABLE `ec_order_item` DROP FOREIGN KEY `fk_ec_order_item_product`;
ALTER TABLE `ec_order_item` DROP INDEX `idx_ec_order_item_product`;
ALTER TABLE `ec_order_item` DROP COLUMN `product_id`;
-- ========== ec_product_sku_cost ==========
ALTER TABLE `ec_product_sku_cost` DROP FOREIGN KEY `fk_ec_product_sku_cost_product`;
ALTER TABLE `ec_product_sku_cost` DROP INDEX `idx_ec_product_sku_cost_product`;
ALTER TABLE `ec_product_sku_cost` DROP COLUMN `product_id`;
-- ========== ec_product_sku_cost_impact(条件删列) ==========
SET @impact_has_product_id := (
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'ec_product_sku_cost_impact'
AND COLUMN_NAME = 'product_id'
);
SET @impact_drop_sql := IF(
@impact_has_product_id > 0,
'ALTER TABLE `ec_product_sku_cost_impact` DROP COLUMN `product_id`',
'SELECT 1'
);
PREPARE impact_drop_stmt FROM @impact_drop_sql;
EXECUTE impact_drop_stmt;
DEALLOCATE PREPARE impact_drop_stmt;