golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

145 rivejä
7.4 KiB

  1. -- ----------------------------
  2. -- Table structure for device
  3. -- ----------------------------
  4. DROP TABLE IF EXISTS `device`;
  5. CREATE TABLE `device`
  6. (
  7. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  8. `user_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '账户id',
  9. `type` tinyint(3) NOT NULL COMMENT '设备类型,1:Android;2:IOS;3:Windows; 4:MacOS;5:Web',
  10. `brand` varchar(20) NOT NULL COMMENT '手机厂商',
  11. `model` varchar(20) NOT NULL COMMENT '机型',
  12. `system_version` varchar(10) NOT NULL COMMENT '系统版本',
  13. `sdk_version` varchar(10) NOT NULL COMMENT 'app版本',
  14. `status` tinyint(3) NOT NULL DEFAULT '0' COMMENT '在线状态,0:离线;1:在线',
  15. `conn_addr` varchar(25) NOT NULL COMMENT '连接层服务器地址',
  16. `client_addr` varchar(25) NOT NULL COMMENT '客户端地址',
  17. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  18. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  19. PRIMARY KEY (`id`),
  20. KEY `idx_user_id` (`user_id`) USING BTREE
  21. ) ENGINE = InnoDB
  22. DEFAULT CHARSET = utf8mb4
  23. COLLATE = utf8mb4_bin COMMENT ='设备';
  24. -- ----------------------------
  25. -- Table structure for friend
  26. -- ----------------------------
  27. DROP TABLE IF EXISTS `friend`;
  28. CREATE TABLE `friend`
  29. (
  30. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  31. `user_id` bigint(20) unsigned NOT NULL COMMENT '用户id',
  32. `friend_id` bigint(20) unsigned NOT NULL COMMENT '好友id',
  33. `remarks` varchar(20) NOT NULL COMMENT '备注',
  34. `extra` varchar(1024) NOT NULL COMMENT '附加属性',
  35. `status` tinyint(4) NOT NULL COMMENT '状态,0:申请,1:同意',
  36. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  37. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  38. PRIMARY KEY (`id`),
  39. UNIQUE KEY `uk_user_id_friend_id` (`user_id`, `friend_id`)
  40. ) ENGINE = InnoDB
  41. DEFAULT CHARSET = utf8mb4
  42. COLLATE = utf8mb4_bin COMMENT ='好友';
  43. -- ----------------------------
  44. -- Table structure for group
  45. -- ----------------------------
  46. DROP TABLE IF EXISTS `group`;
  47. CREATE TABLE `group`
  48. (
  49. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  50. `name` varchar(50) NOT NULL COMMENT '群组名称',
  51. `avatar_url` varchar(255) NOT NULL COMMENT '群组头像',
  52. `introduction` varchar(255) NOT NULL COMMENT '群组简介',
  53. `user_num` int(11) NOT NULL DEFAULT '0' COMMENT '群组人数',
  54. `extra` varchar(1024) NOT NULL COMMENT '附加属性',
  55. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  56. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  57. PRIMARY KEY (`id`)
  58. ) ENGINE = InnoDB
  59. DEFAULT CHARSET = utf8mb4
  60. COLLATE = utf8mb4_bin COMMENT ='群组';
  61. -- ----------------------------
  62. -- Table structure for group_user
  63. -- ----------------------------
  64. DROP TABLE IF EXISTS `group_user`;
  65. CREATE TABLE `group_user`
  66. (
  67. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  68. `group_id` bigint(20) unsigned NOT NULL COMMENT '组id',
  69. `user_id` bigint(20) unsigned NOT NULL COMMENT '用户id',
  70. `member_type` tinyint(4) NOT NULL COMMENT '成员类型,1:管理员;2:普通成员',
  71. `remarks` varchar(20) NOT NULL COMMENT '备注',
  72. `extra` varchar(1024) NOT NULL COMMENT '附加属性',
  73. `status` tinyint(255) NOT NULL COMMENT '状态',
  74. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  75. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  76. PRIMARY KEY (`id`),
  77. UNIQUE KEY `uk_group_id_user_id` (`group_id`, `user_id`) USING BTREE,
  78. KEY `idx_user_id` (`user_id`) USING BTREE
  79. ) ENGINE = InnoDB
  80. DEFAULT CHARSET = utf8mb4
  81. COLLATE = utf8mb4_bin COMMENT ='群组成员';
  82. -- ----------------------------
  83. -- Table structure for user
  84. -- ----------------------------
  85. DROP TABLE IF EXISTS `user`;
  86. CREATE TABLE `user`
  87. (
  88. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  89. `phone_number` varchar(20) NOT NULL COMMENT '手机号',
  90. `nickname` varchar(20) NOT NULL COMMENT '昵称',
  91. `sex` tinyint(4) NOT NULL COMMENT '性别,0:未知;1:男;2:女',
  92. `avatar_url` varchar(256) NOT NULL COMMENT '用户头像链接',
  93. `extra` varchar(1024) NOT NULL COMMENT '附加属性',
  94. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  95. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  96. PRIMARY KEY (`id`),
  97. UNIQUE KEY `uk_phone_number` (`phone_number`)
  98. ) ENGINE = InnoDB
  99. DEFAULT CHARSET = utf8mb4
  100. COLLATE = utf8mb4_bin COMMENT ='用户';
  101. CREATE TABLE `seq`
  102. (
  103. `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  104. `object_type` tinyint NOT NULL COMMENT '对象类型,1:用户;2:群组',
  105. `object_id` bigint unsigned NOT NULL COMMENT '对象id',
  106. `seq` bigint unsigned NOT NULL COMMENT '序列号',
  107. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  108. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  109. PRIMARY KEY (`id`),
  110. UNIQUE KEY `uk_object` (`object_type`,`object_id`)
  111. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='序列号';
  112. -- ----------------------------
  113. -- Table structure for message
  114. -- ----------------------------
  115. DROP TABLE IF EXISTS `message_000`;
  116. CREATE TABLE `message_000`
  117. (
  118. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  119. `user_id` bigint(20) unsigned NOT NULL COMMENT '所属类型的id',
  120. `request_id` bigint(20) NOT NULL COMMENT '请求id',
  121. `sender_type` tinyint(3) NOT NULL COMMENT '发送者类型',
  122. `sender_id` bigint(20) unsigned NOT NULL COMMENT '发送者id',
  123. `receiver_type` tinyint(3) NOT NULL COMMENT '接收者类型,1:个人;2:群组',
  124. `receiver_id` bigint(20) unsigned NOT NULL COMMENT '接收者id,如果是单聊信息,则为user_id,如果是群组消息,则为group_id',
  125. `to_user_ids` varchar(255) NOT NULL COMMENT '需要@的用户id列表,多个用户用,隔开',
  126. `type` tinyint(4) NOT NULL COMMENT '消息类型',
  127. `content` blob NOT NULL COMMENT '消息内容',
  128. `seq` bigint(20) unsigned NOT NULL COMMENT '消息序列号',
  129. `send_time` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP (3) COMMENT '消息发送时间',
  130. `status` tinyint(255) NOT NULL DEFAULT '0' COMMENT '消息状态,0:未处理1:消息撤回',
  131. `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  132. `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  133. PRIMARY KEY (`id`),
  134. UNIQUE KEY `uk_user_id_seq` (`user_id`, `seq`) USING BTREE
  135. ) ENGINE = InnoDB
  136. DEFAULT CHARSET = utf8mb4
  137. COLLATE = utf8mb4_bin COMMENT ='消息';