-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
1427 lines (1211 loc) · 50.5 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
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
-- Registry Schema - 2024-01-29
CREATE TABLE public.ar_internal_metadata (
"key" varchar NOT NULL,
value varchar NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
id serial4 NOT NULL,
CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (id)
);
CREATE UNIQUE INDEX ix_ar_internal_metadata_uniq_key ON public.ar_internal_metadata USING btree (key);
-- public.bulk_delete_jobs definition
CREATE TABLE public.bulk_delete_jobs (
id bigserial NOT NULL,
requested_by varchar NULL,
institutional_approver varchar NULL,
aptrust_approver varchar NULL,
institutional_approval_at timestamp NULL,
aptrust_approval_at timestamp NULL,
note text NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
institution_id int4 NOT NULL,
CONSTRAINT bulk_delete_jobs_pkey PRIMARY KEY (id)
);
-- public.bulk_delete_jobs_emails definition
CREATE TABLE public.bulk_delete_jobs_emails (
bulk_delete_job_id int8 NULL,
email_id int8 NULL
);
CREATE INDEX index_bulk_delete_jobs_emails_on_bulk_delete_job_id ON public.bulk_delete_jobs_emails USING btree (bulk_delete_job_id);
CREATE INDEX index_bulk_delete_jobs_emails_on_email_id ON public.bulk_delete_jobs_emails USING btree (email_id);
-- public.bulk_delete_jobs_generic_files definition
CREATE TABLE public.bulk_delete_jobs_generic_files (
bulk_delete_job_id int8 NULL,
generic_file_id int8 NULL
);
CREATE INDEX index_bulk_delete_jobs_generic_files_on_bulk_delete_job_id ON public.bulk_delete_jobs_generic_files USING btree (bulk_delete_job_id);
CREATE INDEX index_bulk_delete_jobs_generic_files_on_generic_file_id ON public.bulk_delete_jobs_generic_files USING btree (generic_file_id);
-- public.bulk_delete_jobs_institutions definition
CREATE TABLE public.bulk_delete_jobs_institutions (
bulk_delete_job_id int8 NULL,
institution_id int8 NULL
);
CREATE INDEX index_bulk_delete_jobs_institutions_on_bulk_delete_job_id ON public.bulk_delete_jobs_institutions USING btree (bulk_delete_job_id);
CREATE INDEX index_bulk_delete_jobs_institutions_on_institution_id ON public.bulk_delete_jobs_institutions USING btree (institution_id);
-- public.bulk_delete_jobs_intellectual_objects definition
CREATE TABLE public.bulk_delete_jobs_intellectual_objects (
bulk_delete_job_id int8 NULL,
intellectual_object_id int8 NULL
);
CREATE INDEX index_bulk_delete_jobs_intellectual_objects_on_bulk_job_id ON public.bulk_delete_jobs_intellectual_objects USING btree (bulk_delete_job_id);
CREATE INDEX index_bulk_delete_jobs_intellectual_objects_on_object_id ON public.bulk_delete_jobs_intellectual_objects USING btree (intellectual_object_id);
-- public.confirmation_tokens definition
CREATE TABLE public.confirmation_tokens (
id bigserial NOT NULL,
"token" varchar NULL,
intellectual_object_id int4 NULL,
generic_file_id int4 NULL,
institution_id int4 NULL,
user_id int4 NULL,
CONSTRAINT confirmation_tokens_pkey PRIMARY KEY (id)
);
-- public.emails definition
CREATE TABLE public.emails (
id bigserial NOT NULL,
email_type varchar NULL,
event_identifier varchar NULL,
item_id int4 NULL,
email_text text NULL,
user_list text NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
intellectual_object_id int4 NULL,
generic_file_id int4 NULL,
institution_id int4 NULL,
CONSTRAINT emails_pkey PRIMARY KEY (id)
);
-- public.emails_generic_files definition
CREATE TABLE public.emails_generic_files (
generic_file_id int8 NULL,
email_id int8 NULL
);
CREATE INDEX index_emails_generic_files_on_email_id ON public.emails_generic_files USING btree (email_id);
CREATE INDEX index_emails_generic_files_on_generic_file_id ON public.emails_generic_files USING btree (generic_file_id);
-- public.emails_intellectual_objects definition
CREATE TABLE public.emails_intellectual_objects (
intellectual_object_id int8 NULL,
email_id int8 NULL
);
CREATE INDEX index_emails_intellectual_objects_on_email_id ON public.emails_intellectual_objects USING btree (email_id);
CREATE INDEX index_emails_intellectual_objects_on_intellectual_object_id ON public.emails_intellectual_objects USING btree (intellectual_object_id);
-- public.emails_premis_events definition
CREATE TABLE public.emails_premis_events (
premis_event_id int8 NULL,
email_id int8 NULL
);
CREATE INDEX index_emails_premis_events_on_email_id ON public.emails_premis_events USING btree (email_id);
CREATE INDEX index_emails_premis_events_on_premis_event_id ON public.emails_premis_events USING btree (premis_event_id);
-- public.emails_work_items definition
CREATE TABLE public.emails_work_items (
work_item_id int8 NULL,
email_id int8 NULL
);
CREATE INDEX index_emails_work_items_on_email_id ON public.emails_work_items USING btree (email_id);
CREATE INDEX index_emails_work_items_on_work_item_id ON public.emails_work_items USING btree (work_item_id);
-- public.generic_files definition
CREATE TABLE public.generic_files (
id serial4 NOT NULL,
file_format varchar NULL,
"size" int8 NULL,
identifier varchar NULL,
intellectual_object_id int4 NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
state varchar NULL,
last_fixity_check timestamp NOT NULL DEFAULT '2000-01-01 00:00:00'::timestamp without time zone,
institution_id int4 NOT NULL,
storage_option varchar NOT NULL DEFAULT 'Standard'::character varying,
"uuid" varchar NOT NULL,
CONSTRAINT generic_files_pkey PRIMARY KEY (id)
);
CREATE INDEX index_generic_files_on_created_at ON public.generic_files USING btree (created_at);
CREATE UNIQUE INDEX index_generic_files_on_identifier ON public.generic_files USING btree (identifier);
CREATE INDEX index_generic_files_on_institution_id ON public.generic_files USING btree (institution_id);
CREATE INDEX index_generic_files_on_institution_id_and_state ON public.generic_files USING btree (institution_id, state);
CREATE INDEX index_generic_files_on_institution_id_and_updated_at ON public.generic_files USING btree (institution_id, updated_at);
CREATE INDEX index_generic_files_on_intellectual_object_id ON public.generic_files USING btree (intellectual_object_id);
CREATE INDEX index_generic_files_on_updated_at ON public.generic_files USING btree (updated_at);
CREATE UNIQUE INDEX index_generic_files_on_uuid ON public.generic_files USING btree (uuid);
CREATE INDEX ix_generic_files_state_opt_fixity ON public.generic_files USING btree (state, storage_option, last_fixity_check);
CREATE INDEX ix_gf_last_fixity_check ON public.generic_files USING btree (last_fixity_check);
-- public.historical_deposit_stats definition
CREATE TABLE public.historical_deposit_stats (
institution_id int8 NULL,
institution_name varchar(80) NULL,
storage_option varchar(40) NULL,
object_count int8 NULL,
file_count int8 NULL,
total_bytes int8 NULL,
total_gb float8 NULL,
total_tb float8 NULL,
cost_gb_per_month float8 NULL,
monthly_cost float8 NULL,
end_date date NULL,
member_institution_id int4 NULL,
primary_sort varchar NULL,
secondary_sort varchar NULL
);
CREATE INDEX ix_historical_deposit_stats_end_date ON public.historical_deposit_stats USING btree (end_date);
CREATE INDEX ix_historical_deposit_stats_inst_id ON public.historical_deposit_stats USING btree (institution_id);
CREATE INDEX ix_historical_deposit_stats_storage_option ON public.historical_deposit_stats USING btree (storage_option);
CREATE UNIQUE INDEX ix_historical_inst_opt_date ON public.historical_deposit_stats USING btree (institution_id, storage_option, end_date);
-- public.intellectual_objects definition
CREATE TABLE public.intellectual_objects (
id serial4 NOT NULL,
title varchar NULL,
description text NULL,
identifier varchar NULL,
alt_identifier varchar NULL,
"access" varchar NULL,
bag_name varchar NULL,
institution_id int4 NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
state varchar NULL,
etag varchar NULL,
bag_group_identifier varchar NULL,
storage_option varchar NOT NULL DEFAULT 'Standard'::character varying,
bagit_profile_identifier varchar NULL,
source_organization varchar NULL,
internal_sender_identifier varchar NULL,
internal_sender_description text NULL,
CONSTRAINT intellectual_objects_pkey PRIMARY KEY (id)
);
CREATE INDEX index_intellectual_objects_on_bag_name ON public.intellectual_objects USING btree (bag_name);
CREATE INDEX index_intellectual_objects_on_created_at ON public.intellectual_objects USING btree (created_at);
CREATE UNIQUE INDEX index_intellectual_objects_on_identifier ON public.intellectual_objects USING btree (identifier);
CREATE INDEX index_intellectual_objects_on_institution_id ON public.intellectual_objects USING btree (institution_id);
CREATE INDEX index_intellectual_objects_on_updated_at ON public.intellectual_objects USING btree (updated_at);
-- public.old_passwords definition
CREATE TABLE public.old_passwords (
id bigserial NOT NULL,
encrypted_password varchar NOT NULL,
password_salt varchar NULL,
password_archivable_type varchar NOT NULL,
password_archivable_id int4 NOT NULL,
created_at timestamp NULL,
CONSTRAINT old_passwords_pkey PRIMARY KEY (id)
);
CREATE INDEX index_password_archivable ON public.old_passwords USING btree (password_archivable_type, password_archivable_id);
-- public.premis_events definition
CREATE TABLE public.premis_events (
id serial4 NOT NULL,
identifier varchar NULL,
event_type varchar NULL,
date_time timestamp NULL,
outcome_detail varchar NULL,
detail varchar NULL,
outcome_information varchar NULL,
"object" varchar NULL,
agent varchar NULL,
intellectual_object_id int4 NULL,
generic_file_id int4 NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
outcome varchar NULL,
institution_id int4 NULL,
old_uuid varchar NULL,
CONSTRAINT premis_events_pkey PRIMARY KEY (id)
);
CREATE INDEX index_premis_events_date_time_desc ON public.premis_events USING btree (date_time DESC);
CREATE INDEX index_premis_events_on_event_type ON public.premis_events USING btree (event_type);
CREATE INDEX index_premis_events_on_event_type_and_outcome ON public.premis_events USING btree (event_type, outcome);
CREATE INDEX index_premis_events_on_generic_file_id ON public.premis_events USING btree (generic_file_id);
CREATE UNIQUE INDEX index_premis_events_on_identifier ON public.premis_events USING btree (identifier);
CREATE INDEX index_premis_events_on_institution_id ON public.premis_events USING btree (institution_id);
CREATE INDEX index_premis_events_on_intellectual_object_id ON public.premis_events USING btree (intellectual_object_id);
CREATE INDEX index_premis_events_on_outcome ON public.premis_events USING btree (outcome);
-- public.schema_migrations definition
CREATE TABLE public.schema_migrations (
"version" varchar NOT NULL,
started_at timestamp NULL,
finished_at timestamp NULL,
CONSTRAINT schema_migrations_pkey PRIMARY KEY (version)
);
-- public.snapshots definition
CREATE TABLE public.snapshots (
id bigserial NOT NULL,
audit_date timestamp NULL,
institution_id int4 NULL,
apt_bytes int8 NULL,
"cost" numeric NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
snapshot_type varchar NULL,
cs_bytes int8 NULL,
go_bytes int8 NULL,
CONSTRAINT snapshots_pkey PRIMARY KEY (id)
);
-- public.storage_options definition
CREATE TABLE public.storage_options (
id bigserial NOT NULL,
provider varchar NOT NULL,
service varchar NOT NULL,
region varchar NOT NULL,
"name" varchar NOT NULL,
cost_gb_per_month numeric(12, 8) NOT NULL,
"comment" varchar NOT NULL,
updated_at timestamp NOT NULL,
CONSTRAINT storage_options_pkey PRIMARY KEY (id)
);
CREATE UNIQUE INDEX index_storage_options_name ON public.storage_options USING btree (name);
-- public.usage_samples definition
CREATE TABLE public.usage_samples (
id serial4 NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
institution_id varchar NULL,
"data" text NULL,
CONSTRAINT usage_samples_pkey PRIMARY KEY (id)
);
-- public.checksums definition
CREATE TABLE public.checksums (
id serial4 NOT NULL,
algorithm varchar NULL,
datetime timestamp NULL,
digest varchar NULL,
generic_file_id int4 NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
CONSTRAINT checksums_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_89bb0866e7 FOREIGN KEY (generic_file_id) REFERENCES public.generic_files(id)
);
CREATE INDEX index_checksums_on_generic_file_id ON public.checksums USING btree (generic_file_id);
-- public.storage_records definition
CREATE TABLE public.storage_records (
id bigserial NOT NULL,
generic_file_id int4 NULL,
url varchar NULL,
CONSTRAINT storage_records_pkey PRIMARY KEY (id),
CONSTRAINT fk_rails_a126ea6adc FOREIGN KEY (generic_file_id) REFERENCES public.generic_files(id)
);
CREATE INDEX index_storage_records_on_generic_file_id ON public.storage_records USING btree (generic_file_id);
-- public.alerts definition
CREATE TABLE public.alerts (
id bigserial NOT NULL,
institution_id int4 NULL,
"type" varchar NOT NULL,
subject varchar NOT NULL,
"content" text NOT NULL,
deletion_request_id int4 NULL,
created_at timestamp NOT NULL,
CONSTRAINT alerts_pkey PRIMARY KEY (id)
);
CREATE INDEX index_alerts_institution_id ON public.alerts USING btree (institution_id);
CREATE INDEX index_alerts_type ON public.alerts USING btree (type);
-- public.alerts_premis_events definition
CREATE TABLE public.alerts_premis_events (
alert_id int4 NOT NULL,
premis_event_id int4 NOT NULL
);
CREATE INDEX index_alerts_premis_events_alert_id ON public.alerts_premis_events USING btree (alert_id);
CREATE UNIQUE INDEX index_alerts_premis_events_unique ON public.alerts_premis_events USING btree (alert_id, premis_event_id);
-- public.alerts_users definition
CREATE TABLE public.alerts_users (
alert_id int4 NOT NULL,
user_id int4 NOT NULL,
sent_at timestamp NULL,
read_at timestamp NULL
);
CREATE INDEX index_alerts_users_alert_id ON public.alerts_users USING btree (alert_id);
CREATE UNIQUE INDEX index_alerts_users_unique ON public.alerts_users USING btree (alert_id, user_id);
CREATE INDEX index_alerts_users_user_id ON public.alerts_users USING btree (user_id);
-- public.alerts_work_items definition
CREATE TABLE public.alerts_work_items (
alert_id int4 NOT NULL,
work_item_id int4 NOT NULL
);
CREATE INDEX index_alerts_work_items_alert_id ON public.alerts_work_items USING btree (alert_id);
CREATE UNIQUE INDEX index_alerts_work_items_unique ON public.alerts_work_items USING btree (alert_id, work_item_id);
-- public.deletion_requests definition
CREATE TABLE public.deletion_requests (
id bigserial NOT NULL,
institution_id int4 NOT NULL,
requested_by_id int4 NOT NULL,
requested_at timestamp NOT NULL,
encrypted_confirmation_token varchar NOT NULL,
confirmed_by_id int4 NULL,
confirmed_at timestamp NULL,
cancelled_by_id int4 NULL,
cancelled_at timestamp NULL,
CONSTRAINT deletion_requests_pkey PRIMARY KEY (id)
);
CREATE INDEX index_deletion_requests_institution_id ON public.deletion_requests USING btree (institution_id);
-- public.deletion_requests_generic_files definition
CREATE TABLE public.deletion_requests_generic_files (
deletion_request_id int4 NOT NULL,
generic_file_id int4 NOT NULL
);
CREATE UNIQUE INDEX index_drgf_unique ON public.deletion_requests_generic_files USING btree (deletion_request_id, generic_file_id);
-- public.deletion_requests_intellectual_objects definition
CREATE TABLE public.deletion_requests_intellectual_objects (
deletion_request_id int4 NOT NULL,
intellectual_object_id int4 NOT NULL
);
CREATE UNIQUE INDEX index_drio_unique ON public.deletion_requests_intellectual_objects USING btree (deletion_request_id, intellectual_object_id);
-- public.institutions definition
CREATE TABLE public.institutions (
id serial4 NOT NULL,
"name" varchar NULL,
identifier varchar NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
state varchar NULL,
"type" varchar NULL,
member_institution_id int4 NULL,
deactivated_at timestamp NULL,
otp_enabled bool NULL,
receiving_bucket varchar NOT NULL,
restore_bucket varchar NOT NULL,
spot_restore_frequency int4 NOT NULL DEFAULT 0,
last_spot_restore_work_item_id int8 NULL,
CONSTRAINT institutions_pkey PRIMARY KEY (id)
);
CREATE UNIQUE INDEX index_institutions_identifier ON public.institutions USING btree (identifier);
CREATE INDEX index_institutions_on_name ON public.institutions USING btree (name);
CREATE UNIQUE INDEX index_institutions_receiving_bucket ON public.institutions USING btree (receiving_bucket);
CREATE UNIQUE INDEX index_institutions_restore_bucket ON public.institutions USING btree (restore_bucket);
-- public.users definition
CREATE TABLE public.users (
id serial4 NOT NULL,
"name" varchar NULL,
email varchar NULL,
phone_number varchar NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
encrypted_password varchar NOT NULL DEFAULT ''::character varying,
reset_password_token varchar NULL,
reset_password_sent_at timestamp NULL,
remember_created_at timestamp NULL,
sign_in_count int4 NOT NULL DEFAULT 0,
current_sign_in_at timestamp NULL,
last_sign_in_at timestamp NULL,
current_sign_in_ip varchar NULL,
last_sign_in_ip varchar NULL,
institution_id int4 NULL,
encrypted_api_secret_key text NULL,
password_changed_at timestamp NULL,
encrypted_otp_secret varchar NULL,
encrypted_otp_secret_iv varchar NULL,
encrypted_otp_secret_salt varchar NULL,
encrypted_otp_sent_at timestamp NULL,
consumed_timestep int4 NULL,
otp_required_for_login bool NULL,
deactivated_at timestamp NULL,
enabled_two_factor bool NULL DEFAULT false,
confirmed_two_factor bool NULL DEFAULT false,
otp_backup_codes _varchar NULL,
authy_id varchar NULL,
last_sign_in_with_authy timestamp NULL,
authy_status varchar NULL,
email_verified bool NULL DEFAULT false,
initial_password_updated bool NULL DEFAULT false,
force_password_update bool NULL DEFAULT false,
account_confirmed bool NULL DEFAULT true,
grace_period timestamp NULL,
awaiting_second_factor bool NOT NULL DEFAULT false,
"role" varchar(50) NOT NULL DEFAULT 'none'::character varying,
CONSTRAINT users_pkey PRIMARY KEY (id)
);
CREATE INDEX index_users_on_authy_id ON public.users USING btree (authy_id);
CREATE UNIQUE INDEX index_users_on_email ON public.users USING btree (email);
CREATE INDEX index_users_on_institution_id ON public.users USING btree (institution_id);
CREATE INDEX index_users_on_password_changed_at ON public.users USING btree (password_changed_at);
CREATE UNIQUE INDEX index_users_on_reset_password_token ON public.users USING btree (reset_password_token);
-- public.work_items definition
CREATE TABLE public.work_items (
id serial4 NOT NULL,
created_at timestamp NOT NULL,
updated_at timestamp NOT NULL,
intellectual_object_id int4 NULL,
generic_file_id int4 NULL,
"name" varchar NULL,
etag varchar NULL,
bucket varchar NULL,
"user" varchar NULL,
note text NULL,
"action" varchar NULL,
stage varchar NULL,
status varchar NULL,
outcome text NULL,
bag_date timestamp NULL,
date_processed timestamp NULL,
retry bool NOT NULL DEFAULT false,
node varchar(255) NULL,
pid int4 NULL DEFAULT 0,
needs_admin_review bool NOT NULL DEFAULT false,
institution_id int4 NULL,
queued_at timestamp NULL,
"size" int8 NULL,
stage_started_at timestamp NULL,
aptrust_approver varchar NULL,
inst_approver varchar NULL,
deletion_request_id int8 NULL,
CONSTRAINT work_items_pkey PRIMARY KEY (id)
);
CREATE INDEX index_work_items_etag_instid_and_name ON public.work_items USING btree (etag, institution_id, name);
CREATE INDEX index_work_items_on_action ON public.work_items USING btree (action);
CREATE INDEX index_work_items_on_date_processed ON public.work_items USING btree (date_processed);
CREATE INDEX index_work_items_on_etag_and_name ON public.work_items USING btree (etag, name);
CREATE INDEX index_work_items_on_generic_file_id ON public.work_items USING btree (generic_file_id);
CREATE INDEX index_work_items_on_inst_id_and_date_processed ON public.work_items USING btree (institution_id, date_processed);
CREATE INDEX index_work_items_on_institution_id ON public.work_items USING btree (institution_id);
CREATE INDEX index_work_items_on_intellectual_object_id ON public.work_items USING btree (intellectual_object_id);
CREATE INDEX index_work_items_on_stage ON public.work_items USING btree (stage);
CREATE INDEX index_work_items_on_status ON public.work_items USING btree (status);
-- public.alerts foreign keys
ALTER TABLE public.alerts ADD CONSTRAINT alerts_deletion_request_id_fkey FOREIGN KEY (deletion_request_id) REFERENCES public.deletion_requests(id);
ALTER TABLE public.alerts ADD CONSTRAINT alerts_institution_id_fkey FOREIGN KEY (institution_id) REFERENCES public.institutions(id);
-- public.alerts_premis_events foreign keys
ALTER TABLE public.alerts_premis_events ADD CONSTRAINT alerts_premis_events_alert_id_fkey FOREIGN KEY (alert_id) REFERENCES public.alerts(id);
ALTER TABLE public.alerts_premis_events ADD CONSTRAINT alerts_premis_events_premis_event_id_fkey FOREIGN KEY (premis_event_id) REFERENCES public.premis_events(id);
-- public.alerts_users foreign keys
ALTER TABLE public.alerts_users ADD CONSTRAINT alerts_users_alert_id_fkey FOREIGN KEY (alert_id) REFERENCES public.alerts(id);
ALTER TABLE public.alerts_users ADD CONSTRAINT alerts_users_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
-- public.alerts_work_items foreign keys
ALTER TABLE public.alerts_work_items ADD CONSTRAINT alerts_work_items_alert_id_fkey FOREIGN KEY (alert_id) REFERENCES public.alerts(id);
ALTER TABLE public.alerts_work_items ADD CONSTRAINT alerts_work_items_work_item_id_fkey FOREIGN KEY (work_item_id) REFERENCES public.work_items(id);
-- public.deletion_requests foreign keys
ALTER TABLE public.deletion_requests ADD CONSTRAINT deletion_requests_cancelled_by_id_fkey FOREIGN KEY (cancelled_by_id) REFERENCES public.users(id);
ALTER TABLE public.deletion_requests ADD CONSTRAINT deletion_requests_confirmed_by_id_fkey FOREIGN KEY (confirmed_by_id) REFERENCES public.users(id);
ALTER TABLE public.deletion_requests ADD CONSTRAINT deletion_requests_institution_id_fkey FOREIGN KEY (institution_id) REFERENCES public.institutions(id);
ALTER TABLE public.deletion_requests ADD CONSTRAINT deletion_requests_requested_by_id_fkey FOREIGN KEY (requested_by_id) REFERENCES public.users(id);
-- public.deletion_requests_generic_files foreign keys
ALTER TABLE public.deletion_requests_generic_files ADD CONSTRAINT deletion_requests_generic_files_deletion_request_id_fkey FOREIGN KEY (deletion_request_id) REFERENCES public.deletion_requests(id);
ALTER TABLE public.deletion_requests_generic_files ADD CONSTRAINT deletion_requests_generic_files_generic_file_id_fkey FOREIGN KEY (generic_file_id) REFERENCES public.generic_files(id);
-- public.deletion_requests_intellectual_objects foreign keys
ALTER TABLE public.deletion_requests_intellectual_objects ADD CONSTRAINT deletion_requests_intellectual_obje_intellectual_object_id_fkey FOREIGN KEY (intellectual_object_id) REFERENCES public.intellectual_objects(id);
ALTER TABLE public.deletion_requests_intellectual_objects ADD CONSTRAINT deletion_requests_intellectual_objects_deletion_request_id_fkey FOREIGN KEY (deletion_request_id) REFERENCES public.deletion_requests(id);
-- public.institutions foreign keys
ALTER TABLE public.institutions ADD CONSTRAINT fk_institutions_last_spot_restore FOREIGN KEY (last_spot_restore_work_item_id) REFERENCES public.work_items(id);
-- public.users foreign keys
ALTER TABLE public.users ADD CONSTRAINT fk_rails_7fcf39ca13 FOREIGN KEY (institution_id) REFERENCES public.institutions(id);
-- public.work_items foreign keys
ALTER TABLE public.work_items ADD CONSTRAINT fk_work_items_deletion_request_id FOREIGN KEY (deletion_request_id) REFERENCES public.deletion_requests(id);
-- public.alerts_view source
CREATE OR REPLACE VIEW public.alerts_view
AS SELECT a.id,
a.institution_id,
i.name AS institution_name,
i.identifier AS institution_identifier,
a.type,
a.subject,
a.content,
a.deletion_request_id,
a.created_at,
au.user_id,
u.name AS user_name,
u.email AS user_email,
au.sent_at,
au.read_at
FROM alerts a
LEFT JOIN alerts_users au ON a.id = au.alert_id
LEFT JOIN users u ON au.user_id = u.id
LEFT JOIN institutions i ON a.institution_id = i.id;
-- public.checksums_view source
CREATE OR REPLACE VIEW public.checksums_view
AS SELECT cs.id,
cs.algorithm,
cs.datetime,
cs.digest,
gf.state,
gf.identifier AS generic_file_identifier,
cs.generic_file_id,
gf.intellectual_object_id,
gf.institution_id,
cs.created_at,
cs.updated_at
FROM checksums cs
LEFT JOIN generic_files gf ON cs.generic_file_id = gf.id;
-- public.current_deposit_stats source
CREATE MATERIALIZED VIEW public.current_deposit_stats
TABLESPACE pg_default
AS SELECT i2.id AS institution_id,
i2.member_institution_id,
COALESCE(stats.institution_name, 'All Institutions'::character varying) AS institution_name,
COALESCE(stats.storage_option, 'Total'::character varying) AS storage_option,
stats.file_count,
stats.object_count,
stats.total_bytes,
stats.total_bytes / 1073741824::numeric AS total_gb,
stats.total_bytes / '1099511627776'::bigint::numeric AS total_tb,
so.cost_gb_per_month,
stats.total_bytes / 1073741824::numeric * so.cost_gb_per_month AS monthly_cost,
now() AS end_date,
COALESCE(stats.institution_name, 'zzz'::character varying) AS primary_sort,
COALESCE(stats.storage_option, 'zzz'::character varying) AS secondary_sort
FROM ( SELECT i.name AS institution_name,
count(gf.id) AS file_count,
count(DISTINCT gf.intellectual_object_id) AS object_count,
sum(gf.size) AS total_bytes,
gf.storage_option
FROM generic_files gf
LEFT JOIN institutions i ON i.id = gf.institution_id
WHERE gf.state::text = 'A'::text
GROUP BY CUBE(i.name, gf.storage_option)) stats
LEFT JOIN storage_options so ON so.name::text = stats.storage_option::text
LEFT JOIN institutions i2 ON i2.name::text = stats.institution_name::text
ORDER BY stats.institution_name, stats.storage_option
WITH DATA;
-- View indexes:
CREATE UNIQUE INDEX ix_current_deposits_inst_id_storage_option ON public.current_deposit_stats USING btree (institution_id, storage_option);
-- public.deletion_requests_view source
CREATE OR REPLACE VIEW public.deletion_requests_view
AS SELECT dr.id,
dr.institution_id,
i.name AS institution_name,
i.identifier AS institution_identifier,
dr.requested_by_id,
req.name AS requested_by_name,
req.email AS requested_by_email,
dr.requested_at,
dr.confirmed_by_id,
conf.name AS confirmed_by_name,
conf.email AS confirmed_by_email,
dr.confirmed_at,
dr.cancelled_by_id,
can.name AS cancelled_by_name,
can.email AS cancelled_by_email,
dr.cancelled_at,
( SELECT count(*) AS count
FROM deletion_requests_generic_files drgf
WHERE drgf.deletion_request_id = dr.id) AS file_count,
( SELECT count(*) AS count
FROM deletion_requests_intellectual_objects drio
WHERE drio.deletion_request_id = dr.id) AS object_count
FROM deletion_requests dr
LEFT JOIN institutions i ON dr.institution_id = i.id
LEFT JOIN users req ON dr.requested_by_id = req.id
LEFT JOIN users conf ON dr.confirmed_by_id = conf.id
LEFT JOIN users can ON dr.confirmed_by_id = can.id;
-- public.generic_file_counts source
CREATE MATERIALIZED VIEW public.generic_file_counts
TABLESPACE pg_default
AS SELECT generic_files.institution_id,
count(generic_files.id) AS row_count,
generic_files.state,
CURRENT_TIMESTAMP AS updated_at
FROM generic_files
GROUP BY CUBE(generic_files.institution_id, generic_files.state)
ORDER BY generic_files.institution_id, generic_files.state
WITH DATA;
-- View indexes:
CREATE UNIQUE INDEX ix_generic_file_counts ON public.generic_file_counts USING btree (institution_id, state);
-- public.generic_files_view source
CREATE OR REPLACE VIEW public.generic_files_view
AS SELECT gf.id,
gf.file_format,
gf.size,
gf.identifier,
gf.intellectual_object_id,
io.identifier AS object_identifier,
io.access,
gf.state,
gf.last_fixity_check,
gf.institution_id,
i.name AS institution_name,
i.identifier AS institution_identifier,
gf.storage_option,
gf.uuid,
( SELECT checksums.digest
FROM checksums
WHERE checksums.generic_file_id = gf.id AND checksums.algorithm::text = 'md5'::text
ORDER BY checksums.created_at DESC
LIMIT 1) AS md5,
( SELECT checksums.digest
FROM checksums
WHERE checksums.generic_file_id = gf.id AND checksums.algorithm::text = 'sha1'::text
ORDER BY checksums.created_at DESC
LIMIT 1) AS sha1,
( SELECT checksums.digest
FROM checksums
WHERE checksums.generic_file_id = gf.id AND checksums.algorithm::text = 'sha256'::text
ORDER BY checksums.created_at DESC
LIMIT 1) AS sha256,
( SELECT checksums.digest
FROM checksums
WHERE checksums.generic_file_id = gf.id AND checksums.algorithm::text = 'sha512'::text
ORDER BY checksums.created_at DESC
LIMIT 1) AS sha512,
gf.created_at,
gf.updated_at
FROM generic_files gf
LEFT JOIN intellectual_objects io ON io.id = gf.intellectual_object_id
LEFT JOIN institutions i ON i.id = gf.institution_id;
-- public.institutions_view source
CREATE OR REPLACE VIEW public.institutions_view
AS SELECT i.id,
i.name,
i.identifier,
i.state,
i.type,
i.deactivated_at,
i.otp_enabled,
i.receiving_bucket,
i.restore_bucket,
i.spot_restore_frequency,
i.last_spot_restore_work_item_id,
i.created_at,
i.updated_at,
i.member_institution_id AS parent_id,
parent.name AS parent_name,
parent.identifier AS parent_identifier,
parent.state AS parent_state,
parent.deactivated_at AS parent_deactivated_at
FROM institutions i
LEFT JOIN institutions parent ON i.member_institution_id = parent.id;
-- public.intellectual_object_counts source
CREATE MATERIALIZED VIEW public.intellectual_object_counts
TABLESPACE pg_default
AS SELECT intellectual_objects.institution_id,
count(intellectual_objects.id) AS row_count,
intellectual_objects.state,
CURRENT_TIMESTAMP AS updated_at
FROM intellectual_objects
GROUP BY CUBE(intellectual_objects.institution_id, intellectual_objects.state)
ORDER BY intellectual_objects.institution_id, intellectual_objects.state
WITH DATA;
-- View indexes:
CREATE UNIQUE INDEX ix_intellectual_object_counts ON public.intellectual_object_counts USING btree (institution_id, state);
-- public.intellectual_objects_view source
CREATE OR REPLACE VIEW public.intellectual_objects_view
AS SELECT io.id,
io.title,
io.description,
io.identifier,
io.alt_identifier,
io.access,
io.bag_name,
io.institution_id,
io.state,
io.etag,
io.bag_group_identifier,
io.storage_option,
io.bagit_profile_identifier,
io.source_organization,
io.internal_sender_identifier,
io.internal_sender_description,
io.created_at,
io.updated_at,
i.name AS institution_name,
i.identifier AS institution_identifier,
i.type AS institution_type,
i.member_institution_id AS institution_parent_id,
( SELECT count(*) AS count
FROM generic_files gf
WHERE gf.intellectual_object_id = io.id AND gf.state::text = 'A'::text) AS file_count,
( SELECT sum(gf.size) AS sum
FROM generic_files gf
WHERE gf.intellectual_object_id = io.id AND gf.state::text = 'A'::text) AS size,
( SELECT count(*) AS count
FROM generic_files gf
WHERE gf.intellectual_object_id = io.id AND gf.state::text = 'A'::text AND gf.identifier::text ~~ concat(io.identifier, '/data/%')) AS payload_file_count,
( SELECT sum(gf.size) AS sum
FROM generic_files gf
WHERE gf.intellectual_object_id = io.id AND gf.state::text = 'A'::text AND gf.identifier::text ~~ concat(io.identifier, '/data/%')) AS payload_size
FROM intellectual_objects io
LEFT JOIN institutions i ON io.institution_id = i.id;
-- public.premis_event_counts source
CREATE MATERIALIZED VIEW public.premis_event_counts
TABLESPACE pg_default
AS SELECT premis_events.institution_id,
count(premis_events.id) AS row_count,
premis_events.event_type,
premis_events.outcome,
CURRENT_TIMESTAMP AS updated_at
FROM premis_events
GROUP BY CUBE(premis_events.institution_id, premis_events.event_type, premis_events.outcome)
ORDER BY premis_events.institution_id, premis_events.event_type, premis_events.outcome
WITH DATA;
-- View indexes:
CREATE UNIQUE INDEX ix_premis_event_counts ON public.premis_event_counts USING btree (institution_id, event_type, outcome);
-- public.premis_events_view source
CREATE OR REPLACE VIEW public.premis_events_view
AS SELECT pe.id,
pe.identifier,
pe.institution_id,
i.name AS institution_name,
pe.intellectual_object_id,
io.identifier AS intellectual_object_identifier,
pe.generic_file_id,
gf.identifier AS generic_file_identifier,
pe.event_type,
pe.date_time,
pe.detail,
pe.outcome,
pe.outcome_detail,
pe.outcome_information,
pe.object,
pe.agent,
pe.created_at,
pe.updated_at,
pe.old_uuid
FROM premis_events pe
LEFT JOIN institutions i ON pe.institution_id = i.id
LEFT JOIN intellectual_objects io ON pe.intellectual_object_id = io.id
LEFT JOIN generic_files gf ON pe.generic_file_id = gf.id;
-- public.storage_option_stats source
CREATE OR REPLACE VIEW public.storage_option_stats
AS WITH stats AS (
SELECT sum(gf.size) AS total_bytes,
count(*) AS file_count,
gf.institution_id,
gf.storage_option
FROM generic_files gf
WHERE gf.state::text = 'A'::text
GROUP BY ROLLUP(gf.institution_id, gf.storage_option)
)
SELECT s.total_bytes,
s.file_count,
s.institution_id,
s.storage_option,
i.name AS institution_name,
i.identifier AS institution_identifier
FROM stats s
LEFT JOIN institutions i ON s.institution_id = i.id;
-- public.users_view source
CREATE OR REPLACE VIEW public.users_view
AS SELECT u.id,
u.name,
u.email,
u.phone_number,
u.created_at,
u.updated_at,
u.reset_password_sent_at,
u.remember_created_at,
u.sign_in_count,
u.current_sign_in_at,
u.last_sign_in_at,
u.current_sign_in_ip,
u.last_sign_in_ip,
u.institution_id,
u.password_changed_at,
u.consumed_timestep,
u.otp_required_for_login,
u.deactivated_at,
u.enabled_two_factor,
u.confirmed_two_factor,
u.authy_id,
u.last_sign_in_with_authy,
u.authy_status,
u.email_verified,
u.initial_password_updated,
u.force_password_update,
u.account_confirmed,
u.grace_period,
u.role,
i.name AS institution_name,
i.identifier AS institution_identifier,
i.state AS institution_state,
i.type AS institution_type,
i.member_institution_id,
i2.name AS member_institution_name,
i2.identifier AS member_institution_identifier,
i2.state AS member_institution_state,
i.otp_enabled,
i.receiving_bucket,
i.restore_bucket
FROM users u
LEFT JOIN institutions i ON u.institution_id = i.id
LEFT JOIN institutions i2 ON i.member_institution_id = i2.id;
-- public.work_item_counts source
CREATE MATERIALIZED VIEW public.work_item_counts
TABLESPACE pg_default
AS SELECT work_items.institution_id,
count(work_items.id) AS row_count,
work_items.action,
CURRENT_TIMESTAMP AS updated_at
FROM work_items
GROUP BY CUBE(work_items.institution_id, work_items.action)
ORDER BY work_items.institution_id, work_items.action
WITH DATA;
-- View indexes:
CREATE UNIQUE INDEX ix_work_item_counts ON public.work_item_counts USING btree (institution_id, action);