-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
223 lines (198 loc) · 9.29 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
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
-- Adminer 4.6.3 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `files`;
CREATE TABLE `files` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`telegram_file_id` varchar(255) CHARACTER SET latin1 NOT NULL,
`md5_sum` char(32) CHARACTER SET latin1 NOT NULL,
`sha1_sum` char(40) CHARACTER SET latin1 NOT NULL,
`absolute_hash` char(74) CHARACTER SET latin1 NOT NULL,
`hit_count` bigint(20) NOT NULL DEFAULT '0',
`file_type` varchar(32) CHARACTER SET latin1 NOT NULL DEFAULT 'unknown',
`extension` varchar(32) CHARACTER SET latin1 DEFAULT NULL,
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `absolute_hash` (`absolute_hash`),
KEY `md5_sum` (`md5_sum`),
KEY `sha1_sum` (`sha1_sum`),
KEY `telegram_file_id` (`telegram_file_id`),
KEY `file_type` (`file_type`),
FULLTEXT KEY `description` (`description`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `groups`;
CREATE TABLE `groups` (
`id` bigint(20) NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`username` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`link` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`photo` bigint(20) DEFAULT NULL,
`msg_count` bigint(20) NOT NULL DEFAULT '0',
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`last_seen` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `photo` (`photo`),
KEY `name` (`name`),
KEY `username` (`username`),
KEY `link` (`link`),
CONSTRAINT `groups_ibfk_2` FOREIGN KEY (`photo`) REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `groups_history`;
CREATE TABLE `groups_history` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` bigint(20) DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`username` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`link` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`photo` bigint(20) DEFAULT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `group_id` (`group_id`),
KEY `photo` (`photo`),
CONSTRAINT `groups_history_ibfk_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `groups_history_ibfk_4` FOREIGN KEY (`photo`) REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `group_admin`;
CREATE TABLE `group_admin` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` bigint(20) NOT NULL,
`user_id` int(11) NOT NULL,
`status` enum('creator','administrator') CHARACTER SET latin1 NOT NULL DEFAULT 'administrator',
`can_change_info` tinyint(1) NOT NULL,
`can_delete_messages` tinyint(1) NOT NULL,
`can_invite_users` tinyint(1) NOT NULL,
`can_restrict_members` tinyint(1) NOT NULL,
`can_pin_messages` tinyint(1) NOT NULL,
`can_promote_members` tinyint(1) NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `group_id` (`group_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `group_admin_ibfk_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `group_admin_ibfk_4` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `group_messages`;
CREATE TABLE `group_messages` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`group_id` bigint(20) DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
`tmsg_id` bigint(20) NOT NULL,
`reply_to_tmsg_id` bigint(20) DEFAULT NULL,
`msg_type` varchar(32) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`text` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`text_entities` text CHARACTER SET latin1 COLLATE latin1_general_ci,
`file` bigint(20) DEFAULT NULL,
`is_edited_message` tinyint(1) NOT NULL DEFAULT '0',
`tmsg_datetime` datetime NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `group_id` (`group_id`),
KEY `file` (`file`),
KEY `user_id` (`user_id`),
KEY `tmsg_id` (`tmsg_id`),
FULLTEXT KEY `text` (`text`),
CONSTRAINT `group_messages_ibfk_4` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `group_messages_ibfk_5` FOREIGN KEY (`file`) REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `group_messages_ibfk_6` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `group_settings`;
CREATE TABLE `group_settings` (
`group_id` bigint(20) NOT NULL,
`max_warns` int(11) NOT NULL DEFAULT '3',
`welcome_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
KEY `group_id` (`group_id`),
CONSTRAINT `group_settings_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `private_messages`;
CREATE TABLE `private_messages` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`tmsg_id` bigint(20) NOT NULL,
`reply_to_tmsg_id` bigint(20) DEFAULT NULL,
`msg_type` varchar(32) CHARACTER SET latin1 NOT NULL DEFAULT 'unknown',
`text` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`text_entities` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`file` bigint(20) DEFAULT NULL,
`is_edited_message` tinyint(1) NOT NULL DEFAULT '0',
`tmsg_datetime` datetime NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `tmsg_id` (`tmsg_id`),
KEY `file` (`file`),
FULLTEXT KEY `text` (`text`),
CONSTRAINT `private_messages_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `private_messages_ibfk_4` FOREIGN KEY (`file`) REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `sudoers`;
CREATE TABLE `sudoers` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `sudoers_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`username` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
`first_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`last_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`is_bot` tinyint(1) DEFAULT '0',
`photo` bigint(20) DEFAULT NULL,
`private_message_count` bigint(20) DEFAULT '0',
`group_message_count` bigint(20) DEFAULT '0',
`created_at` datetime NOT NULL,
`updated_at` datetime DEFAULT NULL,
`last_seen` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `username` (`username`),
KEY `first_name` (`first_name`),
KEY `last_name` (`last_name`),
KEY `photo` (`photo`),
CONSTRAINT `users_ibfk_2` FOREIGN KEY (`photo`) REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `users_history`;
CREATE TABLE `users_history` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`username` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`first_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`last_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`photo` bigint(20) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `photo` (`photo`),
KEY `first_name` (`first_name`),
KEY `last_name` (`last_name`),
KEY `username` (`username`),
KEY `user_id` (`user_id`),
CONSTRAINT `users_history_ibfk_4` FOREIGN KEY (`photo`) REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `users_history_ibfk_5` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `user_warning`;
CREATE TABLE `user_warning` (
`id` bigint(20) NOT NULL,
`group_id` bigint(20) NOT NULL,
`user_id` int(11) NOT NULL,
`warned_by` int(11) DEFAULT NULL,
`reason` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime NOT NULL,
KEY `group_id` (`group_id`),
KEY `warned_by` (`warned_by`),
KEY `user_id` (`user_id`),
CONSTRAINT `user_warning_ibfk_4` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `user_warning_ibfk_5` FOREIGN KEY (`warned_by`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `user_warning_ibfk_6` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 2019-01-01 15:25:26