青春纸盒子

文: 芦苇

你喜欢我笑的样子

我靠上了落寞的窗子

晚风吹起了我的袖子

明月沾湿了你的眸子


转身,你走出了两个人的圈子

树影婆娑,整座院子


挽起袖子

回头,把揽你忧伤一地的影子

装进,青春,这纸盒子


更多代码请关注我的微信小程序: "ecoder"

luwei0915

导航

04_Go-1_04 数据库数据表设计

一. API 设计
用户:上传、观看、下载、删除资源(视频)
评论:用户对视频可以进行评论
视频:被评论的视频与用户,三者的从属关系


1. 用户
创建/注册用户:
    URL: /user
    Method: POST
    SC:
        201:ok
        400500:

用户登录:
    URL: /user:/username
    Method: POST
    SC:
        200:ok
        400500:

获取用户基本信息:
    URL: /usr/username
    Method: GET 
    SC:
        200400401403500:

用户注销:
    URL: /user/username
    Method: DELETE
    SC:
        2044004014035002. 资源
List All videos
    URL: /user/:username/videos
    Method: GET
    SC:
        200
        400
        500

Get One Video
    URL: /user/:username/videos/:vid-id
    Method: GET
    SC: 
        200
        400
        500

Delete One Video
    URL: /user/:username/videos/:vid-id
    Method: DELETE
    SC:
        204
        400
        401
        403
        500


3. 评论
Show Comments
URL: /videos/:vid-id/comments
    Method: GET
    SC:
        200
        400
        500

Post A Comment
URL: /videos/:vid-id/comments
    Method: POST
    SC:
        201
        400
        500

Delete A Comment
URL: /videos/:vid-id/comment/:comment-id
    Method: DELETE
    SC:
        204
        400
        401
        403
        500


4. 数据表设计
4.1 users 表
CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `login_name` varchar(64) DEFAULT NULL,
  `pwd` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `login_name` (`login_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

> desc users;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| login_name | varchar(64)      | YES  | UNI | NULL    |                |
| pwd        | text             | YES  |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+

4.2 video_info 表
CREATE TABLE `video_info` (
  `id` varchar(64) NOT NULL,
  `author_id` int(10) unsigned DEFAULT NULL,
  `name` text DEFAULT NULL,
  `display_ctime` text DEFAULT NULL,
  `create_time` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

> desc video_info;
+---------------+------------------+------+-----+---------------------+-------+
| Field         | Type             | Null | Key | Default             | Extra |
+---------------+------------------+------+-----+---------------------+-------+
| id            | varchar(64)      | NO   | PRI | NULL                |       |
| author_id     | int(10) unsigned | YES  |     | NULL                |       |
| name          | text             | YES  |     | NULL                |       |
| display_ctime | text             | YES  |     | NULL                |       |
| create_time   | datetime         | YES  |     | current_timestamp() |       |
+---------------+------------------+------+-----+---------------------+-------+

4.3 comments 表
CREATE TABLE `comments` (
  `id` varchar(64) NOT NULL,
  `video_id` varchar(64) DEFAULT NULL,
  `author_id` int(10) unsigned DEFAULT NULL,
  `content` text DEFAULT NULL,
  `time` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

> desc comments;
+-----------+------------------+------+-----+---------------------+-------+
| Field     | Type             | Null | Key | Default             | Extra |
+-----------+------------------+------+-----+---------------------+-------+
| id        | varchar(64)      | NO   | PRI | NULL                |       |
| video_id  | varchar(64)      | YES  |     | NULL                |       |
| author_id | int(10) unsigned | YES  |     | NULL                |       |
| content   | text             | YES  |     | NULL                |       |
| time      | datetime         | YES  |     | current_timestamp() |       |
+-----------+------------------+------+-----+---------------------+-------+

4.4 sessions 表
CREATE TABLE `sessions` (
  `session_id` char(64) NOT NULL,
  `TTL` tinytext DEFAULT NULL,
  `log_name` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
        
> desc sessions;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| session_id | char(64)    | NO   | PRI | NULL    |       |
| TTL        | tinytext    | YES  |     | NULL    |       |
| log_name   | varchar(64) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+

 

posted on 2021-12-13 19:49  芦苇の  阅读(36)  评论(0编辑  收藏  举报