-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity-schema.sql
More file actions
1735 lines (1496 loc) · 53.3 KB
/
entity-schema.sql
File metadata and controls
1735 lines (1496 loc) · 53.3 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
create table avatar (
avatar_id bigint generated by default as identity,
master_id bigint not null,
user_id bigint not null,
nickname varchar(14) not null,
image_url varchar(255),
primary key (avatar_id)
);
create table avatar_master (
id bigint generated by default as identity,
default_image_url varchar(255) not null,
description varchar(255),
primary key (id)
);
create table avatar_post (
avatar_id bigint not null,
avatar_post_id bigint generated by default as identity,
created_at timestamp(6) not null,
like_count bigint,
updated_at timestamp(6) not null,
user_id bigint not null,
caption varchar(2000),
image_url varchar(255),
primary key (avatar_post_id)
);
create table bookmark (
avatar_post_id bigint,
bookmark_id bigint generated by default as identity,
created_at timestamp(6) not null,
user_id bigint not null,
target_type varchar(255),
primary key (bookmark_id)
);
create table comments (
avatar_post_id bigint,
created_at timestamp(6) not null,
diary_id bigint,
id bigint generated by default as identity,
updated_at timestamp(6) not null,
writer_id bigint not null,
content varchar(255) not null,
primary key (id)
);
create table daily_question_answer (
answered_date date not null,
id bigint generated by default as identity,
user_id bigint not null,
question varchar(500) not null,
answer varchar(255) not null check (answer in ('YES','NEUTRAL','NO')),
primary key (id),
unique (user_id, answered_date)
);
create table daily_keywords (
created_at timestamp(6),
keyword_date timestamp(6),
keyword_id bigint generated by default as identity,
keyword varchar(255),
primary key (keyword_id)
);
create table daily_mission_image (
id bigint generated by default as identity,
image_url varchar(255),
primary key (id)
);
create table daily_mission_master (
is_active boolean,
created_at timestamp(6),
mission_master_id bigint generated by default as identity,
reward_points bigint,
content varchar(255),
description varchar(255),
mission_type varchar(255) check (mission_type in ('PHOTO','QUIZ','DIARY')),
title varchar(255),
primary key (mission_master_id)
);
create table delivery (
created_at timestamp(6),
delivery_plant_id bigint not null,
id bigint generated by default as identity,
user_id bigint not null,
address varchar(255) not null,
address_detail varchar(255),
message varchar(255),
postal_code varchar(255) not null,
recipient_name varchar(255) not null,
recipient_phone varchar(255) not null,
primary key (id)
);
create table delivery_plant (
id bigint generated by default as identity,
image_url varchar(255),
name varchar(255),
primary key (id)
);
create table device_tokens (
created_at timestamp(6) not null,
id bigint generated by default as identity,
updated_at timestamp(6) not null,
user_id bigint not null,
token varchar(255) not null unique,
primary key (id)
);
create table diaries (
is_public boolean,
like_count integer,
created_at timestamp(6),
diary_id bigint generated by default as identity,
updated_at timestamp(6),
user_id bigint not null,
content TEXT not null,
keyword varchar(255),
title varchar(255) not null,
primary key (diary_id)
);
create table diary_image (
created_at timestamp(6),
diary_id bigint unique,
id bigint generated by default as identity,
user_id bigint not null,
image_url varchar(255) not null,
primary key (id)
);
create table feeds (
created_at timestamp(6) not null,
id bigint generated by default as identity,
user_id bigint not null,
content varchar(255) not null,
image_url varchar(255) not null,
primary key (id)
);
create table follows (
follower_id bigint not null,
following_id bigint not null,
id bigint generated by default as identity,
primary key (id)
);
create table friend_watering_log (
id bigint generated by default as identity,
water_giver_id bigint not null,
watered_at timestamp(6) not null,
watered_garden_id bigint not null,
primary key (id)
);
create table garden (
is_locked boolean not null,
slot_number integer not null,
sunlight_count integer not null,
water_count integer not null,
avatar_id bigint unique,
created_at timestamp(6) not null,
garden_background_id bigint,
id bigint generated by default as identity,
last_sunlight_received_at timestamp(6),
last_watered_by_friend_at timestamp(6),
last_watered_by_owner_at timestamp(6),
updated_at timestamp(6) not null,
user_id bigint not null,
primary key (id)
);
create table garden_background (
id bigint generated by default as identity,
image_url varchar(255) not null,
name varchar(255) not null,
primary key (id)
);
create table guestbooks (
created_at timestamp(6) not null,
id bigint generated by default as identity,
owner_id bigint not null,
writer_id bigint not null,
content varchar(500) not null,
primary key (id)
);
create table keyword (
created_at timestamp(6) not null,
keyword_id bigint generated by default as identity,
keyword varchar(255) not null,
primary key (keyword_id)
);
create table likes (
created_at timestamp(6) not null,
id bigint generated by default as identity,
target_id bigint not null,
user_id bigint not null,
target_type varchar(255) not null,
primary key (id),
constraint uk_likes_user_target unique (user_id, target_id, target_type)
);
create table notifications (
is_read boolean not null,
created_at timestamp(6) not null,
id bigint generated by default as identity,
user_id bigint not null,
content varchar(255) not null,
notification_type varchar(255) not null check (notification_type in ('FOLLOW','POLLEN','FEED_LIKE','DIARY_LIKE','AVATAR_POST_LIKE','FEED_COMMENT','GUESTBOOK','WATERING','SUNSHINE','DIARY_COMMENT','AVATAR_POST_COMMENT','WATERING_BY_FRIEND','POLLEN_AVAILABLE','REPORT_PROCESSED','SEED_DELIVERY')),
url varchar(255) not null,
primary key (id)
);
create table plant_masters (
growth_stages integer,
unlock_level integer,
created_at timestamp(6),
plant_master_id bigint generated by default as identity,
description varchar(255),
image_url varchar(255),
plant_name varchar(255),
plant_type varchar(255),
primary key (plant_master_id)
);
create table quiz (
quiz_type smallint check (quiz_type between 0 and 1),
answer_number bigint,
id bigint generated by default as identity,
mission_master_id bigint unique,
quiz_question varchar(255),
primary key (id)
);
create table quiz_options (
option_order integer,
quiz_id bigint,
quiz_option_id bigint generated by default as identity,
option_text varchar(255),
primary key (quiz_option_id)
);
create table real_quiz (
answer_number integer,
quiz_type smallint check (quiz_type between 0 and 1),
created_at timestamp(6),
id bigint generated by default as identity,
reward_point bigint,
answer_description varchar(255),
quiz_question varchar(255),
primary key (id)
);
create table real_quiz_option (
option_order integer,
quiz_id bigint,
quiz_option_id bigint generated by default as identity,
option_text varchar(255),
primary key (quiz_option_id)
);
create table refresh_tokens (
expires_at timestamp(6) not null,
user_uuid uuid not null,
token varchar(512) not null,
device_id varchar(255),
primary key (token)
);
create table report_reason (
is_active boolean,
created_at timestamp(6),
id bigint generated by default as identity,
reason_text varchar(255),
reason_type varchar(255) check (reason_type in ('SPAM','ABUSIVE_LANGUAGE','ILLEGAL_CONTENT')),
primary key (id)
);
create table reports (
target_type smallint check (target_type between 0 and 3),
created_at timestamp(6),
report_id bigint generated by default as identity,
report_reason_id bigint,
reported_user_id bigint,
reviewed_at timestamp(6),
reviewer_id bigint,
target_id bigint,
user_id bigint,
additional_comment varchar(255),
report_status varchar(255) check (report_status in ('PENDING','REVIEWED','RESOLVED','DISMISSED')),
primary key (report_id)
);
create table user_block (
blocked_user_id bigint not null,
blocker_user_id bigint not null,
id bigint generated by default as identity,
created_at bytea not null,
primary key (id)
);
create table user_daily_mission (
is_completed boolean not null,
completed_at timestamp(6),
created_at timestamp(6) not null,
mission_master_id bigint not null,
score bigint,
user_id bigint not null,
user_mission_id bigint generated by default as identity,
mission_type varchar(31) not null,
primary key (user_mission_id)
);
create table user_image_mission (
image_id bigint unique,
user_mission_id bigint not null,
primary key (user_mission_id)
);
create table user_quiz (
is_completed boolean,
created_at timestamp(6),
id bigint generated by default as identity,
real_quiz_id bigint,
user_id bigint,
primary key (id)
);
create table user_quiz_mission (
is_quiz_correct boolean,
selected_answer_number integer,
quiz_answered_at timestamp(6),
selected_option_id bigint,
user_mission_id bigint not null,
primary key (user_mission_id)
);
create table users (
notification_enabled boolean,
unlockable_garden_count integer,
created_at timestamp(6) not null,
updated_at timestamp(6) not null,
user_id bigint generated by default as identity,
uuid uuid unique,
email varchar(255),
nickname varchar(255) not null,
password_hash varchar(255),
profile_image_url varchar(255),
role varchar(255) not null check (role in ('USER','ADMIN')),
status varchar(255) check (status in ('ACTIVE','INACTIVE','BANNED')),
primary key (user_id)
);
create table wish_tree (
id bigint generated by default as identity,
points bigint not null,
user_id bigint not null unique,
stage varchar(255) not null check (stage in ('SPROUT','FLOWER','FRUIT','TREE','FINAL')),
primary key (id)
);
alter table if exists avatar
add constraint FK3c2l6kijnmofergvy6qp7r7dq
foreign key (master_id)
references avatar_master;
alter table if exists avatar
add constraint FK68gmcdk6o7ydfrnshsi8lcc4f
foreign key (user_id)
references users;
alter table if exists avatar_post
add constraint FK4lj62tve51qkmveifcgiyd61t
foreign key (avatar_id)
references avatar;
alter table if exists avatar_post
add constraint FKf3tpjurry7x3verpyt097rxg1
foreign key (user_id)
references users;
alter table if exists bookmark
add constraint FKam7hblfd23ngg912do3p9ol3g
foreign key (avatar_post_id)
references avatar_post;
alter table if exists bookmark
add constraint FKo4vbqvq5trl11d85bqu5kl870
foreign key (user_id)
references users;
alter table if exists comments
add constraint FKmhet14lostk1toar22sdlbgra
foreign key (avatar_post_id)
references avatar_post;
alter table if exists comments
add constraint FKbkc4yj8etxgyundtmb3bkx3vu
foreign key (diary_id)
references diaries;
alter table if exists comments
add constraint FKtdvhgjfwg764l2sltaixna6ku
foreign key (writer_id)
references users;
alter table if exists daily_question_answer
add constraint FKddbrdk4bc99liojdowwhnmtsi
foreign key (user_id)
references users;
alter table if exists delivery
add constraint FKjfuxotumr8tlct7fe25x3hss0
foreign key (delivery_plant_id)
references delivery_plant;
alter table if exists delivery
add constraint FKl82fx83nyp1om9iejsfba9n9a
foreign key (user_id)
references users;
alter table if exists device_tokens
add constraint FKhc7d11bnr8x9gs5biohdhnx1c
foreign key (user_id)
references users;
alter table if exists diaries
add constraint FKki7hoimuu910cy56y2695to5e
foreign key (user_id)
references users;
alter table if exists diary_image
add constraint FK43gy512wuvx0yeo9h3en50sp2
foreign key (diary_id)
references diaries;
alter table if exists diary_image
add constraint FKhiyhltwhd6kyqr3b6qs530d07
foreign key (user_id)
references users;
alter table if exists feeds
add constraint FKa4nmt7wyx9clm9okj61dgd1tw
foreign key (user_id)
references users;
alter table if exists follows
add constraint FKqnkw0cwwh6572nyhvdjqlr163
foreign key (follower_id)
references users;
alter table if exists follows
add constraint FKonkdkae2ngtx70jqhsh7ol6uq
foreign key (following_id)
references users;
alter table if exists friend_watering_log
add constraint FKrm7eymmcp08o424doqx16jlnu
foreign key (water_giver_id)
references users;
alter table if exists friend_watering_log
add constraint FK27r61mh7led2ko3qi7wm0fms7
foreign key (watered_garden_id)
references garden;
alter table if exists garden
add constraint FKb1go2jeyl895h1cvkqttei3kw
foreign key (avatar_id)
references avatar;
alter table if exists garden
add constraint FK644fb7lhv1fj8kdlk022bvjk6
foreign key (garden_background_id)
references garden_background;
alter table if exists garden
add constraint FKj9rtqa96sju3bis7te63ini8v
foreign key (user_id)
references users;
alter table if exists guestbooks
add constraint FKe1jvpcykvu08tnqrc6n7q2dk0
foreign key (owner_id)
references users;
alter table if exists guestbooks
add constraint FKlvhrhe3s5xgyhqj11id591x8y
foreign key (writer_id)
references users;
alter table if exists likes
add constraint FKnvx9seeqqyy71bij291pwiwrg
foreign key (user_id)
references users;
alter table if exists notifications
add constraint FK9y21adhxn0ayjhfocscqox7bh
foreign key (user_id)
references users
on delete cascade;
alter table if exists quiz
add constraint FKov1ru4df77adnk6bn4kt7cgor
foreign key (mission_master_id)
references daily_mission_master;
alter table if exists quiz_options
add constraint FKsx28j7orq6asg17veq9nblhw8
foreign key (quiz_id)
references quiz;
alter table if exists real_quiz_option
add constraint FKou16wmevk1dkyxrj14agak0p8
foreign key (quiz_id)
references real_quiz;
alter table if exists reports
add constraint FKnm6ovge58ieru2ll8kjqsd644
foreign key (report_reason_id)
references report_reason;
alter table if exists reports
add constraint FK2o32rer9hfweeylg7x8ut8rj2
foreign key (user_id)
references users;
alter table if exists user_block
add constraint FKfox9qnf21ck8ntnutixv7q1rd
foreign key (blocked_user_id)
references users;
alter table if exists user_block
add constraint FKn7evvw5g73onq7ln4wu1o77ae
foreign key (blocker_user_id)
references users;
alter table if exists user_daily_mission
add constraint FKexixrmrj4nkus39q5kejf3la9
foreign key (mission_master_id)
references daily_mission_master;
alter table if exists user_daily_mission
add constraint FK5tduacjgiplxsjg5s7876dfgw
foreign key (user_id)
references users;
alter table if exists user_image_mission
add constraint FKn7cddfjesmawoufmjp7fqecmu
foreign key (image_id)
references daily_mission_image;
alter table if exists user_image_mission
add constraint FK7xixhbr324hei1390bru6ekum
foreign key (user_mission_id)
references user_daily_mission;
alter table if exists user_quiz
add constraint FKcl7f9baha7rk3f4djeyeo4fxu
foreign key (real_quiz_id)
references real_quiz;
alter table if exists user_quiz
add constraint FKeuoc6oyjhqpnqf4iufs0j6t8b
foreign key (user_id)
references users;
alter table if exists user_quiz_mission
add constraint FK17lgcr0k7m9xe9u3cp2s4o6c
foreign key (user_mission_id)
references user_daily_mission;
alter table if exists wish_tree
add constraint FK39ob4lcul5wj1fd4wcxmc58ot
foreign key (user_id)
references users;
create table avatar (
avatar_id bigint generated by default as identity,
master_id bigint not null,
user_id bigint not null,
nickname varchar(14) not null,
image_url varchar(255),
primary key (avatar_id)
);
create table avatar_post_likes (
avatar_post_id bigint not null,
created_at timestamp(6) not null,
id bigint generated by default as identity,
user_id bigint not null,
primary key (id),
constraint uk_avatar_post_like unique (user_id, avatar_post_id)
);
create table avatar_master (
id bigint generated by default as identity,
default_image_url varchar(255) not null,
description varchar(255),
primary key (id)
);
create table avatar_post (
avatar_id bigint not null,
avatar_post_id bigint generated by default as identity,
created_at timestamp(6) not null,
like_count bigint,
updated_at timestamp(6) not null,
user_id bigint not null,
caption varchar(2000),
image_url varchar(255),
primary key (avatar_post_id)
);
create table bookmark (
avatar_post_id bigint,
bookmark_id bigint generated by default as identity,
created_at timestamp(6) not null,
user_id bigint not null,
target_type varchar(255),
primary key (bookmark_id)
);
create table comments (
avatar_post_id bigint,
created_at timestamp(6) not null,
diary_id bigint,
id bigint generated by default as identity,
updated_at timestamp(6) not null,
writer_id bigint not null,
content varchar(255) not null,
primary key (id)
);
create table daily_question_answer (
answered_date date not null,
id bigint generated by default as identity,
user_id bigint not null,
question varchar(500) not null,
answer varchar(255) not null check (answer in ('YES','NEUTRAL','NO')),
primary key (id),
unique (user_id, answered_date)
);
create table daily_keywords (
created_at timestamp(6),
keyword_date timestamp(6),
keyword_id bigint generated by default as identity,
keyword varchar(255),
primary key (keyword_id)
);
create table daily_mission_master (
is_active boolean,
created_at timestamp(6),
mission_master_id bigint generated by default as identity,
reward_points bigint,
content varchar(255),
description varchar(255),
mission_type varchar(255) check (mission_type in ('PHOTO','QUIZ','DIARY')),
title varchar(255),
primary key (mission_master_id)
);
create table delivery (
created_at timestamp(6),
delivery_plant_id bigint not null,
id bigint generated by default as identity,
user_id bigint not null,
address varchar(255) not null,
address_detail varchar(255),
message varchar(255),
postal_code varchar(255) not null,
recipient_name varchar(255) not null,
recipient_phone varchar(255) not null,
primary key (id)
);
create table delivery_plant (
id bigint generated by default as identity,
image_url varchar(255),
name varchar(255),
primary key (id)
);
create table device_tokens (
created_at timestamp(6) not null,
id bigint generated by default as identity,
updated_at timestamp(6) not null,
user_id bigint not null,
token varchar(255) not null unique,
primary key (id)
);
create table diaries (
is_public boolean,
like_count integer,
created_at timestamp(6),
diary_id bigint generated by default as identity,
updated_at timestamp(6),
user_id bigint not null,
content TEXT not null,
keyword varchar(255),
title varchar(255) not null,
primary key (diary_id)
);
create table diary_likes (
created_at timestamp(6) not null,
diary_id bigint not null,
id bigint generated by default as identity,
user_id bigint not null,
primary key (id),
constraint uk_diary_like unique (user_id, diary_id)
);
create table diary_image (
created_at timestamp(6),
diary_id bigint unique,
id bigint generated by default as identity,
user_id bigint not null,
image_url varchar(255) not null,
primary key (id)
);
create table feeds (
created_at timestamp(6) not null,
id bigint generated by default as identity,
user_id bigint not null,
content varchar(255) not null,
image_url varchar(255) not null,
primary key (id)
);
create table follows (
follower_id bigint not null,
following_id bigint not null,
id bigint generated by default as identity,
primary key (id)
);
create table friend_watering_log (
id bigint generated by default as identity,
water_giver_id bigint not null,
watered_at timestamp(6) not null,
watered_garden_id bigint not null,
primary key (id)
);
create table garden (
is_locked boolean not null,
slot_number integer not null,
sunlight_count integer not null,
water_count integer not null,
avatar_id bigint unique,
created_at timestamp(6) not null,
garden_background_id bigint,
id bigint generated by default as identity,
last_sunlight_received_at timestamp(6),
last_watered_by_friend_at timestamp(6),
last_watered_by_owner_at timestamp(6),
updated_at timestamp(6) not null,
user_id bigint not null,
primary key (id)
);
create table garden_background (
id bigint generated by default as identity,
image_url varchar(255) not null,
name varchar(255) not null,
primary key (id)
);
create table guestbooks (
created_at timestamp(6) not null,
id bigint generated by default as identity,
owner_id bigint not null,
writer_id bigint not null,
content varchar(500) not null,
primary key (id)
);
create table keyword (
created_at timestamp(6) not null,
keyword_id bigint generated by default as identity,
keyword varchar(255) not null,
primary key (keyword_id)
);
create table notifications (
is_read boolean not null,
created_at timestamp(6) not null,
id bigint generated by default as identity,
user_id bigint not null,
content varchar(255) not null,
notification_type varchar(255) not null check (notification_type in ('FOLLOW','POLLEN','FEED_LIKE','DIARY_LIKE','AVATAR_POST_LIKE','FEED_COMMENT','GUESTBOOK','WATERING','SUNSHINE','DIARY_COMMENT','AVATAR_POST_COMMENT','WATERING_BY_FRIEND','POLLEN_AVAILABLE','REPORT_PROCESSED','SEED_DELIVERY')),
url varchar(255) not null,
primary key (id)
);
create table plant_masters (
growth_stages integer,
unlock_level integer,
created_at timestamp(6),
plant_master_id bigint generated by default as identity,
description varchar(255),
image_url varchar(255),
plant_name varchar(255),
plant_type varchar(255),
primary key (plant_master_id)
);
create table quiz (
quiz_type smallint check (quiz_type between 0 and 1),
answer_number bigint,
id bigint generated by default as identity,
mission_master_id bigint unique,
quiz_question varchar(255),
primary key (id)
);
create table quiz_options (
option_order integer,
quiz_id bigint,
quiz_option_id bigint generated by default as identity,
option_text varchar(255),
primary key (quiz_option_id)
);
create table real_quiz (
answer_number integer,
quiz_type smallint check (quiz_type between 0 and 1),
created_at timestamp(6),
id bigint generated by default as identity,
reward_point bigint,
answer_description varchar(255),
quiz_question varchar(255),
primary key (id)
);
create table real_quiz_option (
option_order integer,
quiz_id bigint,
quiz_option_id bigint generated by default as identity,
option_text varchar(255),
primary key (quiz_option_id)
);
create table refresh_tokens (
expires_at timestamp(6) not null,
user_uuid uuid not null,
token varchar(512) not null,
device_id varchar(255),
primary key (token)
);
create table report_reason (
is_active boolean,
created_at timestamp(6),
id bigint generated by default as identity,
reason_text varchar(255),
reason_type varchar(255) check (reason_type in ('SPAM','ABUSIVE_LANGUAGE','ILLEGAL_CONTENT')),
primary key (id)
);
create table reports (
target_type smallint check (target_type between 0 and 3),
created_at timestamp(6),
report_id bigint generated by default as identity,
report_reason_id bigint,
reported_user_id bigint,
reviewed_at timestamp(6),
reviewer_id bigint,
target_id bigint,
user_id bigint,
additional_comment varchar(255),
report_status varchar(255) check (report_status in ('PENDING','REVIEWED','RESOLVED','DISMISSED')),
primary key (report_id)
);
create table user_block (
blocked_user_id bigint not null,
blocker_user_id bigint not null,
id bigint generated by default as identity,
created_at bytea not null,
primary key (id)
);
create table user_daily_mission (
is_completed boolean not null,
is_quiz_correct boolean,
selected_answer_number integer,
completed_at timestamp(6),
created_at timestamp(6) not null,
mission_master_id bigint not null,
score bigint,
user_id bigint not null,
user_mission_id bigint generated by default as identity,
mission_type varchar(31) not null,
submission_image_url varchar(2048),
primary key (user_mission_id)
);
create table user_quiz (
is_completed boolean,
created_at timestamp(6),
id bigint generated by default as identity,
real_quiz_id bigint,
user_id bigint,
primary key (id)
);
create table users (
notification_enabled boolean,
unlockable_garden_count integer,
created_at timestamp(6) not null,
updated_at timestamp(6) not null,
user_id bigint generated by default as identity,
uuid uuid unique,
email varchar(255),
nickname varchar(255) not null,
password_hash varchar(255),
profile_image_url varchar(255),
role varchar(255) not null check (role in ('USER','ADMIN')),
status varchar(255) check (status in ('ACTIVE','INACTIVE','BANNED')),
primary key (user_id)
);
create table wish_tree (
id bigint generated by default as identity,
points bigint not null,
user_id bigint not null unique,
stage varchar(255) not null check (stage in ('SPROUT','FLOWER','FRUIT','TREE','FINAL')),
primary key (id)
);
alter table if exists avatar
add constraint FK3c2l6kijnmofergvy6qp7r7dq
foreign key (master_id)
references avatar_master;
alter table if exists avatar
add constraint FK68gmcdk6o7ydfrnshsi8lcc4f
foreign key (user_id)
references users;
alter table if exists avatar_post_likes
add constraint FK2aeciw1jg6cys34cxqdw75ouu
foreign key (avatar_post_id)
references avatar_post;
alter table if exists avatar_post_likes
add constraint FKdigvfto4vofxhb85u9rf2db3d
foreign key (user_id)
references users;
alter table if exists avatar_post
add constraint FK4lj62tve51qkmveifcgiyd61t
foreign key (avatar_id)
references avatar;
alter table if exists avatar_post
add constraint FKf3tpjurry7x3verpyt097rxg1
foreign key (user_id)
references users;
alter table if exists bookmark
add constraint FKam7hblfd23ngg912do3p9ol3g
foreign key (avatar_post_id)
references avatar_post;
alter table if exists bookmark
add constraint FKo4vbqvq5trl11d85bqu5kl870
foreign key (user_id)
references users;
alter table if exists comments
add constraint FKmhet14lostk1toar22sdlbgra
foreign key (avatar_post_id)
references avatar_post;
alter table if exists comments
add constraint FKbkc4yj8etxgyundtmb3bkx3vu
foreign key (diary_id)
references diaries;
alter table if exists comments
add constraint FKtdvhgjfwg764l2sltaixna6ku
foreign key (writer_id)
references users;