-
Notifications
You must be signed in to change notification settings - Fork 123
/
poplar_init.sql
205 lines (185 loc) · 6.91 KB
/
poplar_init.sql
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
create database IF NOT EXISTS poplar;
drop table if EXISTS `poplar`.`poplar_users`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_users` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_name` VARCHAR(50) NOT NULL COMMENT '昵称',
`user_avatar` VARCHAR(100) NULL,
`user_desc` TEXT NULL COMMENT '个人简介',
`user_gender` INT NULL,
`user_birthday` VARCHAR(10) NULL,
`user_location` TEXT NULL COMMENT '居住地',
`user_cover` VARCHAR(45) NULL COMMENT '封面',
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC))
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_user_auths`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_user_auths` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`identify_type` INT NOT NULL COMMENT '1 email\n2 phone\n3 weibo\n4 weixin',
`identifier` VARCHAR(50) NULL,
`credential` VARCHAR(50) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_posts`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_posts` (
`id` INT NOT NULL AUTO_INCREMENT,
`post_author` INT NOT NULL COMMENT '作者ID',
`post_ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
`post_content` LONGTEXT NOT NULL,
`post_title` TEXT NULL,
`post_excerpt` TEXT NULL COMMENT '摘要',
`post_status` INT NOT NULL DEFAULT 0,
`comment_status` INT NOT NULL DEFAULT 0,
`post_pwd` VARCHAR(60) NULL,
`post_lastts` TIMESTAMP NOT NULL DEFAULT current_timestamp on update CURRENT_TIMESTAMP,
`comment_count` INT NOT NULL DEFAULT 0,
`like_count` INT NOT NULL DEFAULT 0,
`share_count` INT NOT NULL DEFAULT 0,
`post_url` VARCHAR(45) NULL,
`post_tags` TEXT NULL,
`post_album` INT NOT NULL DEFAULT 0,
`post_cover` VARCHAR(100) NULL,
PRIMARY KEY (`id`),
INDEX `fk_poplar_users_post_author_idx` (`post_author` ASC),
CONSTRAINT `fk_poplar_users_post_author`
FOREIGN KEY (`post_author`)
REFERENCES `poplar`.`poplar_users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_events`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_events` (
`id` INT NOT NULL AUTO_INCREMENT,
`object_type` INT NOT NULL,
`object_id` INT NOT NULL,
`ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
`user_id` INT NOT NULL,
`user_name` VARCHAR(50) NULL,
`user_avatar` VARCHAR(100) NULL,
`like_count` INT NOT NULL,
`share_count` INT NOT NULL,
`comment_count` INT NOT NULL,
`title` TEXT NULL,
`summary` TEXT NULL,
`content` TEXT NULL,
`tags` TEXT NULL,
`following_user_id` INT NULL,
`following_user_name` VARCHAR(50) NULL,
`follower_user_id` INT NULL,
`follower_user_name` VARCHAR(50) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_albums`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_albums` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`create_ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
`album_title` TEXT NULL,
`album_desc` TEXT NULL COMMENT '描述',
`last_add_ts` DATETIME NOT NULL DEFAULT current_timestamp,
`photos_count` INT NOT NULL DEFAULT 0,
`status` INT NOT NULL DEFAULT 0,
`cover` VARCHAR(45) NULL,
`album_tags` TEXT null,
PRIMARY KEY (`id`),
INDEX `fk_poplar_albums_album_author_idx` (`user_id` ASC),
CONSTRAINT `fk_poplar_albums_album_author`
FOREIGN KEY (`user_id`)
REFERENCES `poplar`.`poplar_users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_photos`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_photos` (
`id` INT NOT NULL AUTO_INCREMENT,
`key` VARCHAR(45) NOT NULL,
`album_id` INT NOT NULL,
`ts` TIMESTAMP NULL DEFAULT current_timestamp,
`desc` VARCHAR(50) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_comments`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_comments` (
`id` INT NOT NULL AUTO_INCREMENT,
`comment_object_type` INT NOT NULL COMMENT 'post, album,...',
`comment_object_id` INT NOT NULL,
`comment_author` INT NOT NULL,
`comment_author_name` VARCHAR(100) NOT NULL,
`comment_ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
`comment_content` TEXT NOT NULL,
`comment_parent` INT NOT NULL DEFAULT 0,
`comment_parent_author_name` VARCHAR(100) NULL,
`comment_parent_author` INT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
INDEX `fk_poplar_comments_comment_author_idx` (`comment_author` ASC),
CONSTRAINT `fk_poplar_comments_comment_author`
FOREIGN KEY (`comment_author`)
REFERENCES `poplar`.`poplar_users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_likes`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_likes` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`object_type` INT NOT NULL,
`object_id` INT NOT NULL,
`ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
alter table `poplar`.`poplar_likes` add unique(`user_id`, `object_type`, `object_id`);
drop table if EXISTS `poplar`.`poplar_tags`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_tags` (
`id` INT NOT NULL AUTO_INCREMENT,
`tag` VARCHAR(30) NOT NULL,
`add_ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
`cover` VARCHAR(45) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_relations` ;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_relations` (
`id` INT NOT NULL AUTO_INCREMENT,
`object_type` INT NOT NULL,
`object_id` INT NOT NULL,
`tag_id` INT NOT NULL,
`add_ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (`id`),
INDEX `fk_tag_id_idx` (`tag_id` ASC),
CONSTRAINT `fk_tag_id`
FOREIGN KEY (`tag_id`)
REFERENCES `poplar`.`poplar_tags` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
drop table if EXISTS `poplar`.`poplar_interests` ;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_interests` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`tag_id` INT NOT NULL,
`ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
alter table `poplar`.`poplar_interests` add unique(`user_id`, `tag_id`);
drop table if EXISTS `poplar`.`poplar_followings`;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_followings` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`user_name` VARCHAR(50) NULL,
`following_user_id` INT NOT NULL,
`following_user_name` VARCHAR(50) NULL,
`ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
alter table `poplar`.`poplar_followings` add unique(`user_id`, `following_user_id`);
drop table if EXISTS `poplar`.`poplar_followers` ;
CREATE TABLE IF NOT EXISTS `poplar`.`poplar_followers` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id` INT NOT NULL,
`user_name` VARCHAR(50) NULL,
`follower_user_id` INT NOT NULL,
`follower_user_name` VARCHAR(50) NULL,
`ts` TIMESTAMP NOT NULL DEFAULT current_timestamp,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
alter table `poplar`.`poplar_followers` add unique(`user_id`, `follower_user_id`);