-- ******************************************************************
-- 表 kku_team_user_relation_cache 的创建SQL
-- 对应的Model: App\Module\Team\Models\TeamUserRelationCache
-- 警告: 此文件由系统自动生成，禁止修改！
-- ******************************************************************

CREATE TABLE `kku_team_user_relation_cache` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `user_id` bigint NOT NULL COMMENT '用户ID',
  `related_user_id` bigint NOT NULL COMMENT '关联用户ID（上级）',
  `level` tinyint unsigned NOT NULL COMMENT '关系层级:1直接,2间接',
  `path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '关系路径,格式:1,2,3',
  `depth` tinyint unsigned NOT NULL COMMENT '层级深度,从1开始',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `idx_user_relation` (`user_id`,`related_user_id`) USING BTREE,
  KEY `idx_user_id` (`user_id`) USING BTREE,
  KEY `idx_related_user_id` (`related_user_id`) USING BTREE,
  KEY `idx_level` (`level`) USING BTREE,
  KEY `idx_depth` (`depth`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户关系缓存表';
