db.sql 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. use `lx-im`;
  2. create table `im_user`(
  3. `id` bigint not null auto_increment primary key comment 'id',
  4. `user_name` varchar(255) not null comment '用户名',
  5. `nick_name` varchar(255) not null comment '用户昵称',
  6. `head_image` varchar(255) default '' comment '用户头像',
  7. `head_image_thumb` varchar(255) default '' comment '用户头像缩略图',
  8. `password` varchar(255) not null comment '密码(明文)',
  9. `sex` tinyint(1) default 0 comment '性别 0:男 1::女',
  10. `signature` varchar(1024) not null comment '个性签名',
  11. `last_login_time` datetime DEFAULT null comment '最后登录时间',
  12. `created_time` datetime DEFAULT CURRENT_TIMESTAMP comment '创建时间',
  13. unique key `idx_user_name`(user_name),
  14. key `idx_nick_name`(nick_name)
  15. ) ENGINE=InnoDB CHARSET=utf8mb3 comment '用户';
  16. create table `im_friends`(
  17. `id` bigint not null auto_increment primary key comment 'id',
  18. `user_id` bigint not null comment '用户id',
  19. `friend_id` bigint not null comment '好友id',
  20. `friend_nick_name` varchar(255) not null comment '用户昵称',
  21. `friend_head_image` varchar(255) default '' comment '用户头像',
  22. `created_time` datetime DEFAULT CURRENT_TIMESTAMP comment '创建时间',
  23. key `idx_user_id` (`user_id`),
  24. key `idx_friend_id` (`friend_id`)
  25. ) ENGINE=InnoDB CHARSET=utf8mb3 comment '好友';
  26. create table `im_single_message`(
  27. `id` bigint not null auto_increment primary key comment 'id',
  28. `send_user_id` bigint not null comment '发送用户id',
  29. `recv_user_id` bigint not null comment '接收用户id',
  30. `content` text comment '发送内容',
  31. `type` tinyint(1) NOT NULL comment '消息类型 0:文字 1:图片 2:文件',
  32. `status` tinyint(1) NOT NULL comment '状态 0:未读 1:已读 ',
  33. `send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间',
  34. key `idx_send_recv_user_id` (`send_user_id`,`recv_user_id`)
  35. )ENGINE=InnoDB CHARSET=utf8mb3 comment '私聊消息';
  36. create table `im_group`(
  37. `id` bigint not null auto_increment primary key comment 'id',
  38. `name` varchar(255) not null comment '群名字',
  39. `owner_id` bigint not null comment '群主id',
  40. `head_image` varchar(255) default '' comment '群头像',
  41. `head_image_thumb` varchar(255) default '' comment '群头像缩略图',
  42. `notice` varchar(1024) default '' comment '群公告',
  43. `remark` varchar(255) default '' comment '群备注',
  44. `created_time` datetime DEFAULT CURRENT_TIMESTAMP comment '创建时间'
  45. )ENGINE=InnoDB CHARSET=utf8mb3 comment '群';
  46. create table `im_group_member`(
  47. `id` bigint not null auto_increment primary key comment 'id',
  48. `group_id` bigint not null comment '群id',
  49. `user_id` bigint not null comment '用户id',
  50. `alias_name` varchar(255) DEFAULT '' comment '组内显示名称',
  51. `head_image` varchar(255) default '' comment '用户头像',
  52. `remark` varchar(255) DEFAULT '' comment '备注',
  53. `created_time` datetime DEFAULT CURRENT_TIMESTAMP comment '创建时间',
  54. key `idx_group_id`(`group_id`),
  55. key `idx_user_id`(`user_id`)
  56. )ENGINE=InnoDB CHARSET=utf8mb3 comment '群成员';
  57. create table `im_group_message`(
  58. `id` bigint not null auto_increment primary key comment 'id',
  59. `group_id` bigint not null comment '群id',
  60. `send_user_id` bigint not null comment '发送用户id',
  61. `content` text comment '发送内容',
  62. `type` tinyint(1) NOT NULL comment '消息类型 0:文字 1:图片 2:文件',
  63. `send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间',
  64. key `idx_group_id` (group_id)
  65. )ENGINE=InnoDB CHARSET=utf8mb3 comment '群消息';
  66. create table `im_group_message_read_pos`(
  67. `id` bigint not null auto_increment primary key comment 'id',
  68. `group_id` bigint not null comment '群id',
  69. `user_id` bigint not null comment '用户id',
  70. `read_pos` bigint default 0 comment '已读取消息的最大消息id',
  71. `last_read_time` datetime DEFAULT CURRENT_TIMESTAMP comment '最后读取时间',
  72. key `idx_user_id`(`user_id`)
  73. )ENGINE=InnoDB CHARSET=utf8mb3 comment '群消息读取位置';