-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
82 lines (60 loc) · 2.71 KB
/
database.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
CREATE TABLE `videos` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`video_id` VARCHAR(30) COLLATE utf8mb4_unicode_ci NOT NULL,
`title` TEXT COLLATE utf8mb4_unicode_ci NOT NULL,
`description` TEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`published_at` TIMESTAMP NOT NULL,
`deleted` BOOL DEFAULT FALSE,
`deleted_at` TIMESTAMP NULL DEFAULT NULL,
`site` TINYINT UNSIGNED NOT NULL,
`alternative` TEXT COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`thumbnail` VARCHAR(256) COLLATE latin1_swedish_ci DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT (`title`),
UNIQUE KEY (`video_id`, `site`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `channels` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`channel_id` VARCHAR(40) NOT NULL,
`name` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`thumbnail` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`channel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `channelVideos` (
`video_id` BIGINT UNSIGNED NOT NULL,
`channel_id` BIGINT UNSIGNED NOT NULL,
FOREIGN KEY (`video_id`) REFERENCES `videos` (`id`),
FOREIGN KEY (`channel_id`) REFERENCES `channels` (`id`),
PRIMARY KEY (`channel_id`, `video_id`)
) ENGINE=InnoDB;
CREATE TABLE `tags` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`tag` VARCHAR(190) COLLATE utf8mb4_bin NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
CREATE TRIGGER lcase_insert BEFORE INSERT ON `tags` FOR EACH ROW SET NEW.tag = LOWER(NEW.tag);
CREATE TABLE `videoTags` (
`video_id` BIGINT UNSIGNED NOT NULL,
`tag_id` BIGINT UNSIGNED NOT NULL,
FOREIGN KEY (`video_id`) REFERENCES `videos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`video_id`, `tag_id`)
) ENGINE=InnoDB;
CREATE TABLE `playlists` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` TEXT COLLATE utf8mb4_unicode_ci NOT NULL,
`playlist_id` VARCHAR(40) COLLATE utf8mb4_unicode_ci NOT NULL,
`site` TINYINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
KEY (`site`),
UNIQUE KEY (`playlist_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLlATE=utf8mb4_unicode_ci;
CREATE TABLE `playlistVideos` (
`playlist_id` BIGINT UNSIGNED NOT NULL,
`video_id` BIGINT UNSIGNED NOT NULL,
FOREIGN KEY (`playlist_id`) REFERENCES `playlists` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`video_id`) REFERENCES `videos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`playlist_id`, `video_id`)
) ENGINE=InnoDB;