04_Go-1_04 数据库数据表设计
一. API 设计 用户:上传、观看、下载、删除资源(视频) 评论:用户对视频可以进行评论 视频:被评论的视频与用户,三者的从属关系 1. 用户 创建/注册用户: URL: /user Method: POST SC: 201:ok 400: 500: 用户登录: URL: /user:/username Method: POST SC: 200:ok 400: 500: 获取用户基本信息: URL: /usr/username Method: GET SC: 200: 400: 401: 403: 500: 用户注销: URL: /user/username Method: DELETE SC: 204: 400: 401: 403: 500: 2. 资源 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 | | +------------+-------------+------+-----+---------+-------+