Просмотр исходного кода

fix: year_month reserved word quoting + products.min_quantity migration

- Backtick-escape year_month in butler_service_records & butler_commission_settlements CREATE TABLE (MySQL 8.0 reserved word)
- Add migration 105: ensure products.min_quantity column exists
Xiaogang Liao 3 месяцев назад
Родитель
Сommit
838ea756df

+ 8 - 5
cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java

@@ -5894,12 +5894,12 @@ try {
                     "platform_fee_p BIGINT DEFAULT 0, " +
                     "butler_amount_p BIGINT DEFAULT 0, " +
                     "member_tier VARCHAR(10), " +
-                    "year_month VARCHAR(7), " +
+                    "`year_month` VARCHAR(7), " +
                     "remark VARCHAR(500), " +
                     "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
                     "INDEX idx_butler_id (butler_id), " +
                     "INDEX idx_member_user_id (member_user_id), " +
-                    "INDEX idx_year_month (year_month)" +
+                    "INDEX idx_year_month (`year_month`)" +
                     ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家服务记录'");
             log.info("已创建butler_service_records表");
         } catch (Exception e) {
@@ -5910,7 +5910,7 @@ try {
             jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS butler_commission_settlements (" +
                     "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
                     "butler_id BIGINT NOT NULL, " +
-                    "year_month VARCHAR(7) NOT NULL, " +
+                    "`year_month` VARCHAR(7) NOT NULL, " +
                     "member_count INT DEFAULT 0, " +
                     "annual_base_amount_p BIGINT DEFAULT 0, " +
                     "annual_butler_amount_p BIGINT DEFAULT 0, " +
@@ -5923,9 +5923,9 @@ try {
                     "settled_at DATETIME, " +
                     "settled_by BIGINT, " +
                     "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
-                    "UNIQUE KEY uk_butler_month (butler_id, year_month), " +
+                    "UNIQUE KEY uk_butler_month (butler_id, `year_month`), " +
                     "INDEX idx_status (status), " +
-                    "INDEX idx_year_month (year_month)" +
+                    "INDEX idx_year_month (`year_month`)" +
                     ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家月度佣金结算单'");
             log.info("已创建butler_commission_settlements表");
         } catch (Exception e) {
@@ -6597,5 +6597,8 @@ private void runMigration100() {
 		ensureColumn("promotion_tier", "team_size_1st", "INT DEFAULT 0 COMMENT '一层团队人数'");
 		ensureColumn("promotion_tier", "team_size_2nd", "INT DEFAULT 0 COMMENT '二层团队人数'");
 		ensureColumn("promotion_tier", "team_size_3rd", "INT DEFAULT 0 COMMENT '三层团队人数'");
+
+		// 迁移105: products表添加min_quantity列(商品最小购买数量限制)
+		ensureColumn("products", "min_quantity", "INT DEFAULT 1 COMMENT '最小购买数量限制'");
 	}
 }

+ 5 - 5
cfc-backend/src/main/resources/schema.sql

@@ -2375,19 +2375,19 @@ CREATE TABLE IF NOT EXISTS butler_service_records (
     platform_fee_p BIGINT DEFAULT 0,
     butler_amount_p BIGINT DEFAULT 0,
     member_tier VARCHAR(10),
-    year_month VARCHAR(7),
+    `year_month` VARCHAR(7),
     remark VARCHAR(500),
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
     INDEX idx_butler_id (butler_id),
     INDEX idx_member_user_id (member_user_id),
-    INDEX idx_year_month (year_month)
+    INDEX idx_year_month (`year_month`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家服务记录';
 
 -- 管家月度佣金结算单
 CREATE TABLE IF NOT EXISTS butler_commission_settlements (
     id BIGINT AUTO_INCREMENT PRIMARY KEY,
     butler_id BIGINT NOT NULL,
-    year_month VARCHAR(7) NOT NULL,
+    `year_month` VARCHAR(7) NOT NULL,
     member_count INT DEFAULT 0,
     annual_base_amount_p BIGINT DEFAULT 0,
     annual_butler_amount_p BIGINT DEFAULT 0,
@@ -2400,9 +2400,9 @@ CREATE TABLE IF NOT EXISTS butler_commission_settlements (
     settled_at DATETIME,
     settled_by BIGINT,
     created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
-    UNIQUE KEY uk_butler_month (butler_id, year_month),
+    UNIQUE KEY uk_butler_month (butler_id, `year_month`),
     INDEX idx_status (status),
-    INDEX idx_year_month (year_month)
+    INDEX idx_year_month (`year_month`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管家月度佣金结算单';
 
 -- 会员-管家分配记录