Repository navigation
Expand file tree
/
Copy pathblog.sql
More file actions
76 lines (67 loc) · 2.58 KB
/
Copy pathblog.sql
File metadata and controls
76 lines (67 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `post_content`;
DROP TABLE IF EXISTS `post`;
DROP TABLE IF EXISTS `tag`;
DROP TABLE IF EXISTS `page`;
DROP TABLE IF EXISTS `category`;
DROP TABLE IF EXISTS `user`;
CREATE TABLE `category` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_category_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `page` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`ident` varchar(20) NOT NULL,
`title` varchar(100) NOT NULL,
`content` longtext,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_page_ident` (`ident`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `post` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT 0,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`category_id` int unsigned NOT NULL,
`is_top` tinyint(1) NOT NULL DEFAULT 0,
`tag_ids` json NOT NULL,
`views` int unsigned NOT NULL DEFAULT 0,
`description` varchar(2000) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `idx_post_list` (`status`, `is_top`, `updated_at`),
KEY `idx_post_category` (`status`, `category_id`, `is_top`, `updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `post_content` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`content` longtext,
`post_id` int unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_post_content_post_id` (`post_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `tag` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`count` int unsigned NOT NULL DEFAULT 0,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_tag_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `user` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(50) NOT NULL,
`password` varchar(128) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `category` (`name`) VALUES ('技术'), ('产品');
INSERT INTO `page` (`ident`, `title`, `content`) VALUES
('about', '关于', '## 关于'),
('read', '阅读', '## 阅读清单');
SET FOREIGN_KEY_CHECKS = 1;