|
@@ -2939,7 +2939,9 @@ log.info("已添加template_id列到tasks表");
|
|
|
|
|
|
|
|
private void migrateHealthDimensionsTable() {
|
|
private void migrateHealthDimensionsTable() {
|
|
|
try {
|
|
try {
|
|
|
- jdbcTemplate.execute("RENAME TABLE IF EXISTS `health_dimension_score` TO `health_dimension_score_old`");
|
|
|
|
|
|
|
+ if (tableExists("health_dimension_score")) {
|
|
|
|
|
+ jdbcTemplate.execute("RENAME TABLE `health_dimension_score` TO `health_dimension_score_old`");
|
|
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("health_dimension_score rename skipped: {}", e.getMessage());
|
|
log.warn("health_dimension_score rename skipped: {}", e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -2965,7 +2967,9 @@ log.info("已添加template_id列到tasks表");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- jdbcTemplate.execute("RENAME TABLE IF EXISTS `health_data_source_record` TO `health_data_source_record_old`");
|
|
|
|
|
|
|
+ if (tableExists("health_data_source_record")) {
|
|
|
|
|
+ jdbcTemplate.execute("RENAME TABLE `health_data_source_record` TO `health_data_source_record_old`");
|
|
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("health_data_source_record rename skipped: {}", e.getMessage());
|
|
log.warn("health_data_source_record rename skipped: {}", e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -2987,7 +2991,9 @@ log.info("已添加template_id列到tasks表");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- jdbcTemplate.execute("RENAME TABLE IF EXISTS `health_norm_reference` TO `health_norm_reference_old`");
|
|
|
|
|
|
|
+ if (tableExists("health_norm_reference")) {
|
|
|
|
|
+ jdbcTemplate.execute("RENAME TABLE `health_norm_reference` TO `health_norm_reference_old`");
|
|
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("health_norm_reference rename skipped: {}", e.getMessage());
|
|
log.warn("health_norm_reference rename skipped: {}", e.getMessage());
|
|
|
}
|
|
}
|
|
@@ -4693,6 +4699,28 @@ try {
|
|
|
log.info("食品相关表初始化完成");
|
|
log.info("食品相关表初始化完成");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean tableExists(String tableName) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer count = jdbcTemplate.queryForObject(
|
|
|
|
|
+ "SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?",
|
|
|
|
|
+ Integer.class, tableName);
|
|
|
|
|
+ return count != null && count > 0;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean columnExists(String table, String column) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer count = jdbcTemplate.queryForObject(
|
|
|
|
|
+ "SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?",
|
|
|
|
|
+ Integer.class, table, column);
|
|
|
|
|
+ return count != null && count > 0;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void ensureColumn(String table, String column, String definition) {
|
|
private void ensureColumn(String table, String column, String definition) {
|
|
|
try {
|
|
try {
|
|
|
jdbcTemplate.execute("ALTER TABLE " + table + " ADD COLUMN " + column + " " + definition);
|
|
jdbcTemplate.execute("ALTER TABLE " + table + " ADD COLUMN " + column + " " + definition);
|
|
@@ -6042,11 +6070,13 @@ try {
|
|
|
ensureColumn("points_exchange_records", "family_member_id", "BIGINT COMMENT '家庭成员ID'");
|
|
ensureColumn("points_exchange_records", "family_member_id", "BIGINT COMMENT '家庭成员ID'");
|
|
|
|
|
|
|
|
// 迁移133: products表列对齐 — rename min_quantity→purchase_count_threshold, add missing columns
|
|
// 迁移133: products表列对齐 — rename min_quantity→purchase_count_threshold, add missing columns
|
|
|
- try {
|
|
|
|
|
- jdbcTemplate.execute("ALTER TABLE products CHANGE COLUMN min_quantity purchase_count_threshold INT DEFAULT 0 COMMENT '最小购买数量限制'");
|
|
|
|
|
- log.info("已重命名products.min_quantity→purchase_count_threshold");
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.warn("重命名products列可能已处理: {}", e.getMessage());
|
|
|
|
|
|
|
+ if (columnExists("products", "min_quantity")) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE products CHANGE COLUMN min_quantity purchase_count_threshold INT DEFAULT 0 COMMENT '最小购买数量限制'");
|
|
|
|
|
+ log.info("已重命名products.min_quantity→purchase_count_threshold");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("重命名products列失败(可能已处理): {}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
ensureColumn("products", "recommendation_tags", "VARCHAR(500) DEFAULT NULL COMMENT '推荐标签'");
|
|
ensureColumn("products", "recommendation_tags", "VARCHAR(500) DEFAULT NULL COMMENT '推荐标签'");
|
|
|
ensureColumn("products", "repurchase_interval_days", "INT DEFAULT 30 COMMENT '复购间隔天数'");
|
|
ensureColumn("products", "repurchase_interval_days", "INT DEFAULT 30 COMMENT '复购间隔天数'");
|