-
Notifications
You must be signed in to change notification settings - Fork 32
/
schema.sql
803 lines (711 loc) · 26.9 KB
/
schema.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
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
-- MySQL dump 10.13 Distrib 8.0.32, for macos13.0 (arm64)
--
-- Host: localhost Database: smithereen
-- ------------------------------------------------------
-- Server version 8.0.32
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
--
-- Table structure for table `accounts`
--
CREATE TABLE `accounts` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`user_id` int unsigned NOT NULL,
`email` varchar(200) NOT NULL DEFAULT '',
`password` binary(32) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`invited_by` int unsigned DEFAULT NULL,
`preferences` text,
`last_active` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`activation_info` json DEFAULT NULL,
`role` int unsigned DEFAULT NULL,
`promoted_by` int unsigned DEFAULT NULL,
`email_domain` varchar(150) NOT NULL DEFAULT '',
`last_ip` binary(16) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
KEY `user_id` (`user_id`),
KEY `invited_by` (`invited_by`),
KEY `role` (`role`),
KEY `promoted_by` (`promoted_by`),
KEY `email_domain` (`email_domain`),
KEY `last_ip` (`last_ip`),
CONSTRAINT `accounts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `accounts_ibfk_2` FOREIGN KEY (`role`) REFERENCES `user_roles` (`id`) ON DELETE SET NULL,
CONSTRAINT `accounts_ibfk_3` FOREIGN KEY (`promoted_by`) REFERENCES `accounts` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `audit_log`
--
CREATE TABLE `audit_log` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`admin_id` int unsigned NOT NULL,
`action` int unsigned NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`owner_id` int DEFAULT NULL,
`object_id` bigint DEFAULT NULL,
`object_type` int unsigned DEFAULT NULL,
`extra` json DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `owner_id` (`owner_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `blocks_email_domain`
--
CREATE TABLE `blocks_email_domain` (
`domain` varchar(100) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`action` tinyint unsigned NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`note` text NOT NULL,
`creator_id` int unsigned NOT NULL,
PRIMARY KEY (`domain`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `blocks_group_domain`
--
CREATE TABLE `blocks_group_domain` (
`owner_id` int unsigned NOT NULL,
`domain` varchar(100) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
UNIQUE KEY `owner_id` (`owner_id`,`domain`),
KEY `domain` (`domain`),
CONSTRAINT `blocks_group_domain_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `blocks_group_user`
--
CREATE TABLE `blocks_group_user` (
`owner_id` int unsigned NOT NULL,
`user_id` int unsigned NOT NULL,
UNIQUE KEY `owner_id` (`owner_id`,`user_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `blocks_group_user_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE,
CONSTRAINT `blocks_group_user_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `blocks_ip`
--
CREATE TABLE `blocks_ip` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`address` binary(16) NOT NULL,
`prefix_length` tinyint unsigned NOT NULL,
`action` tinyint unsigned NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`expires_at` timestamp NOT NULL,
`note` text NOT NULL,
`creator_id` int unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `blocks_user_domain`
--
CREATE TABLE `blocks_user_domain` (
`owner_id` int unsigned NOT NULL,
`domain` varchar(100) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
UNIQUE KEY `owner_id` (`owner_id`,`domain`),
KEY `domain` (`domain`),
CONSTRAINT `blocks_user_domain_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `blocks_user_user`
--
CREATE TABLE `blocks_user_user` (
`owner_id` int unsigned NOT NULL,
`user_id` int unsigned NOT NULL,
UNIQUE KEY `owner_id` (`owner_id`,`user_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `blocks_user_user_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `blocks_user_user_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `bookmarks_group`
--
CREATE TABLE `bookmarks_group` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`owner_id` int unsigned NOT NULL,
`group_id` int unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `owner_id_2` (`owner_id`,`group_id`),
KEY `group_id` (`group_id`),
CONSTRAINT `bookmarks_group_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `bookmarks_user`
--
CREATE TABLE `bookmarks_user` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`owner_id` int unsigned NOT NULL,
`user_id` int unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `owner_id` (`owner_id`,`user_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `bookmarks_user_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `config`
--
CREATE TABLE `config` (
`key` varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '',
`value` mediumtext NOT NULL,
PRIMARY KEY (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `draft_attachments`
--
CREATE TABLE `draft_attachments` (
`id` binary(16) NOT NULL,
`owner_account_id` int unsigned NOT NULL,
`info` text NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `owner_account_id` (`owner_account_id`),
CONSTRAINT `draft_attachments_ibfk_1` FOREIGN KEY (`owner_account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `email_codes`
--
CREATE TABLE `email_codes` (
`code` binary(64) NOT NULL,
`account_id` int unsigned DEFAULT NULL,
`type` int NOT NULL,
`extra` text,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`code`),
KEY `account_id` (`account_id`),
CONSTRAINT `email_codes_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `followings`
--
CREATE TABLE `followings` (
`follower_id` int unsigned NOT NULL,
`followee_id` int unsigned NOT NULL,
`mutual` tinyint(1) NOT NULL DEFAULT '0',
`accepted` tinyint(1) NOT NULL DEFAULT '1',
KEY `follower_id` (`follower_id`),
KEY `followee_id` (`followee_id`),
KEY `mutual` (`mutual`),
KEY `accepted` (`accepted`),
CONSTRAINT `followings_ibfk_1` FOREIGN KEY (`follower_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `followings_ibfk_2` FOREIGN KEY (`followee_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `friend_requests`
--
CREATE TABLE `friend_requests` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`from_user_id` int unsigned NOT NULL,
`to_user_id` int unsigned NOT NULL,
`message` text,
PRIMARY KEY (`id`),
UNIQUE KEY `from_user_id` (`from_user_id`,`to_user_id`),
KEY `to_user_id` (`to_user_id`),
CONSTRAINT `friend_requests_ibfk_1` FOREIGN KEY (`from_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `friend_requests_ibfk_2` FOREIGN KEY (`to_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `group_admins`
--
CREATE TABLE `group_admins` (
`user_id` int unsigned NOT NULL,
`group_id` int unsigned NOT NULL,
`level` int unsigned NOT NULL,
`title` varchar(300) DEFAULT NULL,
`display_order` int unsigned NOT NULL DEFAULT '0',
KEY `user_id` (`user_id`),
KEY `group_id` (`group_id`),
CONSTRAINT `group_admins_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `group_admins_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `group_invites`
--
CREATE TABLE `group_invites` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`inviter_id` int unsigned NOT NULL,
`invitee_id` int unsigned NOT NULL,
`group_id` int unsigned NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`is_event` tinyint(1) NOT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ap_id` (`ap_id`),
KEY `inviter_id` (`inviter_id`),
KEY `invitee_id` (`invitee_id`),
KEY `group_id` (`group_id`),
KEY `is_event` (`is_event`),
CONSTRAINT `group_invites_ibfk_1` FOREIGN KEY (`inviter_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `group_invites_ibfk_2` FOREIGN KEY (`invitee_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `group_invites_ibfk_3` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `group_memberships`
--
CREATE TABLE `group_memberships` (
`user_id` int unsigned NOT NULL,
`group_id` int unsigned NOT NULL,
`post_feed_visibility` tinyint unsigned NOT NULL DEFAULT '0',
`tentative` tinyint(1) NOT NULL DEFAULT '0',
`accepted` tinyint(1) NOT NULL DEFAULT '1',
`time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY `user_id` (`user_id`,`group_id`),
KEY `group_id` (`group_id`),
CONSTRAINT `group_memberships_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `group_memberships_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `groups`
--
CREATE TABLE `groups` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL DEFAULT '',
`username` varchar(64) NOT NULL,
`domain` varchar(100) NOT NULL DEFAULT '',
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
`ap_url` varchar(300) DEFAULT NULL,
`ap_inbox` varchar(300) DEFAULT NULL,
`ap_shared_inbox` varchar(300) DEFAULT NULL,
`public_key` blob NOT NULL,
`private_key` blob,
`avatar` json DEFAULT NULL,
`about` text,
`about_source` text,
`profile_fields` json DEFAULT NULL,
`event_start_time` timestamp NULL DEFAULT NULL,
`event_end_time` timestamp NULL DEFAULT NULL,
`type` tinyint unsigned NOT NULL DEFAULT '0',
`member_count` int unsigned NOT NULL DEFAULT '0',
`tentative_member_count` int unsigned NOT NULL DEFAULT '0',
`last_updated` timestamp NULL DEFAULT NULL,
`flags` bigint unsigned NOT NULL DEFAULT '0',
`endpoints` json DEFAULT NULL,
`access_type` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`,`domain`),
UNIQUE KEY `ap_id` (`ap_id`),
KEY `type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `likes`
--
CREATE TABLE `likes` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int unsigned NOT NULL,
`object_id` int unsigned NOT NULL,
`object_type` int unsigned NOT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
UNIQUE KEY `user_id` (`user_id`,`object_id`,`object_type`),
UNIQUE KEY `id` (`id`),
KEY `object_type` (`object_type`,`object_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `mail_messages`
--
CREATE TABLE `mail_messages` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`owner_id` int unsigned NOT NULL,
`sender_id` int unsigned NOT NULL,
`to` varbinary(1024) NOT NULL,
`cc` varbinary(1024) DEFAULT NULL,
`text` text NOT NULL,
`subject` text NOT NULL,
`attachments` json DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
`read_receipts` varbinary(1024) DEFAULT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
`reply_info` json DEFAULT NULL,
`related_message_ids` varbinary(1024) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `owner_id` (`owner_id`),
KEY `sender_id` (`sender_id`),
KEY `ap_id` (`ap_id`),
KEY `deleted_at` (`deleted_at`),
KEY `read_receipts` (`read_receipts`),
FULLTEXT KEY `text` (`text`,`subject`),
CONSTRAINT `mail_messages_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `mail_messages_peers`
--
CREATE TABLE `mail_messages_peers` (
`owner_id` int unsigned NOT NULL,
`peer_id` int unsigned NOT NULL,
`message_id` bigint unsigned NOT NULL,
KEY `owner_id` (`owner_id`),
KEY `message_id` (`message_id`),
KEY `peer_id` (`peer_id`),
CONSTRAINT `mail_messages_peers_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `mail_messages_peers_ibfk_2` FOREIGN KEY (`message_id`) REFERENCES `mail_messages` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `mail_privacy_grants`
--
CREATE TABLE `mail_privacy_grants` (
`owner_id` int unsigned NOT NULL,
`user_id` int unsigned NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`messages_remain` int unsigned NOT NULL,
PRIMARY KEY (`owner_id`,`user_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `mail_privacy_grants_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `mail_privacy_grants_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `media_cache`
--
CREATE TABLE `media_cache` (
`url_hash` binary(16) NOT NULL,
`size` int unsigned NOT NULL,
`last_access` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`info` blob,
`type` tinyint NOT NULL,
PRIMARY KEY (`url_hash`),
KEY `last_access` (`last_access`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `media_file_refs`
--
CREATE TABLE `media_file_refs` (
`file_id` bigint unsigned NOT NULL,
`object_id` bigint NOT NULL,
`object_type` tinyint unsigned NOT NULL,
`owner_user_id` int unsigned DEFAULT NULL,
`owner_group_id` int unsigned DEFAULT NULL,
PRIMARY KEY (`object_id`,`object_type`,`file_id`),
KEY `file_id` (`file_id`),
KEY `owner_user_id` (`owner_user_id`),
KEY `owner_group_id` (`owner_group_id`),
CONSTRAINT `media_file_refs_ibfk_1` FOREIGN KEY (`file_id`) REFERENCES `media_files` (`id`),
CONSTRAINT `media_file_refs_ibfk_2` FOREIGN KEY (`owner_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `media_file_refs_ibfk_3` FOREIGN KEY (`owner_group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `media_files`
--
CREATE TABLE `media_files` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`random_id` binary(18) NOT NULL,
`size` bigint unsigned NOT NULL,
`type` tinyint unsigned NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`metadata` json NOT NULL,
`ref_count` int unsigned NOT NULL DEFAULT '0',
`original_owner_id` int NOT NULL,
PRIMARY KEY (`id`),
KEY `ref_count` (`ref_count`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `newsfeed`
--
CREATE TABLE `newsfeed` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`type` int unsigned NOT NULL,
`author_id` int NOT NULL,
`object_id` int DEFAULT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `type` (`type`,`object_id`,`author_id`),
KEY `time` (`time`),
KEY `author_id` (`author_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `newsfeed_comments`
--
CREATE TABLE `newsfeed_comments` (
`user_id` int unsigned NOT NULL,
`object_type` int unsigned NOT NULL,
`object_id` int unsigned NOT NULL,
`last_comment_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`object_type`,`object_id`,`user_id`),
KEY `user_id` (`user_id`),
KEY `last_comment_time` (`last_comment_time`),
CONSTRAINT `newsfeed_comments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `notifications`
--
CREATE TABLE `notifications` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`owner_id` int unsigned NOT NULL,
`type` smallint unsigned NOT NULL,
`object_id` int unsigned DEFAULT NULL,
`object_type` smallint unsigned DEFAULT NULL,
`related_object_id` int unsigned DEFAULT NULL,
`related_object_type` smallint unsigned DEFAULT NULL,
`actor_id` int DEFAULT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `owner_id` (`owner_id`),
KEY `time` (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `poll_options`
--
CREATE TABLE `poll_options` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`poll_id` int unsigned NOT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
`text` text NOT NULL,
`num_votes` int unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `ap_id` (`ap_id`),
KEY `poll_id` (`poll_id`),
CONSTRAINT `poll_options_ibfk_1` FOREIGN KEY (`poll_id`) REFERENCES `polls` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `poll_votes`
--
CREATE TABLE `poll_votes` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`user_id` int unsigned NOT NULL,
`poll_id` int unsigned NOT NULL,
`option_id` int unsigned NOT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ap_id` (`ap_id`),
KEY `user_id` (`user_id`),
KEY `poll_id` (`poll_id`),
KEY `option_id` (`option_id`),
CONSTRAINT `poll_votes_ibfk_2` FOREIGN KEY (`poll_id`) REFERENCES `polls` (`id`) ON DELETE CASCADE,
CONSTRAINT `poll_votes_ibfk_3` FOREIGN KEY (`option_id`) REFERENCES `poll_options` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `polls`
--
CREATE TABLE `polls` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`owner_id` int NOT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
`question` text,
`is_anonymous` tinyint(1) NOT NULL DEFAULT '0',
`is_multi_choice` tinyint(1) NOT NULL DEFAULT '0',
`end_time` timestamp NULL DEFAULT NULL,
`num_voted_users` int unsigned NOT NULL DEFAULT '0',
`last_vote_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `ap_id` (`ap_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `qsearch_index`
--
CREATE TABLE `qsearch_index` (
`string` text NOT NULL,
`user_id` int unsigned DEFAULT NULL,
`group_id` int unsigned DEFAULT NULL,
KEY `user_id` (`user_id`),
KEY `group_id` (`group_id`),
FULLTEXT KEY `string` (`string`),
CONSTRAINT `qsearch_index_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `qsearch_index_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=ascii;
--
-- Table structure for table `report_actions`
--
CREATE TABLE `report_actions` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`report_id` int unsigned NOT NULL,
`user_id` int unsigned NOT NULL,
`action_type` tinyint unsigned NOT NULL,
`text` text,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`extra` json DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `report_id` (`report_id`),
CONSTRAINT `report_actions_ibfk_1` FOREIGN KEY (`report_id`) REFERENCES `reports` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `reports`
--
CREATE TABLE `reports` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`reporter_id` int unsigned DEFAULT NULL,
`target_type` tinyint unsigned NOT NULL,
`target_id` int NOT NULL,
`comment` text NOT NULL,
`moderator_id` int unsigned DEFAULT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`server_domain` varchar(100) DEFAULT NULL,
`content` json DEFAULT NULL,
`state` tinyint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `reporter_id` (`reporter_id`),
KEY `moderator_id` (`moderator_id`),
KEY `state` (`state`),
KEY `target_id` (`target_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `servers`
--
CREATE TABLE `servers` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`host` varchar(100) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
`software` varchar(100) DEFAULT NULL,
`version` varchar(30) DEFAULT NULL,
`last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_error_day` date DEFAULT NULL,
`error_day_count` int NOT NULL DEFAULT '0',
`is_up` tinyint unsigned NOT NULL DEFAULT '1',
`is_restricted` tinyint unsigned NOT NULL DEFAULT '0',
`restriction` json DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `host` (`host`),
KEY `is_up` (`is_up`),
KEY `error_day_count` (`error_day_count`),
KEY `is_restricted` (`is_restricted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `sessions`
--
CREATE TABLE `sessions` (
`id` binary(64) NOT NULL,
`account_id` int unsigned NOT NULL,
`last_active` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ip` binary(16) NOT NULL,
`user_agent` bigint NOT NULL,
PRIMARY KEY (`id`),
KEY `account_id` (`account_id`),
CONSTRAINT `sessions_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `signup_invitations`
--
CREATE TABLE `signup_invitations` (
`code` binary(16) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
`owner_id` int unsigned DEFAULT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`signups_remaining` int unsigned NOT NULL,
`email` varchar(200) DEFAULT NULL,
`extra` json DEFAULT NULL,
`id` int unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`code`),
UNIQUE KEY `id` (`id`),
UNIQUE KEY `email` (`email`),
KEY `owner_id` (`owner_id`),
CONSTRAINT `signup_invitations_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `accounts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `signup_requests`
--
CREATE TABLE `signup_requests` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(200) NOT NULL,
`first_name` varchar(100) NOT NULL,
`last_name` varchar(100) DEFAULT NULL,
`reason` text NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `stats_daily`
--
CREATE TABLE `stats_daily` (
`day` date NOT NULL,
`type` int unsigned NOT NULL,
`object_id` int unsigned NOT NULL,
`count` int unsigned NOT NULL,
PRIMARY KEY (`day`,`type`,`object_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `user_agents`
--
CREATE TABLE `user_agents` (
`hash` bigint NOT NULL,
`user_agent` text NOT NULL,
PRIMARY KEY (`hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `user_roles`
--
CREATE TABLE `user_roles` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`permissions` varbinary(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `user_staff_notes`
--
CREATE TABLE `user_staff_notes` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`target_id` int unsigned NOT NULL,
`author_id` int unsigned NOT NULL,
`text` text NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `target_id` (`target_id`),
CONSTRAINT `user_staff_notes_ibfk_1` FOREIGN KEY (`target_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`fname` varchar(100) NOT NULL DEFAULT '',
`lname` varchar(100) DEFAULT NULL,
`middle_name` varchar(100) DEFAULT NULL,
`maiden_name` varchar(100) DEFAULT NULL,
`bdate` date DEFAULT NULL,
`username` varchar(64) NOT NULL,
`domain` varchar(100) NOT NULL DEFAULT '',
`public_key` blob NOT NULL,
`private_key` blob,
`ap_url` varchar(300) DEFAULT NULL,
`ap_inbox` varchar(300) DEFAULT NULL,
`ap_shared_inbox` varchar(300) DEFAULT NULL,
`about` text,
`about_source` text,
`gender` tinyint unsigned NOT NULL DEFAULT '0',
`profile_fields` json DEFAULT NULL,
`avatar` json DEFAULT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
`last_updated` timestamp NULL DEFAULT NULL,
`flags` bigint unsigned NOT NULL,
`endpoints` json DEFAULT NULL,
`privacy` json DEFAULT NULL,
`ban_status` tinyint unsigned NOT NULL DEFAULT '0',
`ban_info` json DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`,`domain`),
UNIQUE KEY `ap_id` (`ap_id`),
KEY `ban_status` (`ban_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Table structure for table `wall_posts`
--
CREATE TABLE `wall_posts` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`author_id` int unsigned DEFAULT NULL,
`owner_user_id` int unsigned DEFAULT NULL,
`owner_group_id` int unsigned DEFAULT NULL,
`text` text,
`attachments` json DEFAULT NULL,
`repost_of` int unsigned DEFAULT NULL,
`ap_url` varchar(300) DEFAULT NULL,
`ap_id` varchar(300) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`content_warning` text,
`updated_at` timestamp NULL DEFAULT NULL,
`reply_key` varbinary(1024) DEFAULT NULL,
`mentions` varbinary(1024) DEFAULT NULL,
`reply_count` int unsigned NOT NULL DEFAULT '0',
`ap_replies` varchar(300) DEFAULT NULL,
`poll_id` int unsigned DEFAULT NULL,
`federation_state` tinyint unsigned NOT NULL DEFAULT '0',
`source` text,
`source_format` tinyint unsigned DEFAULT NULL,
`privacy` tinyint unsigned NOT NULL DEFAULT '0',
`flags` bigint unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `ap_id` (`ap_id`),
KEY `owner_user_id` (`owner_user_id`),
KEY `repost_of` (`repost_of`),
KEY `author_id` (`author_id`),
KEY `reply_key` (`reply_key`),
KEY `owner_group_id` (`owner_group_id`),
KEY `poll_id` (`poll_id`),
CONSTRAINT `wall_posts_ibfk_1` FOREIGN KEY (`owner_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT `wall_posts_ibfk_4` FOREIGN KEY (`owner_group_id`) REFERENCES `groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
-- Dump completed on 2024-06-06 11:51:39