aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/resources/schema.sql
blob: 59c979d5f8df7ae25fa2edf281214014829bea13 (plain) (blame)
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
SET MODE MYSQL;
SET DB_CLOSE_ON_EXIT TRUE;

CREATE TABLE IF NOT EXISTS `android` (
  `user_id` int(10) unsigned NOT NULL,
  `regid` char(255) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
);
CREATE TABLE IF NOT EXISTS `auth` (
  `user_id` int(10) unsigned NOT NULL,
  `protocol` enum('xmpp','email','sms') NOT NULL,
  `account` char(64) NOT NULL,
  `authcode` char(8) NOT NULL
);
CREATE TABLE IF NOT EXISTS `bl_tags` (
  `user_id` int(10) unsigned NOT NULL,
  `tag_id` int(10) unsigned NOT NULL,
);
CREATE TABLE IF NOT EXISTS `bl_users` (
  `user_id` int(10) unsigned NOT NULL,
  `bl_user_id` int(10) unsigned NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_id`,`bl_user_id`)
);
CREATE TABLE IF NOT EXISTS `emails` (
  `user_id` int(10) unsigned NOT NULL,
  `email` char(64) NOT NULL,
  `subscr_hour` tinyint(4) DEFAULT NULL,
  KEY `email` (`email`)
);
CREATE TABLE IF NOT EXISTS `facebook` (
  `user_id` int(10) unsigned DEFAULT NULL,
  `fb_id` bigint(20) unsigned NOT NULL,
  `loginhash` char(36) DEFAULT NULL,
  `access_token` char(255) DEFAULT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `fb_name` char(64) NOT NULL,
  `fb_link` char(64) NOT NULL,
  `crosspost` tinyint(1) unsigned NOT NULL DEFAULT '1',
  KEY `user_id` (`user_id`)
);

CREATE TABLE IF NOT EXISTS `reactions` (
 `like_id` int(10) unsigned NOT NULL,
 `description` varchar (100) NOT NULL
);
CREATE TABLE IF NOT EXISTS `favorites` (
  `user_id` int(10) unsigned NOT NULL,
  `message_id` int(10) unsigned NOT NULL,
  `ts` datetime NOT NULL,
   `like_id` int(10),
  foreign key (like_id) references reactions(like_id)
);



CREATE TABLE IF NOT EXISTS `friends_facebook` (
  `user_id` int(10) unsigned NOT NULL,
  `friend_id` bigint(20) unsigned NOT NULL,
  UNIQUE KEY `user_id` (`user_id`,`friend_id`)
);
CREATE TABLE IF NOT EXISTS `images` (
  `mid` int(10) unsigned NOT NULL,
  `rid` int(10) unsigned NOT NULL,
  `thumb` int(10) unsigned NOT NULL,
  `small` int(10) unsigned NOT NULL,
  `medium` int(10) unsigned NOT NULL,
  `height` int(10) unsigned NOT NULL,
  `width` int(10) unsigned NOT NULL,
  PRIMARY KEY (`mid`,`rid`)
);
CREATE TABLE IF NOT EXISTS `ios` (
  `user_id` int(10) unsigned NOT NULL,
  `token` char(64) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY `token` (`token`),
  KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `jids` (
  `user_id` int(10) unsigned DEFAULT NULL,
  `jid` char(64) NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `loginhash` char(36) DEFAULT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY `jid` (`jid`),
  KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `logins` (
  `user_id` int(10) unsigned NOT NULL,
  `hash` char(16) NOT NULL,
  UNIQUE KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `mail` (
  `user_id` int(10) unsigned NOT NULL,
  `hash` char(16) NOT NULL,
  PRIMARY KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `meon` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(10) unsigned NOT NULL,
  `link` char(255) NOT NULL,
  `name` char(32) NOT NULL,
  `ico` smallint(5) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `messages` (
  `message_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(10) unsigned NOT NULL,
  `lang` enum('en','ru','fr','fa','__') NOT NULL DEFAULT '__',
  `ts` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `replies` smallint(5) unsigned NOT NULL DEFAULT '0',
  `maxreplyid` smallint(5) unsigned NOT NULL DEFAULT '0',
  `privacy` tinyint(4) NOT NULL DEFAULT '1',
  `readonly` tinyint(1) NOT NULL DEFAULT '0',
  `attach` nchar(3) check (attach in ('jpg', 'mp4', 'png')),
  `place_id` int(10) unsigned DEFAULT NULL,
  `lat` decimal(10,7) DEFAULT NULL,
  `lon` decimal(10,7) DEFAULT NULL,
  `popular` tinyint(4) NOT NULL DEFAULT '0',
  `hidden` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `likes` smallint(6) NOT NULL DEFAULT '0',
  `updated` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`message_id`),
  KEY (`user_id`),
  KEY (`ts`),
  KEY (`attach`),
  KEY (`place_id`),
  KEY (`popular`),
  KEY (`hidden`),
  KEY (`updated`,`message_id`)
);

CREATE TABLE IF NOT EXISTS `messages_access` (
  `message_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  KEY (`message_id`)
);

CREATE TABLE IF NOT EXISTS `messages_tags` (
  `message_id` int(10) unsigned NOT NULL,
  `tag_id` int(10) unsigned NOT NULL,
  UNIQUE KEY `message_id_2` (`message_id`,`tag_id`),
  KEY (`message_id`),
  KEY (`tag_id`)
);

CREATE TABLE IF NOT EXISTS `messages_txt` (
  `message_id` int(10) unsigned NOT NULL,
  `tags` varchar(255) DEFAULT NULL,
  `repliesby` varchar(96) DEFAULT NULL,
  `txt` mediumtext NOT NULL,
  PRIMARY KEY (`message_id`)
);

CREATE TABLE IF NOT EXISTS `messages_votes` (
  `message_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `vote` tinyint(4) NOT NULL DEFAULT '1',
  UNIQUE KEY `message_id` (`message_id`,`user_id`)
);

CREATE TABLE IF NOT EXISTS `messenger` (
  `user_id` int(10) unsigned DEFAULT NULL,
  `sender_id` bigint(20) NOT NULL,
  `display_name` char(64) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `loginhash` char(36) DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS `places` (
  `place_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `lat` decimal(10,7) NOT NULL,
  `lon` decimal(10,7) NOT NULL,
  `name` char(64) NOT NULL,
  `descr` char(255) DEFAULT NULL,
  `url` char(128) DEFAULT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`place_id`)
);

CREATE TABLE IF NOT EXISTS `places_tags` (
  `place_id` int(10) unsigned NOT NULL,
  `tag_id` int(10) unsigned NOT NULL
);

CREATE TABLE IF NOT EXISTS `pm` (
  `user_id` int(10) unsigned NOT NULL,
  `user_id_to` int(10) unsigned NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `txt` text NOT NULL
);

CREATE TABLE IF NOT EXISTS `pm_inroster` (
  `user_id` int(10) unsigned NOT NULL,
  `jid` char(64) NOT NULL,
  UNIQUE KEY (`user_id`,`jid`),
  KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `pm_streams` (
  `user_id` int(10) unsigned NOT NULL,
  `user_id_to` int(10) unsigned NOT NULL,
  `lastmessage` datetime NOT NULL,
  `lastview` datetime DEFAULT NULL,
  `unread` smallint(5) unsigned NOT NULL DEFAULT '0',
  UNIQUE KEY (`user_id`,`user_id_to`)
);

CREATE TABLE IF NOT EXISTS `presence` (
  `user_id` int(10) unsigned NOT NULL,
  `jid` char(64) DEFAULT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY (`jid`)
);

CREATE TABLE IF NOT EXISTS `replies` (
  `message_id` int(10) unsigned NOT NULL,
  `reply_id` smallint(5) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `replyto` smallint(5) unsigned NOT NULL DEFAULT '0',
  `ts` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `attach` nchar(3) check (attach in ('jpg', 'mp4', 'png')),
  `txt` mediumtext NOT NULL,
  KEY (`message_id`),
  KEY (`user_id`),
  KEY (`ts`)
);

CREATE TABLE IF NOT EXISTS `subscr_messages` (
  `message_id` int(10) unsigned NOT NULL,
  `suser_id` int(10) unsigned NOT NULL,
  `last_read_rid` smallint(5) unsigned NOT NULL DEFAULT '0',
  UNIQUE KEY (`message_id`,`suser_id`)
);

CREATE TABLE IF NOT EXISTS `subscr_tags` (
  `tag_id` int(10) unsigned NOT NULL,
  `suser_id` int(10) unsigned NOT NULL,
  UNIQUE KEY (`tag_id`,`suser_id`)
);

CREATE TABLE IF NOT EXISTS `subscr_users` (
  `user_id` int(10) unsigned NOT NULL,
  `suser_id` int(10) unsigned NOT NULL,
  `jid` char(64) DEFAULT NULL,
  `active` bit(1) NOT NULL DEFAULT TRUE,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY (`user_id`,`suser_id`),
  KEY (`suser_id`)
);

CREATE TABLE IF NOT EXISTS `tags` (
  `tag_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `synonym_id` int(10) unsigned DEFAULT NULL,
  `name` varchar_ignorecase(70) DEFAULT NULL,
  `top` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `noindex` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `stat_messages` int(10) unsigned NOT NULL DEFAULT '0',
  `stat_users` smallint(5) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`tag_id`),
  KEY (`synonym_id`)
);

CREATE TABLE IF NOT EXISTS `tags_ignore` (
  `tag_id` int(10) unsigned NOT NULL
);

CREATE TABLE IF NOT EXISTS `tags_synonyms` (
  `name` char(64) NOT NULL,
  `changeto` char(64) NOT NULL
);

CREATE TABLE IF NOT EXISTS `telegram` (
  `user_id` int(10) unsigned DEFAULT NULL,
  `tg_id` bigint(20) NOT NULL,
  `tg_name` char(64) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `loginhash` char(36) DEFAULT NULL
);

CREATE TABLE IF NOT EXISTS `telegram_chats` (
  `chat_id` bigint(20) DEFAULT NULL,
  UNIQUE KEY `chat_id` (`chat_id`)
);

CREATE TABLE IF NOT EXISTS `top_ignore_messages` (
  `message_id` int(10) unsigned NOT NULL
);

CREATE TABLE IF NOT EXISTS `top_ignore_tags` (
  `tag_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`tag_id`)
);

CREATE TABLE IF NOT EXISTS `top_ignore_users` (
  `user_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `twitter` (
  `user_id` int(10) unsigned NOT NULL,
  `access_token` char(64) NOT NULL,
  `access_token_secret` char(64) NOT NULL,
  `uname` char(64) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `crosspost` tinyint(1) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `useroptions` (
  `user_id` int(10) unsigned NOT NULL,
  `jnotify` tinyint(1) NOT NULL DEFAULT '1',
  `subscr_active` tinyint(1) NOT NULL DEFAULT '1',
  `off_ts` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `xmppxhtml` tinyint(1) NOT NULL DEFAULT '0',
  `subscr_notify` tinyint(1) NOT NULL DEFAULT '1',
  `recommendations` tinyint(1) NOT NULL DEFAULT '1',
  `privacy_view` tinyint(1) NOT NULL DEFAULT '1',
  `privacy_reply` tinyint(1) NOT NULL DEFAULT '1',
  `privacy_pm` tinyint(1) NOT NULL DEFAULT '1',
  `repliesview` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`user_id`),
  KEY `recommendations` (`recommendations`)
);

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nick` char(64) NOT NULL,
  `passw` char(32) NOT NULL,
  `lang` enum('en','ru','fr','fa','__') NOT NULL DEFAULT '__',
  `banned` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `lastmessage` timestamp(9) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `lastpm` int(11) NOT NULL DEFAULT '0',
  `lastphoto` int(11) NOT NULL DEFAULT '0',
  `karma` smallint(6) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `nick` (`nick`)
);

CREATE TABLE IF NOT EXISTS `users_refs` (
  `user_id` int(10) unsigned NOT NULL,
  `ref` int(10) unsigned NOT NULL,
  KEY `ref` (`ref`)
);

CREATE TABLE IF NOT EXISTS `users_subscr` (
  `user_id` int(10) unsigned NOT NULL,
  `cnt` smallint(5) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `usersinfo` (
  `user_id` int(10) unsigned NOT NULL,
  `jid` char(32) DEFAULT NULL,
  `fullname` char(32) DEFAULT NULL,
  `country` char(32) DEFAULT NULL,
  `url` char(64) DEFAULT NULL,
  `gender` char(32) DEFAULT NULL,
  `bday` char(10) DEFAULT NULL,
  `descr` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `version` (
  `version` bigint(20) NOT NULL
);

CREATE TABLE IF NOT EXISTS `vk` (
  `user_id` int(10) unsigned DEFAULT NULL,
  `vk_id` bigint(20) NOT NULL,
  `loginhash` char(36) DEFAULT NULL,
  `access_token` char(128) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `vk_name` char(64) NOT NULL,
  `vk_link` char(64) NOT NULL,
  `crosspost` bit(1) unsigned NOT NULL DEFAULT FALSE,
  KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `winphone` (
  `user_id` int(10) unsigned NOT NULL,
  `url` char(255) NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY (`url`),
  KEY (`user_id`)
);

CREATE TABLE IF NOT EXISTS `wl_users` (
  `user_id` int(10) unsigned NOT NULL,
  `wl_user_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`user_id`,`wl_user_id`)
);