/
CreateTables.sql
4076 lines (3699 loc) · 171 KB
/
CreateTables.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
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
\set ON_ERROR_STOP 1
BEGIN;
CREATE TABLE alternative_release ( -- replicate
id SERIAL, -- PK
gid UUID NOT NULL,
release INTEGER NOT NULL, -- references release.id
name VARCHAR,
artist_credit INTEGER, -- references artist_credit.id
type INTEGER NOT NULL, -- references alternative_release_type.id
language INTEGER NOT NULL, -- references language.id
script INTEGER NOT NULL, -- references script.id
comment VARCHAR(255) NOT NULL DEFAULT ''
CHECK (name != '')
);
CREATE TABLE alternative_release_type ( -- replicate
id SERIAL, -- PK
name TEXT NOT NULL,
parent INTEGER, -- references alternative_release_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid UUID NOT NULL
);
CREATE TABLE alternative_medium ( -- replicate
id SERIAL, -- PK
medium INTEGER NOT NULL, -- FK, references medium.id
alternative_release INTEGER NOT NULL, -- references alternative_release.id
name VARCHAR
CHECK (name != '')
);
CREATE TABLE alternative_track ( -- replicate
id SERIAL, -- PK
name VARCHAR,
artist_credit INTEGER, -- references artist_credit.id
ref_count INTEGER NOT NULL DEFAULT 0
CHECK (name != '' AND (name IS NOT NULL OR artist_credit IS NOT NULL))
);
CREATE TABLE alternative_medium_track ( -- replicate
alternative_medium INTEGER NOT NULL, -- PK, references alternative_medium.id
track INTEGER NOT NULL, -- PK, references track.id
alternative_track INTEGER NOT NULL -- references alternative_track.id
);
CREATE TABLE annotation ( -- replicate (verbose)
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
text TEXT,
changelog VARCHAR(255),
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE application
(
id SERIAL,
owner INTEGER NOT NULL, -- references editor.id
name TEXT NOT NULL,
oauth_id TEXT NOT NULL,
oauth_secret TEXT NOT NULL,
oauth_redirect_uri TEXT
);
CREATE TABLE area_type ( -- replicate
id SERIAL, -- PK
name VARCHAR(255) NOT NULL,
parent INTEGER, -- references area_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE area ( -- replicate (verbose)
id SERIAL, -- PK
gid uuid NOT NULL,
name VARCHAR NOT NULL,
type INTEGER, -- references area_type.id
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
ended BOOLEAN NOT NULL DEFAULT FALSE
CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR
end_date_day IS NOT NULL) AND
ended = TRUE
) OR (
-- Otherwise, all end date fields must be null
(end_date_year IS NULL AND
end_date_month IS NULL AND
end_date_day IS NULL)
)
),
comment VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE area_gid_redirect ( -- replicate (verbose)
gid UUID NOT NULL, -- PK
new_id INTEGER NOT NULL, -- references area.id
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE area_alias_type ( -- replicate
id SERIAL, -- PK,
name TEXT NOT NULL,
parent INTEGER, -- references area_alias_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE area_alias ( -- replicate (verbose)
id SERIAL, --PK
area INTEGER NOT NULL, -- references area.id
name VARCHAR NOT NULL,
locale TEXT,
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
type INTEGER, -- references area_alias_type.id
sort_name VARCHAR NOT NULL,
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
primary_for_locale BOOLEAN NOT NULL DEFAULT false,
ended BOOLEAN NOT NULL DEFAULT FALSE
CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR
end_date_day IS NOT NULL) AND
ended = TRUE
) OR (
-- Otherwise, all end date fields must be null
(end_date_year IS NULL AND
end_date_month IS NULL AND
end_date_day IS NULL)
)
),
CONSTRAINT primary_check
CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)));
CREATE TABLE area_annotation ( -- replicate (verbose)
area INTEGER NOT NULL, -- PK, references area.id
annotation INTEGER NOT NULL -- PK, references annotation.id
);
CREATE TABLE area_attribute_type ( -- replicate (verbose)
id SERIAL, -- PK
name VARCHAR(255) NOT NULL,
comment VARCHAR(255) NOT NULL DEFAULT '',
free_text BOOLEAN NOT NULL,
parent INTEGER, -- references area_attribute_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE area_attribute_type_allowed_value ( -- replicate (verbose)
id SERIAL, -- PK
area_attribute_type INTEGER NOT NULL, -- references area_attribute_type.id
value TEXT,
parent INTEGER, -- references area_attribute_type_allowed_value.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE area_attribute ( -- replicate (verbose)
id SERIAL, -- PK
area INTEGER NOT NULL, -- references area.id
area_attribute_type INTEGER NOT NULL, -- references area_attribute_type.id
area_attribute_type_allowed_value INTEGER, -- references area_attribute_type_allowed_value.id
area_attribute_text TEXT
CHECK (
(area_attribute_type_allowed_value IS NULL AND area_attribute_text IS NOT NULL)
OR
(area_attribute_type_allowed_value IS NOT NULL AND area_attribute_text IS NULL)
)
);
CREATE TABLE area_containment (
descendant INTEGER NOT NULL, -- PK, references area.id
parent INTEGER NOT NULL, -- PK, references area.id
depth SMALLINT NOT NULL
);
CREATE TABLE area_tag ( -- replicate (verbose)
area INTEGER NOT NULL, -- PK, references area.id
tag INTEGER NOT NULL, -- PK, references tag.id
count INTEGER NOT NULL,
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE area_tag_raw (
area INTEGER NOT NULL, -- PK, references area.id
editor INTEGER NOT NULL, -- PK, references editor.id
tag INTEGER NOT NULL, -- PK, references tag.id
is_upvote BOOLEAN NOT NULL DEFAULT TRUE
);
CREATE TABLE artist ( -- replicate (verbose)
id SERIAL,
gid UUID NOT NULL,
name VARCHAR NOT NULL,
sort_name VARCHAR NOT NULL,
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
type INTEGER, -- references artist_type.id
area INTEGER, -- references area.id
gender INTEGER, -- references gender.id
comment VARCHAR(255) NOT NULL DEFAULT '',
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
ended BOOLEAN NOT NULL DEFAULT FALSE
CONSTRAINT artist_ended_check CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR
end_date_day IS NOT NULL) AND
ended = TRUE
) OR (
-- Otherwise, all end date fields must be null
(end_date_year IS NULL AND
end_date_month IS NULL AND
end_date_day IS NULL)
)
),
begin_area INTEGER, -- references area.id
end_area INTEGER -- references area.id
);
CREATE TABLE artist_alias_type ( -- replicate
id SERIAL,
name TEXT NOT NULL,
parent INTEGER, -- references artist_alias_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE artist_alias ( -- replicate (verbose)
id SERIAL,
artist INTEGER NOT NULL, -- references artist.id
name VARCHAR NOT NULL,
locale TEXT,
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
type INTEGER, -- references artist_alias_type.id
sort_name VARCHAR NOT NULL,
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
primary_for_locale BOOLEAN NOT NULL DEFAULT false,
ended BOOLEAN NOT NULL DEFAULT FALSE
CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR
end_date_day IS NOT NULL) AND
ended = TRUE
) OR (
-- Otherwise, all end date fields must be null
(end_date_year IS NULL AND
end_date_month IS NULL AND
end_date_day IS NULL)
)
),
CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)),
CONSTRAINT search_hints_are_empty
CHECK (
(type <> 3) OR (
type = 3 AND sort_name = name AND
begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND
end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND
primary_for_locale IS FALSE AND locale IS NULL
)
)
);
CREATE TABLE artist_annotation ( -- replicate (verbose)
artist INTEGER NOT NULL, -- PK, references artist.id
annotation INTEGER NOT NULL -- PK, references annotation.id
);
CREATE TABLE artist_attribute_type ( -- replicate (verbose)
id SERIAL, -- PK
name VARCHAR(255) NOT NULL,
comment VARCHAR(255) NOT NULL DEFAULT '',
free_text BOOLEAN NOT NULL,
parent INTEGER, -- references artist_attribute_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE artist_attribute_type_allowed_value ( -- replicate (verbose)
id SERIAL, -- PK
artist_attribute_type INTEGER NOT NULL, -- references artist_attribute_type.id
value TEXT,
parent INTEGER, -- references artist_attribute_type_allowed_value.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE artist_attribute ( -- replicate (verbose)
id SERIAL, -- PK
artist INTEGER NOT NULL, -- references artist.id
artist_attribute_type INTEGER NOT NULL, -- references artist_attribute_type.id
artist_attribute_type_allowed_value INTEGER, -- references artist_attribute_type_allowed_value.id
artist_attribute_text TEXT
CHECK (
(artist_attribute_type_allowed_value IS NULL AND artist_attribute_text IS NOT NULL)
OR
(artist_attribute_type_allowed_value IS NOT NULL AND artist_attribute_text IS NULL)
)
);
CREATE TABLE artist_ipi ( -- replicate (verbose)
artist INTEGER NOT NULL, -- PK, references artist.id
ipi CHAR(11) NOT NULL CHECK (ipi ~ E'^\\d{11}$'), -- PK
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE artist_isni ( -- replicate (verbose)
artist INTEGER NOT NULL, -- PK, references artist.id
isni CHAR(16) NOT NULL CHECK (isni ~ E'^\\d{15}[\\dX]$'), -- PK
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE artist_meta ( -- replicate
id INTEGER NOT NULL, -- PK, references artist.id CASCADE
rating SMALLINT CHECK (rating >= 0 AND rating <= 100),
rating_count INTEGER
);
CREATE TABLE artist_tag ( -- replicate (verbose)
artist INTEGER NOT NULL, -- PK, references artist.id
tag INTEGER NOT NULL, -- PK, references tag.id
count INTEGER NOT NULL,
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE artist_rating_raw
(
artist INTEGER NOT NULL, -- PK, references artist.id
editor INTEGER NOT NULL, -- PK, references editor.id
rating SMALLINT NOT NULL CHECK (rating >= 0 AND rating <= 100)
);
CREATE TABLE artist_tag_raw
(
artist INTEGER NOT NULL, -- PK, references artist.id
editor INTEGER NOT NULL, -- PK, references editor.id
tag INTEGER NOT NULL, -- PK, references tag.id
is_upvote BOOLEAN NOT NULL DEFAULT TRUE
);
CREATE TABLE artist_credit ( -- replicate
id SERIAL,
name VARCHAR NOT NULL,
artist_count SMALLINT NOT NULL,
ref_count INTEGER DEFAULT 0,
created TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
gid UUID NOT NULL
);
CREATE TABLE artist_credit_gid_redirect ( -- replicate (verbose)
gid UUID NOT NULL, -- PK
new_id INTEGER NOT NULL, -- references artist_credit.id
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE artist_credit_name ( -- replicate (verbose)
artist_credit INTEGER NOT NULL, -- PK, references artist_credit.id CASCADE
position SMALLINT NOT NULL, -- PK
artist INTEGER NOT NULL, -- references artist.id CASCADE
name VARCHAR NOT NULL,
join_phrase TEXT NOT NULL DEFAULT ''
);
CREATE TABLE artist_gid_redirect ( -- replicate (verbose)
gid UUID NOT NULL, -- PK
new_id INTEGER NOT NULL, -- references artist.id
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE artist_type ( -- replicate
id SERIAL,
name VARCHAR(255) NOT NULL,
parent INTEGER, -- references artist_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE artist_release (
-- `is_track_artist` is TRUE only if the artist came from a track
-- AC and does not also appear in the release AC. Track artists
-- that appear in the release AC are not stored.
is_track_artist BOOLEAN NOT NULL,
artist INTEGER NOT NULL, -- references artist.id, CASCADE
first_release_date INTEGER,
catalog_numbers TEXT[],
country_code CHAR(2),
barcode BIGINT,
-- Prior to adding these materialized tables, we'd order releases
-- by name only if all other attributes where equal. It's not too
-- common that an artist will have tons of releases with no dates,
-- catalog numbers, countries, or barcodes (though it can be seen
-- on some big composers). As a compromise between dropping the
-- name sorting and having to store the entire name here (which,
-- as a reminder, is duplicated for every artist on the release),
-- we only store the first character of the name for sorting.
sort_character CHAR(1) COLLATE musicbrainz NOT NULL,
release INTEGER NOT NULL -- references release.id, CASCADE
) PARTITION BY LIST (is_track_artist);
CREATE TABLE artist_release_nonva
PARTITION OF artist_release FOR VALUES IN (FALSE);
CREATE TABLE artist_release_va
PARTITION OF artist_release FOR VALUES IN (TRUE);
-- The set of triggers keeping the `artist_release` table up-to-date
-- don't update the table directly. The query to do that for a particular
-- release can be moderately heavy if there are a lot of tracks, so it
-- would degrade performance if identical updates to the same release
-- were triggered many times in the same transaction (which is very
-- easy to trigger when adding, editing, or removing tracks). The
-- strategy we use is to instead push release IDs that need updating
-- to the `artist_release_pending_update` table, and perform the
-- actual updates in a DEFERRED trigger at the end of the transaction.
-- (For where this happens, see the apply_*_pending_updates functions.)
CREATE TABLE artist_release_pending_update (
release INTEGER NOT NULL
);
CREATE TABLE artist_release_group (
-- See comment for `artist_release.is_track_artist`.
is_track_artist BOOLEAN NOT NULL,
artist INTEGER NOT NULL, -- references artist.id, CASCADE
unofficial BOOLEAN NOT NULL,
primary_type SMALLINT,
secondary_types SMALLINT[],
first_release_date INTEGER,
-- See comment for `artist_release.sort_character`.
sort_character CHAR(1) COLLATE musicbrainz NOT NULL,
release_group INTEGER NOT NULL -- references release_group.id, CASCADE
) PARTITION BY LIST (is_track_artist);
CREATE TABLE artist_release_group_nonva
PARTITION OF artist_release_group FOR VALUES IN (FALSE);
CREATE TABLE artist_release_group_va
PARTITION OF artist_release_group FOR VALUES IN (TRUE);
-- Please see the comment above `artist_release_pending_update`
-- (the same idea applies).
CREATE TABLE artist_release_group_pending_update (
release_group INTEGER NOT NULL
);
CREATE TABLE autoeditor_election
(
id SERIAL,
candidate INTEGER NOT NULL, -- references editor.id
proposer INTEGER NOT NULL, -- references editor.id
seconder_1 INTEGER, -- references editor.id
seconder_2 INTEGER, -- references editor.id
status INTEGER NOT NULL DEFAULT 1
CHECK (status IN (1,2,3,4,5,6)),
-- 1 : has proposer
-- 2 : has seconder_1
-- 3 : has seconder_2 (voting open)
-- 4 : accepted!
-- 5 : rejected
-- 6 : cancelled (by proposer)
yes_votes INTEGER NOT NULL DEFAULT 0,
no_votes INTEGER NOT NULL DEFAULT 0,
propose_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
open_time TIMESTAMP WITH TIME ZONE,
close_time TIMESTAMP WITH TIME ZONE
);
CREATE TABLE autoeditor_election_vote
(
id SERIAL,
autoeditor_election INTEGER NOT NULL, -- references autoeditor_election.id
voter INTEGER NOT NULL, -- references editor.id
vote INTEGER NOT NULL CHECK (vote IN (-1,0,1)),
vote_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE TABLE cdtoc ( -- replicate
id SERIAL,
discid CHAR(28) NOT NULL,
freedb_id CHAR(8) NOT NULL,
track_count INTEGER NOT NULL,
leadout_offset INTEGER NOT NULL,
track_offset INTEGER[] NOT NULL,
degraded BOOLEAN NOT NULL DEFAULT FALSE,
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE cdtoc_raw ( -- replicate
id SERIAL, -- PK
release INTEGER NOT NULL, -- references release_raw.id
discid CHAR(28) NOT NULL,
track_count INTEGER NOT NULL,
leadout_offset INTEGER NOT NULL,
track_offset INTEGER[] NOT NULL
);
CREATE TABLE country_area ( -- replicate (verbose)
area INTEGER -- PK, references area.id
);
CREATE TABLE deleted_entity (
gid UUID NOT NULL, -- PK
data JSONB NOT NULL,
deleted_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE edit
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
type SMALLINT NOT NULL,
status SMALLINT NOT NULL,
autoedit SMALLINT NOT NULL DEFAULT 0,
open_time TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
close_time TIMESTAMP WITH TIME ZONE,
expire_time TIMESTAMP WITH TIME ZONE NOT NULL,
language INTEGER, -- references language.id
quality SMALLINT NOT NULL DEFAULT 1
);
CREATE TABLE edit_data
(
edit INTEGER NOT NULL, -- PK, references edit.id
data JSONB NOT NULL
);
CREATE TABLE edit_note
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
edit INTEGER NOT NULL, -- references edit.id
text TEXT NOT NULL,
post_time TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE edit_note_recipient (
recipient INTEGER NOT NULL, -- PK, references editor.id
edit_note INTEGER NOT NULL -- PK, references edit_note.id
);
CREATE TABLE edit_area
(
edit INTEGER NOT NULL, -- PK, references edit.id
area INTEGER NOT NULL -- PK, references area.id CASCADE
);
CREATE TABLE edit_artist
(
edit INTEGER NOT NULL, -- PK, references edit.id
artist INTEGER NOT NULL, -- PK, references artist.id CASCADE
status SMALLINT NOT NULL -- materialized from edit.status
);
CREATE TABLE edit_event
(
edit INTEGER NOT NULL, -- PK, references edit.id
event INTEGER NOT NULL -- PK, references event.id CASCADE
);
CREATE TABLE edit_genre
(
edit INTEGER NOT NULL, -- PK, references edit.id
genre INTEGER NOT NULL -- PK, references genre.id CASCADE
);
CREATE TABLE edit_instrument
(
edit INTEGER NOT NULL, -- PK, references edit.id
instrument INTEGER NOT NULL -- PK, references instrument.id CASCADE
);
CREATE TABLE edit_label
(
edit INTEGER NOT NULL, -- PK, references edit.id
label INTEGER NOT NULL, -- PK, references label.id CASCADE
status SMALLINT NOT NULL -- materialized from edit.status
);
CREATE TABLE edit_mood
(
edit INTEGER NOT NULL, -- PK, references edit.id
mood INTEGER NOT NULL -- PK, references mood.id CASCADE
);
CREATE TABLE edit_place
(
edit INTEGER NOT NULL, -- PK, references edit.id
place INTEGER NOT NULL -- PK, references place.id CASCADE
);
CREATE TABLE edit_release
(
edit INTEGER NOT NULL, -- PK, references edit.id
release INTEGER NOT NULL -- PK, references release.id CASCADE
);
CREATE TABLE edit_release_group
(
edit INTEGER NOT NULL, -- PK, references edit.id
release_group INTEGER NOT NULL -- PK, references release_group.id CASCADE
);
CREATE TABLE edit_recording
(
edit INTEGER NOT NULL, -- PK, references edit.id
recording INTEGER NOT NULL -- PK, references recording.id CASCADE
);
CREATE TABLE edit_series
(
edit INTEGER NOT NULL, -- PK, references edit.id
series INTEGER NOT NULL -- PK, references series.id CASCADE
);
CREATE TABLE edit_work
(
edit INTEGER NOT NULL, -- PK, references edit.id
work INTEGER NOT NULL -- PK, references work.id CASCADE
);
CREATE TABLE edit_url
(
edit INTEGER NOT NULL, -- PK, references edit.id
url INTEGER NOT NULL -- PK, references url.id CASCADE
);
CREATE TABLE editor
(
id SERIAL,
name VARCHAR(64) NOT NULL,
privs INTEGER DEFAULT 0,
email VARCHAR(64) DEFAULT NULL,
website VARCHAR(255) DEFAULT NULL,
bio TEXT DEFAULT NULL,
member_since TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
email_confirm_date TIMESTAMP WITH TIME ZONE,
last_login_date TIMESTAMP WITH TIME ZONE DEFAULT now(),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
birth_date DATE,
gender INTEGER, -- references gender.id
area INTEGER, -- references area.id
password VARCHAR(128) NOT NULL,
ha1 CHAR(32) NOT NULL,
deleted BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE old_editor_name (
name VARCHAR(64) NOT NULL
);
CREATE TABLE editor_language (
editor INTEGER NOT NULL, -- PK, references editor.id
language INTEGER NOT NULL, -- PK, references language.id
fluency FLUENCY NOT NULL
);
CREATE TABLE editor_preference
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
name VARCHAR(50) NOT NULL,
value VARCHAR(100) NOT NULL
);
CREATE TABLE editor_subscribe_artist
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
artist INTEGER NOT NULL, -- references artist.id
last_edit_sent INTEGER NOT NULL -- references edit.id
);
CREATE TABLE editor_subscribe_artist_deleted
(
editor INTEGER NOT NULL, -- PK, references editor.id
gid UUID NOT NULL, -- PK, references deleted_entity.gid
deleted_by INTEGER NOT NULL -- references edit.id
);
CREATE TABLE editor_subscribe_collection
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
collection INTEGER NOT NULL, -- weakly references editor_collection.id
last_edit_sent INTEGER NOT NULL, -- weakly references edit.id
available BOOLEAN NOT NULL DEFAULT TRUE,
last_seen_name VARCHAR(255)
);
CREATE TABLE editor_subscribe_label
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
label INTEGER NOT NULL, -- references label.id
last_edit_sent INTEGER NOT NULL -- references edit.id
);
CREATE TABLE editor_subscribe_label_deleted
(
editor INTEGER NOT NULL, -- PK, references editor.id
gid UUID NOT NULL, -- PK, references deleted_entity.gid
deleted_by INTEGER NOT NULL -- references edit.id
);
CREATE TABLE editor_subscribe_editor
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id (the one who has subscribed)
subscribed_editor INTEGER NOT NULL, -- references editor.id (the one being subscribed)
last_edit_sent INTEGER NOT NULL -- weakly references edit.id
);
CREATE TABLE editor_subscribe_series
(
id SERIAL,
editor INTEGER NOT NULL, -- references editor.id
series INTEGER NOT NULL, -- references series.id
last_edit_sent INTEGER NOT NULL -- references edit.id
);
CREATE TABLE editor_subscribe_series_deleted
(
editor INTEGER NOT NULL, -- PK, references editor.id
gid UUID NOT NULL, -- PK, references deleted_entity.gid
deleted_by INTEGER NOT NULL -- references edit.id
);
CREATE TABLE event ( -- replicate (verbose)
id SERIAL,
gid UUID NOT NULL,
name VARCHAR NOT NULL,
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
time TIME WITHOUT TIME ZONE,
type INTEGER, -- references event_type.id
cancelled BOOLEAN NOT NULL DEFAULT FALSE,
setlist TEXT,
comment VARCHAR(255) NOT NULL DEFAULT '',
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
ended BOOLEAN NOT NULL DEFAULT FALSE
CONSTRAINT event_ended_check CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR
end_date_day IS NOT NULL) AND
ended = TRUE
) OR (
-- Otherwise, all end date fields must be null
(end_date_year IS NULL AND
end_date_month IS NULL AND
end_date_day IS NULL)
)
)
);
CREATE TABLE event_meta ( -- replicate
id INTEGER NOT NULL, -- PK, references event.id CASCADE
rating SMALLINT CHECK (rating >= 0 AND rating <= 100),
rating_count INTEGER,
event_art_presence event_art_presence NOT NULL DEFAULT 'absent'
);
CREATE TABLE event_rating_raw (
event INTEGER NOT NULL, -- PK, references event.id
editor INTEGER NOT NULL, -- PK, references editor.id
rating SMALLINT NOT NULL CHECK (rating >= 0 AND rating <= 100)
);
CREATE TABLE event_tag_raw (
event INTEGER NOT NULL, -- PK, references event.id
editor INTEGER NOT NULL, -- PK, references editor.id
tag INTEGER NOT NULL, -- PK, references tag.id
is_upvote BOOLEAN NOT NULL DEFAULT TRUE
);
CREATE TABLE event_alias_type ( -- replicate
id SERIAL,
name TEXT NOT NULL,
parent INTEGER, -- references event_alias_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE event_alias ( -- replicate (verbose)
id SERIAL,
event INTEGER NOT NULL, -- references event.id
name VARCHAR NOT NULL,
locale TEXT,
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
type INTEGER, -- references event_alias_type.id
sort_name VARCHAR NOT NULL,
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
primary_for_locale BOOLEAN NOT NULL DEFAULT false,
ended BOOLEAN NOT NULL DEFAULT FALSE
CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR
end_date_day IS NOT NULL) AND
ended = TRUE
) OR (
-- Otherwise, all end date fields must be null
(end_date_year IS NULL AND
end_date_month IS NULL AND
end_date_day IS NULL)
)
),
CONSTRAINT primary_check CHECK ((locale IS NULL AND primary_for_locale IS FALSE) OR (locale IS NOT NULL)),
CONSTRAINT search_hints_are_empty
CHECK (
(type <> 2) OR (
type = 2 AND sort_name = name AND
begin_date_year IS NULL AND begin_date_month IS NULL AND begin_date_day IS NULL AND
end_date_year IS NULL AND end_date_month IS NULL AND end_date_day IS NULL AND
primary_for_locale IS FALSE AND locale IS NULL
)
)
);
CREATE TABLE event_annotation ( -- replicate (verbose)
event INTEGER NOT NULL, -- PK, references event.id
annotation INTEGER NOT NULL -- PK, references annotation.id
);
CREATE TABLE event_attribute_type ( -- replicate (verbose)
id SERIAL, -- PK
name VARCHAR(255) NOT NULL,
comment VARCHAR(255) NOT NULL DEFAULT '',
free_text BOOLEAN NOT NULL,
parent INTEGER, -- references event_attribute_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE event_attribute_type_allowed_value ( -- replicate (verbose)
id SERIAL, -- PK
event_attribute_type INTEGER NOT NULL, -- references event_attribute_type.id
value TEXT,
parent INTEGER, -- references event_attribute_type_allowed_value.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE event_attribute ( -- replicate (verbose)
id SERIAL, -- PK
event INTEGER NOT NULL, -- references event.id
event_attribute_type INTEGER NOT NULL, -- references event_attribute_type.id
event_attribute_type_allowed_value INTEGER, -- references event_attribute_type_allowed_value.id
event_attribute_text TEXT
CHECK (
(event_attribute_type_allowed_value IS NULL AND event_attribute_text IS NOT NULL)
OR
(event_attribute_type_allowed_value IS NOT NULL AND event_attribute_text IS NULL)
)
);
CREATE TABLE event_gid_redirect ( -- replicate (verbose)
gid UUID NOT NULL, -- PK
new_id INTEGER NOT NULL, -- references event.id
created TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE event_tag ( -- replicate (verbose)
event INTEGER NOT NULL, -- PK, references event.id
tag INTEGER NOT NULL, -- PK, references tag.id
count INTEGER NOT NULL,
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE event_type ( -- replicate
id SERIAL,
name VARCHAR(255) NOT NULL,
parent INTEGER, -- references event_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE release_first_release_date (
release INTEGER NOT NULL, -- PK, references release.id CASCADE
year SMALLINT,
month SMALLINT,
day SMALLINT
);
CREATE TABLE recording_first_release_date (
recording INTEGER NOT NULL, -- PK, references recording.id CASCADE
year SMALLINT,
month SMALLINT,
day SMALLINT
);
CREATE TABLE gender ( -- replicate
id SERIAL,
name VARCHAR(255) NOT NULL,
parent INTEGER, -- references gender.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE genre ( -- replicate (verbose)
id SERIAL, -- PK
gid UUID NOT NULL,
name VARCHAR NOT NULL,
comment VARCHAR(255) NOT NULL DEFAULT '',
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >=0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE genre_alias_type ( -- replicate
id SERIAL, -- PK,
name TEXT NOT NULL,
parent INTEGER, -- references genre_alias_type.id
child_order INTEGER NOT NULL DEFAULT 0,
description TEXT,
gid uuid NOT NULL
);
CREATE TABLE genre_alias ( -- replicate (verbose)
id SERIAL, --PK
genre INTEGER NOT NULL, -- references genre.id
name VARCHAR NOT NULL,
locale TEXT,
edits_pending INTEGER NOT NULL DEFAULT 0 CHECK (edits_pending >= 0),
last_updated TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
type INTEGER, -- references genre_alias_type.id
sort_name VARCHAR NOT NULL,
begin_date_year SMALLINT,
begin_date_month SMALLINT,
begin_date_day SMALLINT,
end_date_year SMALLINT,
end_date_month SMALLINT,
end_date_day SMALLINT,
primary_for_locale BOOLEAN NOT NULL DEFAULT false,
ended BOOLEAN NOT NULL DEFAULT FALSE
CHECK (
(
-- If any end date fields are not null, then ended must be true
(end_date_year IS NOT NULL OR
end_date_month IS NOT NULL OR