|
@@ -1556,6 +1556,36 @@ log.info("已添加template_id列到tasks表");
|
|
|
log.warn("重建 family_member_attributes 表失败: {}", e.getMessage());
|
|
log.warn("重建 family_member_attributes 表失败: {}", e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 迁移: children 表添加 show_to_family 列(v1.3 家庭成员卡)
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer colExists = jdbcTemplate.queryForObject(
|
|
|
|
|
+ "SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'children' AND COLUMN_NAME = 'show_to_family'",
|
|
|
|
|
+ Integer.class);
|
|
|
|
|
+ if (colExists == null || colExists == 0) {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE children ADD COLUMN show_to_family TINYINT DEFAULT 1 COMMENT '是否对家庭成员可见: 1=是, 0=否'");
|
|
|
|
|
+ log.info("已为 children 表添加 show_to_family 列");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("children 表 show_to_family 列已存在,跳过");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("检查/添加 children 表 show_to_family 列失败: {}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移: users 表添加 show_to_family 列(v1.3 家庭成员卡)
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer colExists = jdbcTemplate.queryForObject(
|
|
|
|
|
+ "SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'users' AND COLUMN_NAME = 'show_to_family'",
|
|
|
|
|
+ Integer.class);
|
|
|
|
|
+ if (colExists == null || colExists == 0) {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE users ADD COLUMN show_to_family TINYINT DEFAULT 1 COMMENT '是否对家庭成员可见: 1=是, 0=否'");
|
|
|
|
|
+ log.info("已为 users 表添加 show_to_family 列");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("users 表 show_to_family 列已存在,跳过");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("检查/添加 users 表 show_to_family 列失败: {}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// ==================== DanShop 电商模块建表 ====================
|
|
// ==================== DanShop 电商模块建表 ====================
|
|
|
// 1. danshop_categories (商品分类表)
|
|
// 1. danshop_categories (商品分类表)
|
|
|
try {
|
|
try {
|
|
@@ -2388,7 +2418,7 @@ try {
|
|
|
try {
|
|
try {
|
|
|
jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS health_reports (" +
|
|
jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS health_reports (" +
|
|
|
"id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
"id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
- "child_id BIGINT NOT NULL COMMENT '孩子ID', " +
|
|
|
|
|
|
|
+ "user_id BIGINT NOT NULL COMMENT '用户ID', " +
|
|
|
"family_id BIGINT COMMENT '家庭ID', " +
|
|
"family_id BIGINT COMMENT '家庭ID', " +
|
|
|
"report_type VARCHAR(32) NOT NULL COMMENT '报告类型: physical_exam(体检)/gut_flora(菌群检测)', " +
|
|
"report_type VARCHAR(32) NOT NULL COMMENT '报告类型: physical_exam(体检)/gut_flora(菌群检测)', " +
|
|
|
"report_date DATE COMMENT '报告日期', " +
|
|
"report_date DATE COMMENT '报告日期', " +
|
|
@@ -2403,7 +2433,7 @@ try {
|
|
|
"remark VARCHAR(500) COMMENT '备注', " +
|
|
"remark VARCHAR(500) COMMENT '备注', " +
|
|
|
"created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
"created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
"updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
"updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
- "INDEX idx_child_id (child_id), " +
|
|
|
|
|
|
|
+ "INDEX idx_user_id (user_id), " +
|
|
|
"INDEX idx_family_id (family_id), " +
|
|
"INDEX idx_family_id (family_id), " +
|
|
|
"INDEX idx_report_type (report_type)" +
|
|
"INDEX idx_report_type (report_type)" +
|
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='健康检测报告表'");
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='健康检测报告表'");
|
|
@@ -2455,6 +2485,33 @@ try {
|
|
|
log.warn("创建health_checkins表可能已存在: {}", e.getMessage());
|
|
log.warn("创建health_checkins表可能已存在: {}", e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 迁移31: 创建联系人表
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS contacts (" +
|
|
|
|
|
+ "id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
|
|
+ "user_id BIGINT NOT NULL COMMENT '用户ID', " +
|
|
|
|
|
+ "name VARCHAR(100) NOT NULL COMMENT '姓名', " +
|
|
|
|
|
+ "phone VARCHAR(20) COMMENT '电话', " +
|
|
|
|
|
+ "avatar VARCHAR(500) COMMENT '头像', " +
|
|
|
|
|
+ "relationship_type VARCHAR(20) COMMENT '关系类型: family/friend/partner/colleague/other', " +
|
|
|
|
|
+ "known_since DATETIME COMMENT '认识时间', " +
|
|
|
|
|
+ "bio VARCHAR(500) COMMENT '简介', " +
|
|
|
|
|
+ "birthday DATE COMMENT '生日', " +
|
|
|
|
|
+ "intimacy_level INT DEFAULT 0 COMMENT '亲密度(0-100)', " +
|
|
|
|
|
+ "contact_source VARCHAR(20) DEFAULT 'manual' COMMENT '来源: phone/manual', " +
|
|
|
|
|
+ "tags VARCHAR(500) COMMENT '标签(逗号分隔)', " +
|
|
|
|
|
+ "last_contact_at DATETIME COMMENT '最近联系时间', " +
|
|
|
|
|
+ "contact_count INT DEFAULT 0 COMMENT '联系次数', " +
|
|
|
|
|
+ "notes TEXT COMMENT '备注', " +
|
|
|
|
|
+ "created_at DATETIME, " +
|
|
|
|
|
+ "updated_at DATETIME, " +
|
|
|
|
|
+ "INDEX idx_user_id (user_id)" +
|
|
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='联系人表'");
|
|
|
|
|
+ log.info("已创建contacts联系表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("创建contacts表可能已存在: {}", e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 迁移30: activities表添加visibility和visible_to字段
|
|
// 迁移30: activities表添加visibility和visible_to字段
|
|
|
try {
|
|
try {
|
|
|
jdbcTemplate.execute("ALTER TABLE activities ADD COLUMN visibility VARCHAR(20) DEFAULT 'all' COMMENT '可见性: all/member'");
|
|
jdbcTemplate.execute("ALTER TABLE activities ADD COLUMN visibility VARCHAR(20) DEFAULT 'all' COMMENT '可见性: all/member'");
|