CREATE TABLE `rooms`(
`room_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`room_name` VARCHAR(100) NOT NULL,
`create_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
UNIQUE INDEX (`room_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
- room_id是rooms表的主键和索引
- room_name:群组名
CREATE TABLE `users`(
`user_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`user_name` VARCHAR(100) NOT NULL,
`password` VARCHAR(100) NOT NULL,
`create_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
UNIQUE INDEX (`user_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
- user_id:user唯一ID
- user_name:username
- password:用户密码密文
CREATE TABLE `room_users`(
`room_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`join_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
UNIQUE INDEX(`room_id`,`user_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
- room_id:room唯一ID
- user_id:user唯一ID
CREATE TABLE `records`(
`record_id` int(11) NOT NULL PRIMARY KEY,
`content` VARCHAR(1000) NOT NULL,
`create_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
UNIQUE INDEX (`record_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `record_room_user`(
`record_id` int(11) NOT NULL PRIMARY KEY,
`room_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`create_time` timestamp NOT NULL default CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
UNIQUE INDEX (`record_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
- knex链接mysql异常
- 问题现象:knex 链接显示
Client does not support authentication protocol requested by server; consider upgrading MySQL client
- 版本:mysql:8.0.18
- 解决方法: 换成mysql
- 问题现象:knex 链接显示
- react ts app 和 nodejs service 分区问题
- 偷懒技巧:
mkdir client
cd client
create-react-app . --template=typescript
- 偷懒技巧:
- Could not find a declaration file for module '**'
- 举个🌰,如果提示Could not find a declaration file for module 'react',
- 那你应该执行如下命令:
yarn add @types/react
- nodemon ignore 的部分要加单引号
- history跳转时socket仍然处于连接中可能会产生多个socket
- useEffect中有用useState-setState要在return时把他删掉
- 若要数据库能保存emoji
- ALTER DATABASE chat_room CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
- ALTER TABLE rooms CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;