-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_script.sql
352 lines (311 loc) · 13.6 KB
/
db_script.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
-- MySQL Script generated by MySQL Workbench
-- Fri Aug 19 22:30:32 2022
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema twitch-collector
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema twitch-collector
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `twitch-collector` DEFAULT CHARACTER SET utf8 ;
USE `twitch-collector` ;
-- -----------------------------------------------------
-- Table `twitch-collector`.`circles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`circles` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`number` BIGINT UNSIGNED NOT NULL,
`startTime` DATETIME(3) NULL,
`endTime` DATETIME(3) NULL,
`grabDuration` INT UNSIGNED NULL DEFAULT 0,
`totalChannels` INT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`sites`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`sites` (
`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
`site` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `site_UNIQUE` (`site` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`channels`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`channels` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`lastCircle_id` BIGINT UNSIGNED NULL,
`name` VARCHAR(45) NOT NULL,
`lastCheckedTime` DATETIME(3) NULL,
`site_id` TINYINT UNSIGNED NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC, `site_id` ASC) ,
INDEX `fk_channels_circles1_idx` (`lastCircle_id` ASC) ,
INDEX `fk_channels_sites1_idx` (`site_id` ASC) ,
CONSTRAINT `fk_channels_circles1`
FOREIGN KEY (`lastCircle_id`)
REFERENCES `twitch-collector`.`circles` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_channels_sites1`
FOREIGN KEY (`site_id`)
REFERENCES `twitch-collector`.`sites` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`users` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`site_id` TINYINT UNSIGNED NOT NULL DEFAULT 1,
`lastVisit` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC, `site_id` ASC) ,
INDEX `fk_users_site1_idx` (`site_id` ASC) ,
CONSTRAINT `fk_users_site1`
FOREIGN KEY (`site_id`)
REFERENCES `twitch-collector`.`sites` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`user_types`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`user_types` (
`id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
`type` VARCHAR(45) NOT NULL,
`platforms` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`users_channels`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`users_channels` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` BIGINT UNSIGNED NOT NULL,
`channel_id` BIGINT UNSIGNED NOT NULL,
`firstCircle_id` BIGINT UNSIGNED NULL,
`lastCircle_id` BIGINT UNSIGNED NULL,
`type_id` TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX `fk_users_has_channels_channels1_idx` (`channel_id` ASC) ,
INDEX `fk_users_has_channels_users_idx` (`user_id` ASC) ,
INDEX `fk_users_channels_circles1_idx` (`firstCircle_id` ASC) ,
INDEX `fk_users_channels_circles2_idx` (`lastCircle_id` ASC) ,
INDEX `fk_users_channels_user_types1_idx` (`type_id` ASC) ,
CONSTRAINT `fk_users_has_channels_users`
FOREIGN KEY (`user_id`)
REFERENCES `twitch-collector`.`users` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_has_channels_channels1`
FOREIGN KEY (`channel_id`)
REFERENCES `twitch-collector`.`channels` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_channels_circles1`
FOREIGN KEY (`firstCircle_id`)
REFERENCES `twitch-collector`.`circles` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_channels_circles2`
FOREIGN KEY (`lastCircle_id`)
REFERENCES `twitch-collector`.`circles` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_channels_user_types1`
FOREIGN KEY (`type_id`)
REFERENCES `twitch-collector`.`user_types` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`channelstocheck`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`channelstocheck` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`priority` INT NULL,
`site_id` TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC, `site_id` ASC) ,
INDEX `fk_channelstocheck_sites1_idx` (`site_id` ASC) ,
CONSTRAINT `fk_channelstocheck_sites1`
FOREIGN KEY (`site_id`)
REFERENCES `twitch-collector`.`sites` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`channels_circles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`channels_circles` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`circle_id` BIGINT UNSIGNED NOT NULL,
`channel_id` BIGINT UNSIGNED NOT NULL,
`collectTime` DATETIME(3) NULL,
`chattersCount` INT NULL,
PRIMARY KEY (`id`),
INDEX `fk_channels_circles_circles1_idx` (`circle_id` ASC) ,
INDEX `fk_channels_circles_channels1_idx` (`channel_id` ASC) ,
CONSTRAINT `fk_channels_circles_circles1`
FOREIGN KEY (`circle_id`)
REFERENCES `twitch-collector`.`circles` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_channels_circles_channels1`
FOREIGN KEY (`channel_id`)
REFERENCES `twitch-collector`.`channels` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`tgusers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`tgusers` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`tg_id` VARCHAR(25) NOT NULL,
`firstName` VARCHAR(64) NOT NULL,
`lastName` VARCHAR(64) NULL,
`username` VARCHAR(32) NULL,
`language` VARCHAR(8) NOT NULL,
`messagesTotal` BIGINT UNSIGNED NOT NULL DEFAULT 0,
`state` VARCHAR(100) NOT NULL,
`firstOnlineTime` DATETIME(3) NOT NULL,
`lastOnlineTime` DATETIME(3) NOT NULL,
`balance` BIGINT UNSIGNED NOT NULL DEFAULT 0,
`donationKey` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `tg_id_UNIQUE` (`tg_id` ASC) ,
UNIQUE INDEX `donationKey_UNIQUE` (`donationKey` ASC) VISIBLE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`tghistory`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`tghistory` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`tgUser_id` BIGINT UNSIGNED NOT NULL,
`message` VARCHAR(300) NOT NULL,
`result` VARCHAR(100) NULL,
`messageTime` DATETIME(3) NOT NULL,
`requestTime` DATETIME(3) NOT NULL,
`answerTime` DATETIME(3) NULL,
PRIMARY KEY (`id`),
INDEX `fk_tgHistory_tgUsers1_idx` (`tgUser_id` ASC) ,
CONSTRAINT `fk_tgHistory_tgUsers1`
FOREIGN KEY (`tgUser_id`)
REFERENCES `twitch-collector`.`tgusers` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`tgbans`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`tgbans` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`tgUser_id` BIGINT UNSIGNED NOT NULL,
`reason` VARCHAR(100) NOT NULL,
`fromTime` DATETIME(3) NOT NULL,
`untilTime` DATETIME(3) NOT NULL,
INDEX `fk_tgBans_tgUsers1_idx` (`tgUser_id` ASC) ,
PRIMARY KEY (`id`),
CONSTRAINT `fk_tgBans_tgUsers1`
FOREIGN KEY (`tgUser_id`)
REFERENCES `twitch-collector`.`tgusers` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`donations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`donations` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`lastDonationTime` DATETIME(3) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`tgpayments`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`tgpayments` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`tgUser_id` BIGINT UNSIGNED NULL,
`donationId` BIGINT UNSIGNED NULL,
`amount` INT UNSIGNED NOT NULL,
`donationTime` DATETIME(3) NULL,
`getTime` DATETIME(3) NULL,
`message` VARCHAR(200) NULL,
`title` VARCHAR(100) NULL,
INDEX `fk_tgpayments_tgusers1_idx` (`tgUser_id` ASC) ,
PRIMARY KEY (`id`),
CONSTRAINT `fk_tgpayments_tgusers1`
FOREIGN KEY (`tgUser_id`)
REFERENCES `twitch-collector`.`tgusers` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `twitch-collector`.`tgpurchases`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `twitch-collector`.`tgpurchases` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`tgUser_id` BIGINT UNSIGNED NOT NULL,
`amount` INT UNSIGNED NOT NULL,
`goodType` VARCHAR(100) NOT NULL,
`applyTime` DATETIME(3) NOT NULL,
`durationEnd` DATETIME(3) NULL,
PRIMARY KEY (`id`),
INDEX `fk_tgpurchases_tgusers1_idx` (`tgUser_id` ASC) ,
CONSTRAINT `fk_tgpurchases_tgusers1`
FOREIGN KEY (`tgUser_id`)
REFERENCES `twitch-collector`.`tgusers` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
-- -----------------------------------------------------
-- Data for table `twitch-collector`.`sites`
-- -----------------------------------------------------
START TRANSACTION;
USE `twitch-collector`;
INSERT INTO `twitch-collector`.`sites` (`id`, `site`) VALUES (1, 'twitch');
INSERT INTO `twitch-collector`.`sites` (`id`, `site`) VALUES (2, 'wasd');
INSERT INTO `twitch-collector`.`sites` (`id`, `site`) VALUES (3, 'trovo');
INSERT INTO `twitch-collector`.`sites` (`id`, `site`) VALUES (4, 'goodgame');
COMMIT;
-- -----------------------------------------------------
-- Data for table `twitch-collector`.`user_types`
-- -----------------------------------------------------
START TRANSACTION;
USE `twitch-collector`;
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (1, 'admin', 'twitch,trovo,goodgame');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (2, 'staff', 'twitch,trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (3, 'broadcaster', 'twitch,trovo,goodgame,wasd');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (4, 'moderator', 'twitch,trovo,goodgame,wasd');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (5, 'vip', 'twitch,trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (6, 'viewer', 'twitch,trovo,goodgame,wasd');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (7, 'globalMod', 'twitch,trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (8, 'stream_moder', 'goodgame');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (9, 'smoderator', 'trovo,goodgame');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (10, 'ace', 'trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (11, 'aceplus', 'trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (12, 'creators', 'trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (13, 'editors', 'trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (14, 'followers', 'trovo');
INSERT INTO `twitch-collector`.`user_types` (`id`, `type`, `platforms`) VALUES (15, 'subscribers', 'trovo');
COMMIT;
-- -----------------------------------------------------
-- Data for table `twitch-collector`.`donations`
-- -----------------------------------------------------
START TRANSACTION;
USE `twitch-collector`;
INSERT INTO `twitch-collector`.`donations` (`id`, `lastDonationTime`) VALUES (1, NULL);
COMMIT;