-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathschema.sql
More file actions
1932 lines (1773 loc) · 87.8 KB
/
Copy pathschema.sql
File metadata and controls
1932 lines (1773 loc) · 87.8 KB
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
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Accounts, privacy and access
CREATE TABLE public.accounts (
user_id bigint NOT NULL,
lastfm text,
lastfm_session_key text,
steam text,
roblox text,
genshin text,
letterboxd text,
spotify text,
spotify_refresh_token text,
anilist text,
anilist_access_token text,
CONSTRAINT accounts_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.banned_ips (
ip text NOT NULL,
banned_at timestamp with time zone DEFAULT now(),
CONSTRAINT banned_ips_pkey PRIMARY KEY (ip)
);
CREATE TABLE public.global_user_blocks (
user_id bigint NOT NULL,
blocked_by bigint NOT NULL,
blocked_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT global_user_blocks_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.guild_hourly_post_blocks (
guild_id bigint NOT NULL,
user_id bigint NOT NULL,
blocked_by bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT guild_hourly_post_blocks_pkey PRIMARY KEY (guild_id, user_id)
);
CREATE INDEX guild_hourly_post_blocks_user_idx ON public.guild_hourly_post_blocks USING btree (user_id, guild_id);
CREATE TABLE public.guild_opted_out (
guild_id bigint NOT NULL,
items text[],
CONSTRAINT guild_opted_out_pkey PRIMARY KEY (guild_id)
);
CREATE TABLE public.guild_settings (
guild_id bigint NOT NULL,
auto_download bigint,
auto_upload bigint,
auto_upload_images boolean DEFAULT true NOT NULL,
auto_upload_gifs boolean DEFAULT true NOT NULL,
auto_upload_videos boolean DEFAULT true NOT NULL,
poketwo boolean DEFAULT false,
poketwo_channel bigint,
auto_reactions boolean DEFAULT false,
auto_reactions_channel bigint,
pinboard bigint,
mudae_auto_scrape_series boolean DEFAULT false NOT NULL,
mudae_recent_claims boolean DEFAULT true NOT NULL,
dehoist boolean DEFAULT false,
snipe_enabled boolean DEFAULT false NOT NULL,
editsnipe_enabled boolean DEFAULT false NOT NULL,
tracking_enabled boolean DEFAULT true NOT NULL,
history_public boolean DEFAULT true NOT NULL,
CONSTRAINT guild_settings_pkey PRIMARY KEY (guild_id)
);
CREATE TABLE public.mudae_dm_consent (
user_id bigint NOT NULL,
consented boolean DEFAULT true NOT NULL,
CONSTRAINT mudae_dm_consent_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.oauth_states (
state_hash text NOT NULL,
code_verifier text NOT NULL,
redirect_uri text NOT NULL,
expires_at timestamp with time zone NOT NULL,
CONSTRAINT oauth_states_pkey PRIMARY KEY (state_hash)
);
CREATE INDEX oauth_states_expires_at_idx ON public.oauth_states USING btree (expires_at);
CREATE TABLE public.opted_out (
user_id bigint NOT NULL,
items text[],
CONSTRAINT opted_out_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.phone_consent (
user_id bigint NOT NULL,
consented boolean NOT NULL,
CONSTRAINT phone_consent_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.post_library_blocks (
user_id bigint NOT NULL,
blocked_uploader_id bigint NOT NULL,
blocked_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT post_library_blocks_not_self CHECK ((user_id <> blocked_uploader_id)),
CONSTRAINT post_library_blocks_pkey PRIMARY KEY (user_id, blocked_uploader_id)
);
CREATE INDEX post_library_blocks_uploader_idx ON public.post_library_blocks USING btree (blocked_uploader_id, user_id);
CREATE TABLE public.post_upload_blocks (
user_id bigint NOT NULL,
blocked_by bigint NOT NULL,
blocked_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT post_upload_blocks_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.social_user_settings (
user_id bigint NOT NULL,
friend_requests_enabled boolean DEFAULT true NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT social_user_settings_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.user_settings (
user_id bigint NOT NULL,
timezone text,
anilist_default_media text DEFAULT 'anime'::text NOT NULL,
currency_tracking_enabled boolean DEFAULT true NOT NULL,
tracking_enabled boolean DEFAULT true NOT NULL,
history_public boolean DEFAULT false NOT NULL,
first_use_notice_shown boolean DEFAULT false NOT NULL,
wordle_hard_mode boolean DEFAULT false NOT NULL,
wordle_colourblind_mode boolean DEFAULT false NOT NULL,
game_tracking_enabled boolean DEFAULT true NOT NULL,
game_history_public boolean DEFAULT true NOT NULL,
tracking_consent boolean DEFAULT false NOT NULL,
CONSTRAINT user_settings_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.video_library_blocks (
user_id bigint NOT NULL,
blocked_uploader_id bigint NOT NULL,
blocked_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT video_library_blocks_not_self CHECK ((user_id <> blocked_uploader_id)),
CONSTRAINT video_library_blocks_pkey PRIMARY KEY (user_id, blocked_uploader_id)
);
CREATE INDEX video_library_blocks_uploader_idx ON public.video_library_blocks USING btree (blocked_uploader_id, user_id);
CREATE TABLE public.video_upload_blocks (
user_id bigint NOT NULL,
blocked_by bigint NOT NULL,
blocked_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT video_upload_blocks_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.web_sessions (
session_id_hash text NOT NULL,
user_id bigint NOT NULL,
discord_access_token text NOT NULL,
expires_at timestamp with time zone NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
last_seen_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT web_sessions_pkey PRIMARY KEY (session_id_hash)
);
CREATE INDEX web_sessions_expires_at_idx ON public.web_sessions USING btree (expires_at);
-- Currency, shop catalogs and ownership
CREATE TABLE public.badge_catalog (
badge_key text NOT NULL,
category text NOT NULL,
display_name text NOT NULL,
emoji_name text NOT NULL,
emoji_id bigint,
is_custom boolean DEFAULT false NOT NULL,
unicode boolean DEFAULT true NOT NULL,
animated boolean DEFAULT false NOT NULL,
price bigint,
enabled boolean DEFAULT true NOT NULL,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT badge_catalog_category_check CHECK ((category = ANY (ARRAY['stat'::text, 'purchase'::text]))),
CONSTRAINT badge_catalog_check CHECK (((category = 'stat'::text) OR (price IS NOT NULL))),
CONSTRAINT badge_catalog_price_check CHECK (((price IS NULL) OR (price > 0))),
CONSTRAINT badge_catalog_pkey PRIMARY KEY (badge_key)
);
CREATE TABLE public.birthday_rewards (
user_id bigint NOT NULL,
last_awarded_on date NOT NULL,
CONSTRAINT birthday_rewards_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.color_catalog (
color_key text NOT NULL,
display_name text NOT NULL,
hex_value text NOT NULL,
price bigint NOT NULL,
enabled boolean DEFAULT true NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT color_catalog_price_check CHECK ((price > 0)),
CONSTRAINT color_catalog_pkey PRIMARY KEY (color_key)
);
CREATE TABLE public.currency_wallets (
user_id bigint NOT NULL,
balance bigint DEFAULT 0 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT currency_wallets_balance_check CHECK (((balance >= 0) AND (balance <= '9000000000000000000'::bigint))),
CONSTRAINT currency_wallets_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.currency_claims (
user_id bigint NOT NULL,
claim_type text NOT NULL,
period_start date NOT NULL,
base_amount bigint NOT NULL,
bonus_amount bigint DEFAULT 0 NOT NULL,
claimed_at timestamp with time zone DEFAULT now() NOT NULL,
streak integer DEFAULT 0 NOT NULL,
streak_bonus_amount bigint DEFAULT 0 NOT NULL,
CONSTRAINT currency_claims_base_amount_check CHECK ((base_amount > 0)),
CONSTRAINT currency_claims_bonus_amount_check CHECK ((bonus_amount >= 0)),
CONSTRAINT currency_claims_claim_type_check CHECK ((claim_type = ANY (ARRAY['daily'::text, 'weekly'::text]))),
CONSTRAINT currency_claims_streak_bonus_amount_check CHECK ((streak_bonus_amount >= 0)),
CONSTRAINT currency_claims_streak_check CHECK ((streak >= 0)),
CONSTRAINT currency_claims_pkey PRIMARY KEY (user_id, claim_type, period_start),
CONSTRAINT currency_claims_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id) ON DELETE CASCADE
);
CREATE TABLE public.currency_daily_rewards (
user_id bigint NOT NULL,
source text NOT NULL,
period_start date NOT NULL,
amount bigint NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT currency_daily_rewards_amount_check CHECK ((amount >= 0)),
CONSTRAINT currency_daily_rewards_pkey PRIMARY KEY (user_id, source, period_start),
CONSTRAINT currency_daily_rewards_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id) ON DELETE CASCADE
);
CREATE TABLE public.currency_gambling_stats (
user_id bigint NOT NULL,
total_wagered bigint DEFAULT 0 NOT NULL,
total_earned bigint DEFAULT 0 NOT NULL,
total_lost bigint DEFAULT 0 NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
losses bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT currency_gambling_stats_losses_check CHECK ((losses >= 0)),
CONSTRAINT currency_gambling_stats_total_earned_check CHECK ((total_earned >= 0)),
CONSTRAINT currency_gambling_stats_total_lost_check CHECK ((total_lost >= 0)),
CONSTRAINT currency_gambling_stats_total_wagered_check CHECK ((total_wagered >= 0)),
CONSTRAINT currency_gambling_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT currency_gambling_stats_pkey PRIMARY KEY (user_id),
CONSTRAINT currency_gambling_stats_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id) ON DELETE CASCADE
);
CREATE INDEX currency_gambling_stats_wins_idx ON public.currency_gambling_stats USING btree (wins DESC, user_id);
CREATE TABLE public.currency_transactions (
id bigserial NOT NULL,
user_id bigint NOT NULL,
amount bigint NOT NULL,
source text NOT NULL,
reference_key text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT currency_transactions_amount_check CHECK ((amount <> 0)),
CONSTRAINT currency_transactions_pkey PRIMARY KEY (id),
CONSTRAINT currency_transactions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX currency_transactions_reference_idx ON public.currency_transactions USING btree (user_id, reference_key) WHERE (reference_key IS NOT NULL);
CREATE INDEX currency_transactions_user_created_idx ON public.currency_transactions USING btree (user_id, created_at DESC);
CREATE TABLE public.currency_wagers (
id bigserial NOT NULL,
user_id bigint NOT NULL,
source text NOT NULL,
stake bigint,
status text DEFAULT 'open'::text NOT NULL,
payout bigint DEFAULT 0 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
settled_at timestamp with time zone,
CONSTRAINT currency_wagers_check CHECK ((((status = 'open'::text) AND (payout = 0) AND (settled_at IS NULL)) OR ((status = 'lost'::text) AND (payout = 0) AND (settled_at IS NOT NULL)) OR ((status = 'cashed_out'::text) AND (payout > 0) AND (settled_at IS NOT NULL)))),
CONSTRAINT currency_wagers_payout_check CHECK (((payout >= 0) AND (payout <= '1000000000000000000'::bigint))),
CONSTRAINT currency_wagers_status_check CHECK ((status = ANY (ARRAY['open'::text, 'lost'::text, 'cashed_out'::text]))),
CONSTRAINT currency_wagers_pkey PRIMARY KEY (id),
CONSTRAINT currency_wagers_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id) ON DELETE CASCADE
);
ALTER TABLE public.currency_wagers
ADD CONSTRAINT currency_wagers_stake_limit_check CHECK ((stake >= 10)) NOT VALID;
CREATE INDEX currency_wagers_user_created_idx ON public.currency_wagers USING btree (user_id, created_at DESC);
CREATE TABLE public.lottery_rounds (
round_start timestamp with time zone NOT NULL,
prize_pool bigint DEFAULT 1000 NOT NULL,
status text DEFAULT 'open'::text NOT NULL,
winning_ticket character(6),
winner_user_id bigint,
drawn_at timestamp with time zone,
CONSTRAINT lottery_rounds_check CHECK ((((status = 'open'::text) AND (winning_ticket IS NULL) AND (winner_user_id IS NULL) AND (drawn_at IS NULL)) OR ((status = 'no_winner'::text) AND (winning_ticket IS NULL) AND (winner_user_id IS NULL) AND (drawn_at IS NOT NULL)) OR ((status = 'drawn'::text) AND (winning_ticket IS NOT NULL) AND (drawn_at IS NOT NULL)))),
CONSTRAINT lottery_rounds_prize_pool_check CHECK (((prize_pool >= 1000) AND (prize_pool <= '9000000000000000000'::bigint))),
CONSTRAINT lottery_rounds_status_check CHECK ((status = ANY (ARRAY['open'::text, 'drawn'::text, 'no_winner'::text]))),
CONSTRAINT lottery_rounds_pkey PRIMARY KEY (round_start),
CONSTRAINT lottery_rounds_winner_user_id_fkey FOREIGN KEY (winner_user_id) REFERENCES public.currency_wallets(user_id) ON DELETE SET NULL
);
CREATE TABLE public.lottery_tickets (
id bigserial NOT NULL,
round_start timestamp with time zone NOT NULL,
user_id bigint NOT NULL,
ticket_digits character(6) NOT NULL,
purchased_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT lottery_tickets_ticket_digits_check CHECK ((ticket_digits ~ '^[0-9]{6}$'::text)),
CONSTRAINT lottery_tickets_pkey PRIMARY KEY (id),
CONSTRAINT lottery_tickets_round_start_ticket_digits_key UNIQUE (round_start, ticket_digits),
CONSTRAINT lottery_tickets_round_start_fkey FOREIGN KEY (round_start) REFERENCES public.lottery_rounds(round_start) ON DELETE CASCADE,
CONSTRAINT lottery_tickets_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id) ON DELETE CASCADE
);
CREATE INDEX lottery_tickets_user_round_idx ON public.lottery_tickets USING btree (user_id, round_start);
CREATE TABLE public.ring_catalog (
ring_key text NOT NULL,
display_name text NOT NULL,
emoji_name text NOT NULL,
emoji_id bigint,
unicode boolean DEFAULT true NOT NULL,
animated boolean DEFAULT false NOT NULL,
display text NOT NULL,
price bigint NOT NULL,
enabled boolean DEFAULT true NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT ring_catalog_price_check CHECK ((price > 0)),
CONSTRAINT ring_catalog_pkey PRIMARY KEY (ring_key)
);
CREATE TABLE public.title_catalog (
title_key text NOT NULL,
display_name text NOT NULL,
price bigint NOT NULL,
enabled boolean DEFAULT true NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
category text DEFAULT 'Misc titles'::text NOT NULL,
CONSTRAINT title_catalog_price_check CHECK ((price > 0)),
CONSTRAINT title_catalog_pkey PRIMARY KEY (title_key)
);
CREATE TABLE public.user_badge_orders (
user_id bigint NOT NULL,
badge_keys text[] DEFAULT ARRAY[]::text[] NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT user_badge_orders_pkey PRIMARY KEY (user_id)
);
CREATE INDEX user_badge_orders_updated_idx ON public.user_badge_orders USING btree (updated_at DESC);
CREATE TABLE public.user_badges (
id bigserial NOT NULL,
user_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
emoji_name text NOT NULL,
emoji_id bigint,
is_custom boolean NOT NULL,
unicode boolean DEFAULT false NOT NULL,
animated boolean DEFAULT false NOT NULL,
badge_key text DEFAULT 'custom'::text NOT NULL,
text text NOT NULL,
badge_source text DEFAULT 'owner'::text NOT NULL,
catalog_key text,
purchase_price bigint DEFAULT 0 NOT NULL,
purchase_guild_id bigint,
active boolean DEFAULT true NOT NULL,
revoked_at timestamp with time zone,
refund_amount bigint DEFAULT 0 NOT NULL,
revocation_reason text,
CONSTRAINT user_badges_badge_source_check CHECK ((badge_source = ANY (ARRAY['owner'::text, 'stat'::text, 'purchase'::text]))),
CONSTRAINT user_badges_check CHECK (((is_custom AND (emoji_id IS NOT NULL) AND (NOT unicode)) OR ((NOT is_custom) AND (emoji_id IS NULL) AND unicode))),
CONSTRAINT user_badges_purchase_price_check CHECK ((purchase_price >= 0)),
CONSTRAINT user_badges_refund_amount_check CHECK ((refund_amount >= 0)),
CONSTRAINT user_badges_pkey PRIMARY KEY (id)
);
CREATE INDEX user_badges_active_idx ON public.user_badges USING btree (user_id, id DESC) WHERE active;
CREATE INDEX user_badges_catalog_idx ON public.user_badges USING btree (catalog_key, active, id DESC);
CREATE INDEX user_badges_user_idx ON public.user_badges USING btree (user_id, id DESC);
CREATE UNIQUE INDEX user_badges_user_key_idx ON public.user_badges USING btree (user_id, badge_key);
CREATE TABLE public.user_colors (
user_id bigint NOT NULL,
color_key text NOT NULL,
hex_value text NOT NULL,
purchase_price bigint NOT NULL,
active boolean DEFAULT true NOT NULL,
equipped boolean DEFAULT false NOT NULL,
purchased_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT user_colors_purchase_price_check CHECK ((purchase_price > 0)),
CONSTRAINT user_colors_pkey PRIMARY KEY (user_id, color_key),
CONSTRAINT user_colors_color_key_fkey FOREIGN KEY (color_key) REFERENCES public.color_catalog(color_key),
CONSTRAINT user_colors_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id)
);
CREATE INDEX user_colors_active_idx ON public.user_colors USING btree (user_id, purchased_at DESC) WHERE active;
CREATE UNIQUE INDEX user_colors_one_equipped_idx ON public.user_colors USING btree (user_id) WHERE (active AND equipped);
CREATE TABLE public.user_racing_emojis (
user_id bigint NOT NULL,
emoji_key text NOT NULL,
emoji_name text NOT NULL,
emoji_id bigint,
unicode boolean DEFAULT true NOT NULL,
animated boolean DEFAULT false NOT NULL,
display text NOT NULL,
category text NOT NULL,
purchase_price bigint NOT NULL,
purchase_guild_id bigint,
active boolean DEFAULT true NOT NULL,
equipped boolean DEFAULT false NOT NULL,
purchased_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT user_racing_emojis_purchase_price_check CHECK ((purchase_price > 0)),
CONSTRAINT user_racing_emojis_pkey PRIMARY KEY (user_id, emoji_key),
CONSTRAINT user_racing_emojis_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id)
);
CREATE INDEX user_racing_emojis_active_idx ON public.user_racing_emojis USING btree (user_id, purchased_at DESC) WHERE active;
CREATE UNIQUE INDEX user_racing_emojis_one_equipped_idx ON public.user_racing_emojis USING btree (user_id) WHERE (active AND equipped);
CREATE TABLE public.user_rings (
user_id bigint NOT NULL,
ring_key text NOT NULL,
quantity bigint DEFAULT 0 NOT NULL,
equipped_count bigint DEFAULT 0 NOT NULL,
purchased_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT user_rings_check CHECK (((equipped_count = ANY (ARRAY[(0)::bigint, (1)::bigint])) AND (equipped_count <= quantity))),
CONSTRAINT user_rings_quantity_check CHECK ((quantity >= 0)),
CONSTRAINT user_rings_pkey PRIMARY KEY (user_id, ring_key),
CONSTRAINT user_rings_ring_key_fkey FOREIGN KEY (ring_key) REFERENCES public.ring_catalog(ring_key),
CONSTRAINT user_rings_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.currency_wallets(user_id)
);
CREATE INDEX user_rings_inventory_idx ON public.user_rings USING btree (user_id, updated_at DESC) WHERE (quantity > 0);
CREATE UNIQUE INDEX user_rings_one_equipped_idx ON public.user_rings USING btree (user_id) WHERE (equipped_count > 0);
CREATE TABLE public.user_titles (
user_id bigint NOT NULL,
title_key text NOT NULL,
text text NOT NULL,
purchase_price bigint NOT NULL,
active boolean DEFAULT true NOT NULL,
purchased_at timestamp with time zone DEFAULT now() NOT NULL,
equipped boolean DEFAULT false NOT NULL,
CONSTRAINT user_titles_purchase_price_check CHECK ((purchase_price > 0)),
CONSTRAINT user_titles_pkey PRIMARY KEY (user_id, title_key),
CONSTRAINT user_titles_title_key_fkey FOREIGN KEY (title_key) REFERENCES public.title_catalog(title_key)
);
CREATE INDEX user_titles_active_idx ON public.user_titles USING btree (user_id, purchased_at DESC) WHERE active;
CREATE UNIQUE INDEX user_titles_one_equipped_idx ON public.user_titles USING btree (user_id) WHERE (active AND equipped);
-- Profiles, social and reputation
CREATE TABLE public.guild_rep (
guild_id bigint NOT NULL,
count bigint DEFAULT 0 NOT NULL,
CONSTRAINT guild_rep_pkey PRIMARY KEY (guild_id)
);
CREATE TABLE public.message_xp (
id serial NOT NULL,
user_id bigint NOT NULL,
messages bigint,
xp bigint,
CONSTRAINT message_xp_pkey PRIMARY KEY (user_id)
);
CREATE INDEX message_xp_leaderboard_idx ON public.message_xp USING btree (xp DESC, user_id);
CREATE TABLE public.reputation_events (
id bigserial NOT NULL,
giver_id bigint NOT NULL,
receiver_id bigint,
guild_id bigint,
kind text NOT NULL,
source text NOT NULL,
source_message_id bigint,
period_start date NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT reputation_events_check CHECK ((((kind = 'user'::text) AND (receiver_id IS NOT NULL)) OR ((kind = 'guild'::text) AND (receiver_id IS NULL) AND (guild_id IS NOT NULL)))),
CONSTRAINT reputation_events_kind_check CHECK ((kind = ANY (ARRAY['user'::text, 'guild'::text]))),
CONSTRAINT reputation_events_source_check CHECK ((source = ANY (ARRAY['fishie'::text, 'tatsu'::text]))),
CONSTRAINT reputation_events_pkey PRIMARY KEY (id)
);
CREATE UNIQUE INDEX reputation_events_fishie_period_idx ON public.reputation_events USING btree (giver_id, kind, period_start) WHERE (source = 'fishie'::text);
CREATE INDEX reputation_events_giver_idx ON public.reputation_events USING btree (giver_id, created_at);
CREATE INDEX reputation_events_guild_idx ON public.reputation_events USING btree (guild_id, created_at);
CREATE INDEX reputation_events_receiver_idx ON public.reputation_events USING btree (receiver_id, created_at);
CREATE UNIQUE INDEX reputation_events_source_message_idx ON public.reputation_events USING btree (source_message_id) WHERE (source_message_id IS NOT NULL);
CREATE TABLE public.social_follows (
follower_id bigint NOT NULL,
followed_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT social_follows_check CHECK ((follower_id <> followed_id)),
CONSTRAINT social_follows_pkey PRIMARY KEY (follower_id, followed_id)
);
CREATE INDEX social_follows_followed_idx ON public.social_follows USING btree (followed_id, created_at DESC);
CREATE TABLE public.social_friend_requests (
requester_id bigint NOT NULL,
recipient_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT social_friend_requests_check CHECK ((requester_id <> recipient_id)),
CONSTRAINT social_friend_requests_pkey PRIMARY KEY (requester_id, recipient_id)
);
CREATE INDEX social_friend_requests_recipient_idx ON public.social_friend_requests USING btree (recipient_id, created_at DESC);
CREATE TABLE public.social_friendships (
user_low_id bigint NOT NULL,
user_high_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT social_friendships_check CHECK ((user_low_id < user_high_id)),
CONSTRAINT social_friendships_pkey PRIMARY KEY (user_low_id, user_high_id)
);
CREATE INDEX social_friendships_high_idx ON public.social_friendships USING btree (user_high_id, created_at DESC);
CREATE TABLE public.social_marriage_cooldowns (
user_id bigint NOT NULL,
available_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT social_marriage_cooldowns_pkey PRIMARY KEY (user_id)
);
CREATE INDEX social_marriage_cooldowns_available_idx ON public.social_marriage_cooldowns USING btree (available_at);
CREATE TABLE public.social_marriages (
id bigserial NOT NULL,
proposer_id bigint NOT NULL,
recipient_id bigint NOT NULL,
ring_key text NOT NULL,
married_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT social_marriages_check CHECK ((proposer_id <> recipient_id)),
CONSTRAINT social_marriages_pkey PRIMARY KEY (id),
CONSTRAINT social_marriages_ring_key_fkey FOREIGN KEY (ring_key) REFERENCES public.ring_catalog(ring_key)
);
CREATE TABLE public.social_marriage_members (
user_id bigint NOT NULL,
marriage_id bigint NOT NULL,
CONSTRAINT social_marriage_members_pkey PRIMARY KEY (user_id),
CONSTRAINT social_marriage_members_marriage_id_fkey FOREIGN KEY (marriage_id) REFERENCES public.social_marriages(id) ON DELETE CASCADE
);
CREATE INDEX social_marriage_members_marriage_idx ON public.social_marriage_members USING btree (marriage_id);
CREATE TABLE public.user_birthdays (
user_id bigint NOT NULL,
month smallint NOT NULL,
day smallint NOT NULL,
year smallint,
CONSTRAINT user_birthdays_check CHECK ((EXTRACT(month FROM make_date(COALESCE((year)::integer, 2000), (month)::integer, (day)::integer)) = (month)::numeric)),
CONSTRAINT user_birthdays_day_check CHECK (((day >= 1) AND (day <= 31))),
CONSTRAINT user_birthdays_month_check CHECK (((month >= 1) AND (month <= 12))),
CONSTRAINT user_birthdays_year_check CHECK (((year >= 1) AND (year <= 9999))),
CONSTRAINT user_birthdays_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.user_profiles (
user_id bigint NOT NULL,
description text,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT user_profiles_description_length CHECK (((description IS NULL) OR (char_length(description) <= 500))),
CONSTRAINT user_profiles_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.user_rep (
id serial NOT NULL,
user_id bigint,
count integer
);
CREATE UNIQUE INDEX user_rep_user_idx ON public.user_rep USING btree (user_id);
CREATE TABLE public.user_rep_logs (
id serial NOT NULL,
user_id bigint,
author_id bigint,
value boolean,
comment text,
guild_id bigint,
source_message_id bigint,
created_at timestamp with time zone DEFAULT now()
);
CREATE UNIQUE INDEX user_rep_logs_source_message_idx ON public.user_rep_logs USING btree (source_message_id) WHERE (source_message_id IS NOT NULL);
-- Games and clicks
CREATE TABLE public.caught_fish (
user_id bigint NOT NULL,
bass bigint,
commandtuna bigint,
salmon bigint,
caught_fish bigint,
carp bigint,
trout bigint,
sardine bigint,
blue_tang bigint,
pike bigint,
mackerel bigint,
red_snapper bigint,
shark bigint,
hammerhead_shark bigint,
great_white_shark bigint,
leviathan bigint,
kraken bigint,
CONSTRAINT caught_fish_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.click_guild_totals (
guild_id bigint NOT NULL,
clicks bigint DEFAULT 0 NOT NULL,
CONSTRAINT click_guild_totals_clicks_check CHECK ((clicks >= 0)),
CONSTRAINT click_guild_totals_pkey PRIMARY KEY (guild_id)
);
CREATE TABLE public.click_totals (
id boolean DEFAULT true NOT NULL,
clicks bigint DEFAULT 0 NOT NULL,
CONSTRAINT click_totals_clicks_check CHECK ((clicks >= 0)),
CONSTRAINT click_totals_id_check CHECK (id),
CONSTRAINT click_totals_pkey PRIMARY KEY (id)
);
INSERT INTO public.click_totals (id, clicks) VALUES (true, 0);
CREATE TABLE public.click_user_guild_totals (
user_id bigint NOT NULL,
guild_id bigint NOT NULL,
clicks bigint DEFAULT 0 NOT NULL,
CONSTRAINT click_user_guild_totals_clicks_check CHECK ((clicks >= 0)),
CONSTRAINT click_user_guild_totals_pkey PRIMARY KEY (user_id, guild_id)
);
CREATE TABLE public.click_user_totals (
user_id bigint NOT NULL,
clicks bigint DEFAULT 0 NOT NULL,
CONSTRAINT click_user_totals_clicks_check CHECK ((clicks >= 0)),
CONSTRAINT click_user_totals_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.connectfour_games (
id bigserial NOT NULL,
guild_id bigint,
channel_id bigint NOT NULL,
player_yellow_id bigint NOT NULL,
player_red_id bigint NOT NULL,
winner_id bigint,
loser_id bigint,
against_bot boolean DEFAULT false NOT NULL,
bot_difficulty text,
started_by_id bigint NOT NULL,
started_at timestamp with time zone DEFAULT now() NOT NULL,
finished_at timestamp with time zone DEFAULT now() NOT NULL,
move_count integer DEFAULT 0 NOT NULL,
move_history jsonb DEFAULT '[]'::jsonb NOT NULL,
CONSTRAINT connectfour_bot_difficulty_check CHECK (((against_bot AND (bot_difficulty = ANY (ARRAY['easy'::text, 'normal'::text, 'hard'::text]))) OR ((NOT against_bot) AND (bot_difficulty IS NULL)))),
CONSTRAINT connectfour_loser_player_check CHECK (((loser_id IS NULL) OR ((loser_id = player_yellow_id) OR (loser_id = player_red_id)))),
CONSTRAINT connectfour_move_count_check CHECK ((move_count >= 0)),
CONSTRAINT connectfour_winner_loser_check CHECK (((winner_id IS NULL) OR (loser_id IS NULL) OR (winner_id <> loser_id))),
CONSTRAINT connectfour_winner_player_check CHECK (((winner_id IS NULL) OR ((winner_id = player_yellow_id) OR (winner_id = player_red_id)))),
CONSTRAINT connectfour_games_pkey PRIMARY KEY (id)
);
CREATE INDEX connectfour_games_difficulty_winner_idx ON public.connectfour_games USING btree (bot_difficulty, winner_id) WHERE against_bot;
CREATE INDEX connectfour_games_loser_idx ON public.connectfour_games USING btree (loser_id);
CREATE INDEX connectfour_games_player_red_idx ON public.connectfour_games USING btree (player_red_id);
CREATE INDEX connectfour_games_player_yellow_idx ON public.connectfour_games USING btree (player_yellow_id);
CREATE INDEX connectfour_games_winner_idx ON public.connectfour_games USING btree (winner_id);
CREATE TABLE public.download_stats (
user_id bigint NOT NULL,
site text NOT NULL,
downloads bigint DEFAULT 0 NOT NULL,
first_downloaded_at timestamp with time zone DEFAULT now() NOT NULL,
last_downloaded_at timestamp with time zone DEFAULT now() NOT NULL,
auto_download boolean DEFAULT false NOT NULL,
CONSTRAINT download_stats_downloads_check CHECK ((downloads >= 0)),
CONSTRAINT download_stats_site_check CHECK ((site <> ''::text)),
CONSTRAINT download_stats_pkey PRIMARY KEY (user_id, site, auto_download)
);
CREATE INDEX download_stats_site_idx ON public.download_stats USING btree (site, downloads DESC);
CREATE TABLE public.emoji_stats (
author_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
emoji_id text NOT NULL,
guild_id bigint NOT NULL,
unicode boolean DEFAULT false NOT NULL
);
CREATE INDEX emoji_stats_author_emoji_idx ON public.emoji_stats USING btree (author_id, emoji_id, unicode);
CREATE INDEX emoji_stats_created_at_idx ON public.emoji_stats USING btree (created_at);
CREATE INDEX emoji_stats_guild_emoji_idx ON public.emoji_stats USING btree (guild_id, emoji_id, unicode);
CREATE TABLE public.fishing_accounts (
user_id bigint NOT NULL,
coins bigint DEFAULT 20 NOT NULL,
equipped_rod_key text,
equipped_rod_rarity_key text,
equipped_bait_key text,
total_catches bigint DEFAULT 0 NOT NULL,
CONSTRAINT fishing_accounts_coins_check CHECK ((coins >= 0)),
CONSTRAINT fishing_accounts_total_catches_check CHECK ((total_catches >= 0)),
CONSTRAINT fishing_accounts_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.fishing_bait (
user_id bigint NOT NULL,
bait_key text NOT NULL,
quantity bigint DEFAULT 0 NOT NULL,
CONSTRAINT fishing_bait_quantity_check CHECK ((quantity >= 0)),
CONSTRAINT fishing_bait_pkey PRIMARY KEY (user_id, bait_key),
CONSTRAINT fishing_bait_account_fk FOREIGN KEY (user_id) REFERENCES public.fishing_accounts(user_id) ON DELETE CASCADE
);
CREATE TABLE public.fishing_catches (
user_id bigint NOT NULL,
creature_key text NOT NULL,
rarity_key text NOT NULL,
quantity bigint DEFAULT 1 NOT NULL,
CONSTRAINT fishing_catches_quantity_check CHECK ((quantity > 0)),
CONSTRAINT fishing_catches_pkey PRIMARY KEY (user_id, creature_key, rarity_key),
CONSTRAINT fishing_catches_account_fk FOREIGN KEY (user_id) REFERENCES public.fishing_accounts(user_id) ON DELETE CASCADE
);
CREATE TABLE public.fishing_rods (
user_id bigint NOT NULL,
rod_key text NOT NULL,
rarity_key text NOT NULL,
quantity bigint DEFAULT 1 NOT NULL,
CONSTRAINT fishing_rods_quantity_check CHECK ((quantity > 0)),
CONSTRAINT fishing_rods_pkey PRIMARY KEY (user_id, rod_key, rarity_key),
CONSTRAINT fishing_rods_account_fk FOREIGN KEY (user_id) REFERENCES public.fishing_accounts(user_id) ON DELETE CASCADE
);
CREATE TABLE public.game_2048_games (
id bigserial NOT NULL,
user_id bigint NOT NULL,
guild_id bigint,
channel_id bigint,
score bigint DEFAULT 0 NOT NULL,
highest_tile bigint DEFAULT 0 NOT NULL,
move_count integer DEFAULT 0 NOT NULL,
move_history jsonb DEFAULT '[]'::jsonb NOT NULL,
timed_out boolean DEFAULT false NOT NULL,
gave_up boolean DEFAULT false NOT NULL,
duration_seconds bigint DEFAULT 0 NOT NULL,
started_at timestamp with time zone NOT NULL,
finished_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT game_2048_games_duration_seconds_check CHECK ((duration_seconds >= 0)),
CONSTRAINT game_2048_games_highest_tile_check CHECK ((highest_tile >= 0)),
CONSTRAINT game_2048_games_move_count_check CHECK ((move_count >= 0)),
CONSTRAINT game_2048_games_score_check CHECK ((score >= 0)),
CONSTRAINT game_2048_games_pkey PRIMARY KEY (id)
);
CREATE INDEX game_2048_games_user_idx ON public.game_2048_games USING btree (user_id, finished_at DESC);
CREATE TABLE public.game_2048_stats (
user_id bigint NOT NULL,
high_score bigint DEFAULT 0 NOT NULL,
total_playtime_seconds bigint DEFAULT 0 NOT NULL,
games_completed bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT game_2048_stats_games_completed_check CHECK ((games_completed >= 0)),
CONSTRAINT game_2048_stats_high_score_check CHECK ((high_score >= 0)),
CONSTRAINT game_2048_stats_total_playtime_seconds_check CHECK ((total_playtime_seconds >= 0)),
CONSTRAINT game_2048_stats_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.lastletter_stats (
user_id bigint NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
losses bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT lastletter_stats_losses_check CHECK ((losses >= 0)),
CONSTRAINT lastletter_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT lastletter_stats_pkey PRIMARY KEY (user_id)
);
CREATE INDEX lastletter_stats_leaderboard_idx ON public.lastletter_stats USING btree (wins DESC, losses, updated_at, user_id);
CREATE TABLE public.lightsout_games (
id bigserial NOT NULL,
user_id bigint NOT NULL,
guild_id bigint,
channel_id bigint NOT NULL,
move_count integer NOT NULL,
duration_seconds double precision NOT NULL,
started_at timestamp with time zone NOT NULL,
finished_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT lightsout_games_duration_seconds_check CHECK ((duration_seconds >= (0)::double precision)),
CONSTRAINT lightsout_games_move_count_check CHECK ((move_count >= 0)),
CONSTRAINT lightsout_games_pkey PRIMARY KEY (id)
);
CREATE INDEX lightsout_games_fastest_idx ON public.lightsout_games USING btree (duration_seconds, move_count, finished_at);
CREATE INDEX lightsout_games_fewest_moves_idx ON public.lightsout_games USING btree (move_count, duration_seconds, finished_at);
CREATE INDEX lightsout_games_user_idx ON public.lightsout_games USING btree (user_id, finished_at DESC);
CREATE TABLE public.lucky_roll_stats (
user_id bigint NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
losses bigint DEFAULT 0 NOT NULL,
coins_earned bigint DEFAULT 0 NOT NULL,
coins_lost bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT lucky_roll_stats_coins_earned_check CHECK ((coins_earned >= 0)),
CONSTRAINT lucky_roll_stats_coins_lost_check CHECK ((coins_lost >= 0)),
CONSTRAINT lucky_roll_stats_losses_check CHECK ((losses >= 0)),
CONSTRAINT lucky_roll_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT lucky_roll_stats_pkey PRIMARY KEY (user_id)
);
CREATE INDEX lucky_roll_stats_leaderboard_idx ON public.lucky_roll_stats USING btree (wins DESC, coins_earned DESC, updated_at, user_id);
CREATE TABLE public.minigame_stats (
game text NOT NULL,
user_id bigint NOT NULL,
difficulty text NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
fails bigint DEFAULT 0 NOT NULL,
CONSTRAINT minigame_stats_fails_check CHECK ((fails >= 0)),
CONSTRAINT minigame_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT minigame_stats_pkey PRIMARY KEY (game, user_id, difficulty)
);
CREATE INDEX minigame_stats_game_idx ON public.minigame_stats USING btree (game, difficulty, wins DESC);
CREATE TABLE public.pokemon_guesses (
pokemon_name text NOT NULL,
author_id bigint NOT NULL,
correct bigint DEFAULT 0,
incorrect bigint DEFAULT 0,
CONSTRAINT pokemon_guesses_pkey PRIMARY KEY (pokemon_name, author_id)
);
CREATE TABLE public.pokemon_solves (
id serial NOT NULL,
user_id bigint NOT NULL,
pokemon_name text NOT NULL,
method text NOT NULL,
guild_id bigint,
created_at timestamp with time zone DEFAULT now()
);
CREATE INDEX pokemon_solves_user_created_idx ON public.pokemon_solves USING btree (user_id, created_at DESC);
CREATE TABLE public.sea_animal_race_stats (
user_id bigint NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
losses bigint DEFAULT 0 NOT NULL,
faints bigint DEFAULT 0 NOT NULL,
coins_earned bigint DEFAULT 0 NOT NULL,
coins_lost bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT sea_animal_race_stats_coins_earned_check CHECK ((coins_earned >= 0)),
CONSTRAINT sea_animal_race_stats_coins_lost_check CHECK ((coins_lost >= 0)),
CONSTRAINT sea_animal_race_stats_faints_check CHECK ((faints >= 0)),
CONSTRAINT sea_animal_race_stats_losses_check CHECK ((losses >= 0)),
CONSTRAINT sea_animal_race_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT sea_animal_race_stats_pkey PRIMARY KEY (user_id)
);
CREATE INDEX sea_animal_race_stats_leaderboard_idx ON public.sea_animal_race_stats USING btree (wins DESC, coins_earned DESC, updated_at, user_id);
CREATE TABLE public.sold_fish (
user_id bigint NOT NULL,
bass bigint,
commandtuna bigint,
salmon bigint,
caught_fish bigint,
carp bigint,
trout bigint,
sardine bigint,
blue_tang bigint,
pike bigint,
mackerel bigint,
red_snapper bigint,
shark bigint,
hammerhead_shark bigint,
great_white_shark bigint,
leviathan bigint,
kraken bigint,
CONSTRAINT sold_fish_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.streak_game_stats (
game text NOT NULL,
user_id bigint NOT NULL,
highest_streak bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
highest_streak_payout bigint DEFAULT 0 NOT NULL,
highest_payout bigint DEFAULT 0 NOT NULL,
highest_payout_streak bigint DEFAULT 0 NOT NULL,
CONSTRAINT streak_game_stats_game_check CHECK ((game = ANY (ARRAY['higher_or_lower'::text, 'heads_or_tails'::text, 'rock_paper_scissors'::text]))),
CONSTRAINT streak_game_stats_highest_payout_check CHECK ((highest_payout >= 0)),
CONSTRAINT streak_game_stats_highest_payout_streak_check CHECK ((highest_payout_streak >= 0)),
CONSTRAINT streak_game_stats_highest_streak_check CHECK ((highest_streak >= 0)),
CONSTRAINT streak_game_stats_highest_streak_payout_check CHECK ((highest_streak_payout >= 0)),
CONSTRAINT streak_game_stats_pkey PRIMARY KEY (game, user_id)
);
CREATE INDEX streak_game_stats_leaderboard_idx ON public.streak_game_stats USING btree (game, highest_streak DESC, updated_at, user_id);
CREATE INDEX streak_game_stats_payout_leaderboard_idx ON public.streak_game_stats USING btree (game, highest_payout DESC, highest_payout_streak DESC, user_id);
CREATE TABLE public.tictactoe_games (
id bigserial NOT NULL,
guild_id bigint,
channel_id bigint NOT NULL,
player_x_id bigint NOT NULL,
player_o_id bigint NOT NULL,
winner_id bigint,
loser_id bigint,
against_bot boolean DEFAULT false NOT NULL,
bot_difficulty text,
started_by_id bigint NOT NULL,
started_at timestamp with time zone DEFAULT now() NOT NULL,
finished_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT tictactoe_bot_difficulty_check CHECK (((against_bot AND (bot_difficulty = ANY (ARRAY['easy'::text, 'normal'::text, 'hard'::text]))) OR ((NOT against_bot) AND (bot_difficulty IS NULL)))),
CONSTRAINT tictactoe_loser_player_check CHECK (((loser_id IS NULL) OR ((loser_id = player_x_id) OR (loser_id = player_o_id)))),
CONSTRAINT tictactoe_winner_loser_check CHECK (((winner_id IS NULL) OR (loser_id IS NULL) OR (winner_id <> loser_id))),
CONSTRAINT tictactoe_winner_player_check CHECK (((winner_id IS NULL) OR ((winner_id = player_x_id) OR (winner_id = player_o_id)))),
CONSTRAINT tictactoe_games_pkey PRIMARY KEY (id)
);
CREATE INDEX tictactoe_games_loser_idx ON public.tictactoe_games USING btree (loser_id);
CREATE INDEX tictactoe_games_player_o_idx ON public.tictactoe_games USING btree (player_o_id);
CREATE INDEX tictactoe_games_player_x_idx ON public.tictactoe_games USING btree (player_x_id);
CREATE INDEX tictactoe_games_winner_idx ON public.tictactoe_games USING btree (winner_id);
CREATE TABLE public.user_fishing (
user_id bigint NOT NULL,
rod_level integer,
fish_caught bigint,
coins bigint,
CONSTRAINT user_fishing_pkey PRIMARY KEY (user_id)
);
CREATE TABLE public.wordbomb_custom_words (
word text NOT NULL,
added_by bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT wordbomb_custom_words_alpha CHECK ((word ~ '^[[:alpha:]]{2,}$'::text)),
CONSTRAINT wordbomb_custom_words_pkey PRIMARY KEY (word)
);
CREATE INDEX wordbomb_custom_words_added_by_idx ON public.wordbomb_custom_words USING btree (added_by, created_at DESC);
CREATE TABLE public.wordbomb_stats (
user_id bigint NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
losses bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT wordbomb_stats_losses_check CHECK ((losses >= 0)),
CONSTRAINT wordbomb_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT wordbomb_stats_pkey PRIMARY KEY (user_id)
);
CREATE INDEX wordbomb_stats_leaderboard_idx ON public.wordbomb_stats USING btree (wins DESC, losses, updated_at, user_id);
CREATE TABLE public.wordle_games (
id bigserial NOT NULL,
user_id bigint NOT NULL,
guild_id bigint,
channel_id bigint NOT NULL,
answer text NOT NULL,
solved boolean NOT NULL,
attempts smallint NOT NULL,
hard_mode boolean DEFAULT false NOT NULL,
colourblind_mode boolean DEFAULT false NOT NULL,
duration_seconds bigint DEFAULT 0 NOT NULL,
started_at timestamp with time zone NOT NULL,
finished_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT wordle_games_attempts_check CHECK (((attempts >= 0) AND (attempts <= 6))),
CONSTRAINT wordle_games_duration_seconds_check CHECK ((duration_seconds >= 0)),
CONSTRAINT wordle_games_pkey PRIMARY KEY (id)
);
CREATE INDEX wordle_games_guild_idx ON public.wordle_games USING btree (guild_id, finished_at DESC);
CREATE INDEX wordle_games_user_idx ON public.wordle_games USING btree (user_id, finished_at DESC);
CREATE TABLE public.wordle_stats (
user_id bigint NOT NULL,
wins bigint DEFAULT 0 NOT NULL,
losses bigint DEFAULT 0 NOT NULL,
total_playtime_seconds bigint DEFAULT 0 NOT NULL,
attempt_1 bigint DEFAULT 0 NOT NULL,
attempt_2 bigint DEFAULT 0 NOT NULL,
attempt_3 bigint DEFAULT 0 NOT NULL,
attempt_4 bigint DEFAULT 0 NOT NULL,
attempt_5 bigint DEFAULT 0 NOT NULL,
attempt_6 bigint DEFAULT 0 NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT wordle_stats_attempt_1_check CHECK ((attempt_1 >= 0)),
CONSTRAINT wordle_stats_attempt_2_check CHECK ((attempt_2 >= 0)),
CONSTRAINT wordle_stats_attempt_3_check CHECK ((attempt_3 >= 0)),
CONSTRAINT wordle_stats_attempt_4_check CHECK ((attempt_4 >= 0)),
CONSTRAINT wordle_stats_attempt_5_check CHECK ((attempt_5 >= 0)),
CONSTRAINT wordle_stats_attempt_6_check CHECK ((attempt_6 >= 0)),
CONSTRAINT wordle_stats_losses_check CHECK ((losses >= 0)),
CONSTRAINT wordle_stats_total_playtime_seconds_check CHECK ((total_playtime_seconds >= 0)),
CONSTRAINT wordle_stats_wins_check CHECK ((wins >= 0)),
CONSTRAINT wordle_stats_pkey PRIMARY KEY (user_id)
);
-- Notifications and Mudae
CREATE TABLE public.highlights (
user_id bigint NOT NULL,
guild_id bigint NOT NULL,
word text NOT NULL,
word_normalized text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT highlights_pkey PRIMARY KEY (user_id, guild_id, word_normalized)
);
CREATE INDEX highlights_guild_idx ON public.highlights USING btree (guild_id);
CREATE TABLE public.mudae_channels (
guild_id bigint NOT NULL,
channel_id bigint NOT NULL,
CONSTRAINT mudae_channels_pkey PRIMARY KEY (guild_id)