Преглед изворни кода

feat(backend): 迁移246创建product_bundle_items表(套餐商品组成明细)

Xiaogang Liao пре 1 месец
родитељ
комит
66d377b7a4

+ 17 - 0
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -9156,6 +9156,23 @@ private void runMigration100() {
 			log.warn("初始化notification_templates种子数据失败: " + e.getMessage());
 			log.warn("初始化notification_templates种子数据失败: " + e.getMessage());
 		}
 		}
 
 
+		// 迁移246: 创建 product_bundle_items 表(套餐商品组成明细 BUNDLE-001)
+		try {
+			jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS product_bundle_items (" +
+					"id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
+					"bundle_product_id BIGINT NOT NULL COMMENT '套餐商品ID', " +
+					"child_product_id BIGINT NOT NULL COMMENT '子商品ID', " +
+					"child_sku_id BIGINT DEFAULT NULL COMMENT '子SKU ID(为空时直接扣 product.stock)', " +
+					"quantity INT NOT NULL DEFAULT 1 COMMENT '子商品数量', " +
+					"created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
+					"INDEX idx_bundle (bundle_product_id), " +
+					"INDEX idx_child (child_product_id)" +
+					") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='套餐商品组成明细'");
+			log.info("已创建product_bundle_items表");
+		} catch (Exception e) {
+			// 表已存在,忽略错误
+		}
+
 	}
 	}
 
 
 	/**
 	/**

+ 12 - 0
cfc-backend/src/main/resources/schema.sql

@@ -4929,3 +4929,15 @@ CREATE TABLE IF NOT EXISTS system_prompts (
     updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     UNIQUE KEY uk_prompt_key (prompt_key)
     UNIQUE KEY uk_prompt_key (prompt_key)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统提示词管理';
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统提示词管理';
+
+-- 套餐商品组成明细表(套餐 = 商品 productType=bundle,子商品在 product_bundle_items 中配置)
+CREATE TABLE IF NOT EXISTS product_bundle_items (
+    id BIGINT AUTO_INCREMENT PRIMARY KEY,
+    bundle_product_id BIGINT NOT NULL COMMENT '套餐商品ID',
+    child_product_id BIGINT NOT NULL COMMENT '子商品ID',
+    child_sku_id BIGINT DEFAULT NULL COMMENT '子SKU ID(为空时直接扣 product.stock)',
+    quantity INT NOT NULL DEFAULT 1 COMMENT '子商品数量',
+    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+    INDEX idx_bundle (bundle_product_id),
+    INDEX idx_child (child_product_id)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='套餐商品组成明细';