forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1528395617_squashed_migrations.up.sql
1535 lines (1245 loc) · 61.2 KB
/
1528395617_squashed_migrations.up.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
BEGIN;
ALTER TABLE IF EXISTS ONLY user_external_accounts DROP CONSTRAINT IF EXISTS user_external_accounts_user_id_fkey;
ALTER TABLE IF EXISTS ONLY user_emails DROP CONSTRAINT IF EXISTS user_emails_user_id_fkey;
ALTER TABLE IF EXISTS ONLY survey_responses DROP CONSTRAINT IF EXISTS survey_responses_user_id_fkey;
ALTER TABLE IF EXISTS ONLY settings DROP CONSTRAINT IF EXISTS settings_user_id_fkey;
ALTER TABLE IF EXISTS ONLY settings DROP CONSTRAINT IF EXISTS settings_references_orgs;
ALTER TABLE IF EXISTS ONLY settings DROP CONSTRAINT IF EXISTS settings_author_user_id_fkey;
ALTER TABLE IF EXISTS ONLY saved_searches DROP CONSTRAINT IF EXISTS saved_searches_user_id_fkey;
ALTER TABLE IF EXISTS ONLY saved_searches DROP CONSTRAINT IF EXISTS saved_searches_org_id_fkey;
ALTER TABLE IF EXISTS ONLY registry_extensions DROP CONSTRAINT IF EXISTS registry_extensions_publisher_user_id_fkey;
ALTER TABLE IF EXISTS ONLY registry_extensions DROP CONSTRAINT IF EXISTS registry_extensions_publisher_org_id_fkey;
ALTER TABLE IF EXISTS ONLY registry_extension_releases DROP CONSTRAINT IF EXISTS registry_extension_releases_registry_extension_id_fkey;
ALTER TABLE IF EXISTS ONLY registry_extension_releases DROP CONSTRAINT IF EXISTS registry_extension_releases_creator_user_id_fkey;
ALTER TABLE IF EXISTS ONLY product_subscriptions DROP CONSTRAINT IF EXISTS product_subscriptions_user_id_fkey;
ALTER TABLE IF EXISTS ONLY product_licenses DROP CONSTRAINT IF EXISTS product_licenses_product_subscription_id_fkey;
ALTER TABLE IF EXISTS ONLY org_members DROP CONSTRAINT IF EXISTS org_members_user_id_fkey;
ALTER TABLE IF EXISTS ONLY org_members DROP CONSTRAINT IF EXISTS org_members_references_orgs;
ALTER TABLE IF EXISTS ONLY org_invitations DROP CONSTRAINT IF EXISTS org_invitations_sender_user_id_fkey;
ALTER TABLE IF EXISTS ONLY org_invitations DROP CONSTRAINT IF EXISTS org_invitations_recipient_user_id_fkey;
ALTER TABLE IF EXISTS ONLY org_invitations DROP CONSTRAINT IF EXISTS org_invitations_org_id_fkey;
ALTER TABLE IF EXISTS ONLY names DROP CONSTRAINT IF EXISTS names_user_id_fkey;
ALTER TABLE IF EXISTS ONLY names DROP CONSTRAINT IF EXISTS names_org_id_fkey;
ALTER TABLE IF EXISTS ONLY lsif_references DROP CONSTRAINT IF EXISTS lsif_references_dump_id_fkey;
ALTER TABLE IF EXISTS ONLY lsif_packages DROP CONSTRAINT IF EXISTS lsif_packages_dump_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_threads_target_repo DROP CONSTRAINT IF EXISTS discussion_threads_target_repo_thread_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_threads_target_repo DROP CONSTRAINT IF EXISTS discussion_threads_target_repo_repo_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_threads DROP CONSTRAINT IF EXISTS discussion_threads_target_repo_id_fk;
ALTER TABLE IF EXISTS ONLY discussion_threads DROP CONSTRAINT IF EXISTS discussion_threads_author_user_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_mail_reply_tokens DROP CONSTRAINT IF EXISTS discussion_mail_reply_tokens_user_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_mail_reply_tokens DROP CONSTRAINT IF EXISTS discussion_mail_reply_tokens_thread_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_comments DROP CONSTRAINT IF EXISTS discussion_comments_thread_id_fkey;
ALTER TABLE IF EXISTS ONLY discussion_comments DROP CONSTRAINT IF EXISTS discussion_comments_author_user_id_fkey;
ALTER TABLE IF EXISTS ONLY default_repos DROP CONSTRAINT IF EXISTS default_repos_repo_id_fkey;
ALTER TABLE IF EXISTS ONLY changesets DROP CONSTRAINT IF EXISTS changesets_repo_id_fkey;
ALTER TABLE IF EXISTS ONLY changeset_jobs DROP CONSTRAINT IF EXISTS changeset_jobs_changeset_id_fkey;
ALTER TABLE IF EXISTS ONLY changeset_jobs DROP CONSTRAINT IF EXISTS changeset_jobs_campaign_job_id_fkey;
ALTER TABLE IF EXISTS ONLY changeset_jobs DROP CONSTRAINT IF EXISTS changeset_jobs_campaign_id_fkey;
ALTER TABLE IF EXISTS ONLY changeset_events DROP CONSTRAINT IF EXISTS changeset_events_changeset_id_fkey;
ALTER TABLE IF EXISTS ONLY campaigns DROP CONSTRAINT IF EXISTS campaigns_namespace_user_id_fkey;
ALTER TABLE IF EXISTS ONLY campaigns DROP CONSTRAINT IF EXISTS campaigns_namespace_org_id_fkey;
ALTER TABLE IF EXISTS ONLY campaigns DROP CONSTRAINT IF EXISTS campaigns_campaign_plan_id_fkey;
ALTER TABLE IF EXISTS ONLY campaigns DROP CONSTRAINT IF EXISTS campaigns_author_id_fkey;
ALTER TABLE IF EXISTS ONLY campaign_jobs DROP CONSTRAINT IF EXISTS campaign_jobs_repo_id_fkey;
ALTER TABLE IF EXISTS ONLY campaign_jobs DROP CONSTRAINT IF EXISTS campaign_jobs_campaign_plan_id_fkey;
ALTER TABLE IF EXISTS ONLY access_tokens DROP CONSTRAINT IF EXISTS access_tokens_subject_user_id_fkey;
ALTER TABLE IF EXISTS ONLY access_tokens DROP CONSTRAINT IF EXISTS access_tokens_creator_user_id_fkey;
DROP TRIGGER IF EXISTS trig_validate_campaign_plan_is_finished ON campaigns;
DROP TRIGGER IF EXISTS trig_delete_changeset_reference_on_campaigns ON changesets;
DROP TRIGGER IF EXISTS trig_delete_campaign_reference_on_changesets ON campaigns;
DROP INDEX IF EXISTS users_username;
DROP INDEX IF EXISTS users_billing_customer_id;
DROP INDEX IF EXISTS user_external_accounts_account;
DROP INDEX IF EXISTS saved_queries_query_unique;
DROP INDEX IF EXISTS repo_uri_idx;
DROP INDEX IF EXISTS repo_sources_gin_idx;
DROP INDEX IF EXISTS repo_name_trgm;
DROP INDEX IF EXISTS repo_metadata_gin_idx;
DROP INDEX IF EXISTS repo_external_service_unique_idx;
DROP INDEX IF EXISTS registry_extensions_uuid;
DROP INDEX IF EXISTS registry_extensions_publisher_name;
DROP INDEX IF EXISTS registry_extension_releases_version;
DROP INDEX IF EXISTS registry_extension_releases_registry_extension_id;
DROP INDEX IF EXISTS orgs_name;
DROP INDEX IF EXISTS org_invitations_singleflight;
DROP INDEX IF EXISTS org_invitations_recipient_user_id;
DROP INDEX IF EXISTS org_invitations_org_id;
DROP INDEX IF EXISTS lsif_references_package;
DROP INDEX IF EXISTS lsif_packages_package_unique;
DROP INDEX IF EXISTS lsif_dumps_visible_repository_commit;
DROP INDEX IF EXISTS lsif_dumps_uploaded_at;
DROP INDEX IF EXISTS lsif_commits_repo_commit_parent_commit_unique;
DROP INDEX IF EXISTS lsif_commits_parent_commit;
DROP INDEX IF EXISTS event_logs_user_id;
DROP INDEX IF EXISTS event_logs_timestamp;
DROP INDEX IF EXISTS event_logs_name;
DROP INDEX IF EXISTS discussion_threads_target_repo_repo_id_path_idx;
DROP INDEX IF EXISTS discussion_threads_id_idx;
DROP INDEX IF EXISTS discussion_threads_author_user_id_idx;
DROP INDEX IF EXISTS discussion_mail_reply_tokens_user_id_thread_id_idx;
DROP INDEX IF EXISTS discussion_mail_reply_tokens_token_idx;
DROP INDEX IF EXISTS discussion_comments_thread_id_idx;
DROP INDEX IF EXISTS discussion_comments_reports_array_length_idx;
DROP INDEX IF EXISTS discussion_comments_author_user_id_idx;
DROP INDEX IF EXISTS critical_and_site_config_unique;
DROP INDEX IF EXISTS changeset_jobs_started_at;
DROP INDEX IF EXISTS changeset_jobs_finished_at;
DROP INDEX IF EXISTS changeset_jobs_error;
DROP INDEX IF EXISTS campaigns_namespace_user_id;
DROP INDEX IF EXISTS campaigns_namespace_org_id;
DROP INDEX IF EXISTS campaigns_changeset_ids_gin_idx;
DROP INDEX IF EXISTS campaign_jobs_started_at;
DROP INDEX IF EXISTS campaign_jobs_finished_at;
DROP INDEX IF EXISTS campaign_jobs_campaign_plan_id;
DROP INDEX IF EXISTS access_tokens_lookup;
ALTER TABLE IF EXISTS ONLY users DROP CONSTRAINT IF EXISTS users_pkey;
ALTER TABLE IF EXISTS ONLY user_permissions DROP CONSTRAINT IF EXISTS user_permissions_perm_object_unique;
ALTER TABLE IF EXISTS ONLY user_external_accounts DROP CONSTRAINT IF EXISTS user_external_accounts_pkey;
ALTER TABLE IF EXISTS ONLY user_emails DROP CONSTRAINT IF EXISTS user_emails_unique_verified_email;
ALTER TABLE IF EXISTS ONLY user_emails DROP CONSTRAINT IF EXISTS user_emails_no_duplicates_per_user;
ALTER TABLE IF EXISTS ONLY survey_responses DROP CONSTRAINT IF EXISTS survey_responses_pkey;
ALTER TABLE IF EXISTS ONLY settings DROP CONSTRAINT IF EXISTS settings_pkey;
ALTER TABLE IF EXISTS ONLY schema_migrations DROP CONSTRAINT IF EXISTS schema_migrations_pkey;
ALTER TABLE IF EXISTS ONLY saved_searches DROP CONSTRAINT IF EXISTS saved_searches_pkey;
ALTER TABLE IF EXISTS ONLY repo DROP CONSTRAINT IF EXISTS repo_pkey;
ALTER TABLE IF EXISTS ONLY repo DROP CONSTRAINT IF EXISTS repo_name_unique;
ALTER TABLE IF EXISTS ONLY registry_extensions DROP CONSTRAINT IF EXISTS registry_extensions_pkey;
ALTER TABLE IF EXISTS ONLY registry_extension_releases DROP CONSTRAINT IF EXISTS registry_extension_releases_pkey;
ALTER TABLE IF EXISTS ONLY product_subscriptions DROP CONSTRAINT IF EXISTS product_subscriptions_pkey;
ALTER TABLE IF EXISTS ONLY product_licenses DROP CONSTRAINT IF EXISTS product_licenses_pkey;
ALTER TABLE IF EXISTS ONLY phabricator_repos DROP CONSTRAINT IF EXISTS phabricator_repos_repo_name_key;
ALTER TABLE IF EXISTS ONLY phabricator_repos DROP CONSTRAINT IF EXISTS phabricator_repos_pkey;
ALTER TABLE IF EXISTS ONLY orgs DROP CONSTRAINT IF EXISTS orgs_pkey;
ALTER TABLE IF EXISTS ONLY org_members DROP CONSTRAINT IF EXISTS org_members_pkey;
ALTER TABLE IF EXISTS ONLY org_members DROP CONSTRAINT IF EXISTS org_members_org_id_user_id_key;
ALTER TABLE IF EXISTS ONLY org_invitations DROP CONSTRAINT IF EXISTS org_invitations_pkey;
ALTER TABLE IF EXISTS ONLY names DROP CONSTRAINT IF EXISTS names_pkey;
ALTER TABLE IF EXISTS ONLY lsif_references DROP CONSTRAINT IF EXISTS lsif_references_pkey;
ALTER TABLE IF EXISTS ONLY lsif_packages DROP CONSTRAINT IF EXISTS lsif_packages_pkey;
ALTER TABLE IF EXISTS ONLY lsif_dumps DROP CONSTRAINT IF EXISTS lsif_dumps_repository_commit_root;
ALTER TABLE IF EXISTS ONLY lsif_dumps DROP CONSTRAINT IF EXISTS lsif_dumps_pkey;
ALTER TABLE IF EXISTS ONLY lsif_commits DROP CONSTRAINT IF EXISTS lsif_commits_pkey;
ALTER TABLE IF EXISTS ONLY global_state DROP CONSTRAINT IF EXISTS global_state_pkey;
ALTER TABLE IF EXISTS ONLY external_services DROP CONSTRAINT IF EXISTS external_services_pkey;
ALTER TABLE IF EXISTS ONLY event_logs DROP CONSTRAINT IF EXISTS event_logs_pkey;
ALTER TABLE IF EXISTS ONLY discussion_threads_target_repo DROP CONSTRAINT IF EXISTS discussion_threads_target_repo_pkey;
ALTER TABLE IF EXISTS ONLY discussion_threads DROP CONSTRAINT IF EXISTS discussion_threads_pkey;
ALTER TABLE IF EXISTS ONLY discussion_mail_reply_tokens DROP CONSTRAINT IF EXISTS discussion_mail_reply_tokens_pkey;
ALTER TABLE IF EXISTS ONLY discussion_comments DROP CONSTRAINT IF EXISTS discussion_comments_pkey;
ALTER TABLE IF EXISTS ONLY default_repos DROP CONSTRAINT IF EXISTS default_repos_pkey;
ALTER TABLE IF EXISTS ONLY critical_and_site_config DROP CONSTRAINT IF EXISTS critical_and_site_config_pkey;
ALTER TABLE IF EXISTS ONLY changesets DROP CONSTRAINT IF EXISTS changesets_repo_external_id_unique;
ALTER TABLE IF EXISTS ONLY changesets DROP CONSTRAINT IF EXISTS changesets_pkey;
ALTER TABLE IF EXISTS ONLY changeset_jobs DROP CONSTRAINT IF EXISTS changeset_jobs_unique;
ALTER TABLE IF EXISTS ONLY changeset_jobs DROP CONSTRAINT IF EXISTS changeset_jobs_pkey;
ALTER TABLE IF EXISTS ONLY changeset_events DROP CONSTRAINT IF EXISTS changeset_events_pkey;
ALTER TABLE IF EXISTS ONLY changeset_events DROP CONSTRAINT IF EXISTS changeset_events_changeset_id_kind_key_unique;
ALTER TABLE IF EXISTS ONLY campaigns DROP CONSTRAINT IF EXISTS campaigns_pkey;
ALTER TABLE IF EXISTS ONLY campaign_plans DROP CONSTRAINT IF EXISTS campaign_plans_pkey;
ALTER TABLE IF EXISTS ONLY campaign_jobs DROP CONSTRAINT IF EXISTS campaign_jobs_pkey;
ALTER TABLE IF EXISTS ONLY campaign_jobs DROP CONSTRAINT IF EXISTS campaign_jobs_campaign_plan_repo_rev_unique;
ALTER TABLE IF EXISTS ONLY access_tokens DROP CONSTRAINT IF EXISTS access_tokens_value_sha256_key;
ALTER TABLE IF EXISTS ONLY access_tokens DROP CONSTRAINT IF EXISTS access_tokens_pkey;
ALTER TABLE IF EXISTS users ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS user_external_accounts ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS survey_responses ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS settings ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS saved_searches ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS repo ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS registry_extensions ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS registry_extension_releases ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS phabricator_repos ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS orgs ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS org_members ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS org_invitations ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS lsif_references ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS lsif_packages ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS lsif_dumps ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS lsif_commits ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS external_services ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS event_logs ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS discussion_threads_target_repo ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS discussion_threads ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS discussion_comments ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS critical_and_site_config ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS changesets ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS changeset_jobs ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS changeset_events ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS campaigns ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS campaign_plans ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS campaign_jobs ALTER COLUMN id DROP DEFAULT;
ALTER TABLE IF EXISTS access_tokens ALTER COLUMN id DROP DEFAULT;
DROP SEQUENCE IF EXISTS users_id_seq;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS user_permissions;
DROP SEQUENCE IF EXISTS user_external_accounts_id_seq;
DROP TABLE IF EXISTS user_external_accounts;
DROP TABLE IF EXISTS user_emails;
DROP SEQUENCE IF EXISTS survey_responses_id_seq;
DROP TABLE IF EXISTS survey_responses;
DROP VIEW IF EXISTS site_config;
DROP SEQUENCE IF EXISTS settings_id_seq;
DROP TABLE IF EXISTS settings_bkup_1514702776;
DROP TABLE IF EXISTS settings;
DROP TABLE IF EXISTS schema_migrations;
DROP SEQUENCE IF EXISTS saved_searches_id_seq;
DROP TABLE IF EXISTS saved_searches;
DROP TABLE IF EXISTS saved_queries;
DROP SEQUENCE IF EXISTS repo_id_seq;
DROP TABLE IF EXISTS repo;
DROP SEQUENCE IF EXISTS registry_extensions_id_seq;
DROP TABLE IF EXISTS registry_extensions;
DROP SEQUENCE IF EXISTS registry_extension_releases_id_seq;
DROP TABLE IF EXISTS registry_extension_releases;
DROP TABLE IF EXISTS query_runner_state;
DROP TABLE IF EXISTS product_subscriptions;
DROP TABLE IF EXISTS product_licenses;
DROP SEQUENCE IF EXISTS phabricator_repos_id_seq;
DROP TABLE IF EXISTS phabricator_repos;
DROP SEQUENCE IF EXISTS orgs_id_seq;
DROP TABLE IF EXISTS orgs;
DROP SEQUENCE IF EXISTS org_members_id_seq;
DROP TABLE IF EXISTS org_members_bkup_1514536731;
DROP TABLE IF EXISTS org_members;
DROP SEQUENCE IF EXISTS org_invitations_id_seq;
DROP TABLE IF EXISTS org_invitations;
DROP TABLE IF EXISTS names;
DROP SEQUENCE IF EXISTS lsif_references_id_seq;
DROP TABLE IF EXISTS lsif_references;
DROP SEQUENCE IF EXISTS lsif_packages_id_seq;
DROP TABLE IF EXISTS lsif_packages;
DROP SEQUENCE IF EXISTS lsif_dumps_id_seq;
DROP SEQUENCE IF EXISTS lsif_commits_id_seq;
DROP TABLE IF EXISTS lsif_commits;
DROP TABLE IF EXISTS global_state;
DROP SEQUENCE IF EXISTS external_services_id_seq;
DROP TABLE IF EXISTS external_services;
DROP SEQUENCE IF EXISTS event_logs_id_seq;
DROP TABLE IF EXISTS event_logs;
DROP SEQUENCE IF EXISTS discussion_threads_target_repo_id_seq;
DROP TABLE IF EXISTS discussion_threads_target_repo;
DROP SEQUENCE IF EXISTS discussion_threads_id_seq;
DROP TABLE IF EXISTS discussion_threads;
DROP TABLE IF EXISTS discussion_mail_reply_tokens;
DROP SEQUENCE IF EXISTS discussion_comments_id_seq;
DROP TABLE IF EXISTS discussion_comments;
DROP TABLE IF EXISTS default_repos;
DROP SEQUENCE IF EXISTS critical_and_site_config_id_seq;
DROP TABLE IF EXISTS critical_and_site_config;
DROP SEQUENCE IF EXISTS changesets_id_seq;
DROP TABLE IF EXISTS changesets;
DROP SEQUENCE IF EXISTS changeset_jobs_id_seq;
DROP TABLE IF EXISTS changeset_jobs;
DROP SEQUENCE IF EXISTS changeset_events_id_seq;
DROP TABLE IF EXISTS changeset_events;
DROP SEQUENCE IF EXISTS campaigns_id_seq;
DROP TABLE IF EXISTS campaigns;
DROP SEQUENCE IF EXISTS campaign_plans_id_seq;
DROP TABLE IF EXISTS campaign_plans;
DROP SEQUENCE IF EXISTS campaign_jobs_id_seq;
DROP TABLE IF EXISTS campaign_jobs;
DROP SEQUENCE IF EXISTS access_tokens_id_seq;
DROP TABLE IF EXISTS access_tokens;
DROP FUNCTION IF EXISTS validate_campaign_plan_is_finished();
DROP FUNCTION IF EXISTS delete_changeset_reference_on_campaigns();
DROP FUNCTION IF EXISTS delete_campaign_reference_on_changesets();
DROP FUNCTION IF EXISTS closest_dump(repository text, commit text, path text, traversal_limit integer);
DROP TABLE IF EXISTS lsif_dumps;
DROP TYPE IF EXISTS critical_or_site;
CREATE EXTENSION IF NOT EXISTS citext;
CREATE EXTENSION IF NOT EXISTS hstore;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE TYPE critical_or_site AS ENUM (
'critical',
'site'
);
CREATE TABLE lsif_dumps (
id integer NOT NULL,
repository text NOT NULL,
commit text NOT NULL,
root text DEFAULT ''::text NOT NULL,
visible_at_tip boolean DEFAULT false NOT NULL,
processed_at timestamp with time zone DEFAULT now() NOT NULL,
uploaded_at timestamp with time zone NOT NULL,
CONSTRAINT lsif_dumps_commit_valid_chars CHECK ((commit ~ '^[a-z0-9]{40}$'::text)),
CONSTRAINT lsif_dumps_repository_check CHECK ((repository <> ''::text))
);
CREATE FUNCTION closest_dump(repository text, commit text, path text, traversal_limit integer) RETURNS SETOF lsif_dumps
LANGUAGE plpgsql
AS $_$
DECLARE
lineage_row record; -- lineage rows
i float4 := 0; -- traversal counter
found_dump lsif_dumps%ROWTYPE; -- lsif dump row (returned)
BEGIN
FOR lineage_row IN
-- lineage is a recursively defined CTE that returns all ancestor an descendants
-- of the given commit for the given repository. This happens to evaluate in
-- Postgres as a lazy generator, which allows us to pull the "next" closest commit
-- in either direction from the source commit as needed.
WITH RECURSIVE lineage(id, repository, "commit", parent_commit, direction) AS (
SELECT l.* FROM (
-- seed recursive set with commit looking in ancestor direction
SELECT c.*, 'A' FROM lsif_commits c WHERE c.repository = $1 AND c."commit" = $2
UNION
-- seed recursive set with commit looking in descendant direction
SELECT c.*, 'D' FROM lsif_commits c WHERE c.repository = $1 AND c."commit" = $2
) l
UNION
SELECT * FROM (
WITH l_inner AS (SELECT * FROM lineage)
-- get next ancestor
SELECT c.*, l.direction FROM l_inner l JOIN lsif_commits c ON l.direction = 'A' AND c.repository = l.repository AND c."commit" = l.parent_commit
UNION
-- get next descendant
SELECT c.*, l.direction FROM l_inner l JOIN lsif_commits c ON l.direction = 'D' and c.repository = l.repository AND c.parent_commit = l."commit"
) subquery
)
SELECT * FROM lineage l
LOOP
-- Keep track of how many rows we pull from lineage. If we hit the traversal
-- limit, bail out now and return an empty row. Don't keep looking for a closest
-- commit forever, as the farther we travel the more likely it is to be imprecise.
i := i + 1;
IF i > $4 THEN
RETURN;
END IF;
-- Try to find the dump associated with this commit. If there is something
-- return it and end the function. This will end up returning the first row
-- we get from lineage with LSIF data which, as we pull rows back from
-- lineage in order of distance from the source commit, it is necessarily
-- the closest commit with LSIF data.
SELECT dump.* INTO found_dump FROM lsif_dumps dump WHERE dump.repository = lineage_row.repository AND dump.commit = lineage_row.commit AND $3 LIKE (dump.root || '%');
IF found_dump.id IS NOT NULL THEN
RETURN NEXT found_dump; -- return row
RETURN; -- exit function
END IF;
END LOOP;
END;
$_$;
CREATE FUNCTION delete_campaign_reference_on_changesets() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE
changesets
SET
campaign_ids = changesets.campaign_ids - OLD.id::text
WHERE
changesets.campaign_ids ? OLD.id::text;
RETURN OLD;
END;
$$;
CREATE FUNCTION delete_changeset_reference_on_campaigns() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
UPDATE
campaigns
SET
changeset_ids = campaigns.changeset_ids - OLD.id::text
WHERE
campaigns.changeset_ids ? OLD.id::text;
RETURN OLD;
END;
$$;
CREATE FUNCTION validate_campaign_plan_is_finished() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
running int;
BEGIN
running := (
SELECT COUNT(*) FROM campaign_jobs
WHERE campaign_plan_id = NEW.campaign_plan_id
AND finished_at IS NULL
);
IF (running != 0) THEN
RAISE EXCEPTION 'CampaignPlan{ID: %} has % unfinished jobs',
NEW.campaign_plan_id, running;
END IF;
RETURN NEW;
END;
$$;
CREATE TABLE access_tokens (
id bigint NOT NULL,
subject_user_id integer NOT NULL,
value_sha256 bytea NOT NULL,
note text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
last_used_at timestamp with time zone,
deleted_at timestamp with time zone,
creator_user_id integer NOT NULL,
scopes text[] NOT NULL
);
CREATE SEQUENCE access_tokens_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE access_tokens_id_seq OWNED BY access_tokens.id;
CREATE TABLE campaign_jobs (
id bigint NOT NULL,
campaign_plan_id bigint NOT NULL,
repo_id bigint NOT NULL,
rev text NOT NULL,
diff text NOT NULL,
error text NOT NULL,
started_at timestamp with time zone,
finished_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
base_ref text NOT NULL,
CONSTRAINT campaign_jobs_base_ref_check CHECK ((base_ref <> ''::text))
);
CREATE SEQUENCE campaign_jobs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE campaign_jobs_id_seq OWNED BY campaign_jobs.id;
CREATE TABLE campaign_plans (
id bigint NOT NULL,
campaign_type text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
arguments text NOT NULL,
CONSTRAINT campaign_plans_campaign_type_check CHECK ((campaign_type <> ''::text))
);
CREATE SEQUENCE campaign_plans_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE campaign_plans_id_seq OWNED BY campaign_plans.id;
CREATE TABLE campaigns (
id bigint NOT NULL,
name text NOT NULL,
description text,
author_id integer NOT NULL,
namespace_user_id integer,
namespace_org_id integer,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
changeset_ids jsonb DEFAULT '{}'::jsonb NOT NULL,
campaign_plan_id integer,
CONSTRAINT campaigns_changeset_ids_check CHECK ((jsonb_typeof(changeset_ids) = 'object'::text)),
CONSTRAINT campaigns_has_1_namespace CHECK (((namespace_user_id IS NULL) <> (namespace_org_id IS NULL)))
);
CREATE SEQUENCE campaigns_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE campaigns_id_seq OWNED BY campaigns.id;
CREATE TABLE changeset_events (
id bigint NOT NULL,
changeset_id bigint NOT NULL,
kind text NOT NULL,
key text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT changeset_events_key_check CHECK ((key <> ''::text)),
CONSTRAINT changeset_events_kind_check CHECK ((kind <> ''::text)),
CONSTRAINT changeset_events_metadata_check CHECK ((jsonb_typeof(metadata) = 'object'::text))
);
CREATE SEQUENCE changeset_events_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE changeset_events_id_seq OWNED BY changeset_events.id;
CREATE TABLE changeset_jobs (
id bigint NOT NULL,
campaign_id bigint NOT NULL,
campaign_job_id bigint NOT NULL,
changeset_id bigint,
error text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
started_at timestamp with time zone,
finished_at timestamp with time zone
);
CREATE SEQUENCE changeset_jobs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE changeset_jobs_id_seq OWNED BY changeset_jobs.id;
CREATE TABLE changesets (
id bigint NOT NULL,
campaign_ids jsonb DEFAULT '{}'::jsonb NOT NULL,
repo_id integer NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
external_id text NOT NULL,
external_service_type text NOT NULL,
CONSTRAINT changesets_campaign_ids_check CHECK ((jsonb_typeof(campaign_ids) = 'object'::text)),
CONSTRAINT changesets_external_id_check CHECK ((external_id <> ''::text)),
CONSTRAINT changesets_external_service_type_not_blank CHECK ((external_service_type <> ''::text)),
CONSTRAINT changesets_metadata_check CHECK ((jsonb_typeof(metadata) = 'object'::text))
);
CREATE SEQUENCE changesets_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE changesets_id_seq OWNED BY changesets.id;
CREATE TABLE critical_and_site_config (
id integer NOT NULL,
type critical_or_site NOT NULL,
contents text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);
CREATE SEQUENCE critical_and_site_config_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE critical_and_site_config_id_seq OWNED BY critical_and_site_config.id;
CREATE TABLE default_repos (
repo_id integer NOT NULL
);
CREATE TABLE discussion_comments (
id bigint NOT NULL,
thread_id bigint NOT NULL,
author_user_id integer NOT NULL,
contents text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone,
reports text[] DEFAULT '{}'::text[] NOT NULL
);
CREATE SEQUENCE discussion_comments_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE discussion_comments_id_seq OWNED BY discussion_comments.id;
CREATE TABLE discussion_mail_reply_tokens (
token text NOT NULL,
user_id integer NOT NULL,
thread_id bigint NOT NULL,
deleted_at timestamp with time zone
);
CREATE TABLE discussion_threads (
id bigint NOT NULL,
author_user_id integer NOT NULL,
title text,
target_repo_id bigint,
created_at timestamp with time zone DEFAULT now() NOT NULL,
archived_at timestamp with time zone,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone
);
CREATE SEQUENCE discussion_threads_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE discussion_threads_id_seq OWNED BY discussion_threads.id;
CREATE TABLE discussion_threads_target_repo (
id bigint NOT NULL,
thread_id bigint NOT NULL,
repo_id integer NOT NULL,
path text,
branch text,
revision text,
start_line integer,
end_line integer,
start_character integer,
end_character integer,
lines_before text,
lines text,
lines_after text
);
CREATE SEQUENCE discussion_threads_target_repo_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE discussion_threads_target_repo_id_seq OWNED BY discussion_threads_target_repo.id;
CREATE TABLE event_logs (
id bigint NOT NULL,
name text NOT NULL,
url text NOT NULL,
user_id integer NOT NULL,
anonymous_user_id text NOT NULL,
source text NOT NULL,
argument text NOT NULL,
version text NOT NULL,
"timestamp" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT event_logs_check_has_user CHECK ((((user_id = 0) AND (anonymous_user_id <> ''::text)) OR ((user_id <> 0) AND (anonymous_user_id = ''::text)) OR ((user_id <> 0) AND (anonymous_user_id <> ''::text)))),
CONSTRAINT event_logs_check_name_not_empty CHECK ((name <> ''::text)),
CONSTRAINT event_logs_check_source_not_empty CHECK ((source <> ''::text)),
CONSTRAINT event_logs_check_url_not_empty CHECK ((url <> ''::text)),
CONSTRAINT event_logs_check_version_not_empty CHECK ((version <> ''::text))
);
CREATE SEQUENCE event_logs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE event_logs_id_seq OWNED BY event_logs.id;
CREATE TABLE external_services (
id bigint NOT NULL,
kind text NOT NULL,
display_name text NOT NULL,
config text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone,
CONSTRAINT check_non_empty_config CHECK ((btrim(config) <> ''::text))
);
CREATE SEQUENCE external_services_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE external_services_id_seq OWNED BY external_services.id;
CREATE TABLE global_state (
site_id uuid NOT NULL,
initialized boolean DEFAULT false NOT NULL,
mgmt_password_plaintext text DEFAULT ''::text NOT NULL,
mgmt_password_bcrypt text DEFAULT ''::text NOT NULL
);
CREATE TABLE lsif_commits (
id integer NOT NULL,
repository text NOT NULL,
commit text NOT NULL,
parent_commit text,
CONSTRAINT lsif_commits_commit_valid_chars CHECK ((commit ~ '^[a-z0-9]{40}$'::text)),
CONSTRAINT lsif_commits_parent_commit_valid_chars CHECK ((parent_commit ~ '^[a-z0-9]{40}$'::text))
);
CREATE SEQUENCE lsif_commits_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE lsif_commits_id_seq OWNED BY lsif_commits.id;
CREATE SEQUENCE lsif_dumps_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE lsif_dumps_id_seq OWNED BY lsif_dumps.id;
CREATE TABLE lsif_packages (
id integer NOT NULL,
scheme text NOT NULL,
name text NOT NULL,
version text,
dump_id integer NOT NULL
);
CREATE SEQUENCE lsif_packages_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE lsif_packages_id_seq OWNED BY lsif_packages.id;
CREATE TABLE lsif_references (
id integer NOT NULL,
scheme text NOT NULL,
name text NOT NULL,
version text,
filter bytea NOT NULL,
dump_id integer NOT NULL
);
CREATE SEQUENCE lsif_references_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE lsif_references_id_seq OWNED BY lsif_references.id;
CREATE TABLE names (
name citext NOT NULL,
user_id integer,
org_id integer,
CONSTRAINT names_check CHECK (((user_id IS NOT NULL) OR (org_id IS NOT NULL)))
);
CREATE TABLE org_invitations (
id bigint NOT NULL,
org_id integer NOT NULL,
sender_user_id integer NOT NULL,
recipient_user_id integer NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
notified_at timestamp with time zone,
responded_at timestamp with time zone,
response_type boolean,
revoked_at timestamp with time zone,
deleted_at timestamp with time zone,
CONSTRAINT check_atomic_response CHECK (((responded_at IS NULL) = (response_type IS NULL))),
CONSTRAINT check_single_use CHECK ((((responded_at IS NULL) AND (response_type IS NULL)) OR (revoked_at IS NULL)))
);
CREATE SEQUENCE org_invitations_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE org_invitations_id_seq OWNED BY org_invitations.id;
CREATE TABLE org_members (
id integer NOT NULL,
org_id integer NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
user_id integer NOT NULL
);
CREATE TABLE org_members_bkup_1514536731 (
id integer,
org_id integer,
user_id_old text,
created_at timestamp with time zone,
updated_at timestamp with time zone,
user_id integer
);
CREATE SEQUENCE org_members_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE org_members_id_seq OWNED BY org_members.id;
CREATE TABLE orgs (
id integer NOT NULL,
name citext NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
display_name text,
slack_webhook_url text,
deleted_at timestamp with time zone,
CONSTRAINT orgs_display_name_max_length CHECK ((char_length(display_name) <= 255)),
CONSTRAINT orgs_name_max_length CHECK ((char_length((name)::text) <= 255)),
CONSTRAINT orgs_name_valid_chars CHECK ((name OPERATOR(~) '^[a-zA-Z0-9](?:[a-zA-Z0-9]|[-.](?=[a-zA-Z0-9]))*-?$'::citext))
);
CREATE SEQUENCE orgs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE orgs_id_seq OWNED BY orgs.id;
CREATE TABLE phabricator_repos (
id integer NOT NULL,
callsign citext NOT NULL,
repo_name citext NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone,
url text DEFAULT ''::text NOT NULL
);
CREATE SEQUENCE phabricator_repos_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE phabricator_repos_id_seq OWNED BY phabricator_repos.id;
CREATE TABLE product_licenses (
id uuid NOT NULL,
product_subscription_id uuid NOT NULL,
license_key text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
CREATE TABLE product_subscriptions (
id uuid NOT NULL,
user_id integer NOT NULL,
billing_subscription_id text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
archived_at timestamp with time zone
);
CREATE TABLE query_runner_state (
query text,
last_executed timestamp with time zone,
latest_result timestamp with time zone,
exec_duration_ns bigint
);
CREATE TABLE registry_extension_releases (
id bigint NOT NULL,
registry_extension_id integer NOT NULL,
creator_user_id integer NOT NULL,
release_version citext,
release_tag citext NOT NULL,
manifest jsonb NOT NULL,
bundle text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone,
source_map text
);
CREATE SEQUENCE registry_extension_releases_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE registry_extension_releases_id_seq OWNED BY registry_extension_releases.id;
CREATE TABLE registry_extensions (
id integer NOT NULL,
uuid uuid NOT NULL,
publisher_user_id integer,
publisher_org_id integer,
name citext NOT NULL,
manifest text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
deleted_at timestamp with time zone,
CONSTRAINT registry_extensions_name_length CHECK (((char_length((name)::text) > 0) AND (char_length((name)::text) <= 128))),
CONSTRAINT registry_extensions_name_valid_chars CHECK ((name OPERATOR(~) '^[a-zA-Z0-9](?:[a-zA-Z0-9]|[_.-](?=[a-zA-Z0-9]))*$'::citext)),
CONSTRAINT registry_extensions_single_publisher CHECK (((publisher_user_id IS NULL) <> (publisher_org_id IS NULL)))
);
CREATE SEQUENCE registry_extensions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE registry_extensions_id_seq OWNED BY registry_extensions.id;
CREATE TABLE repo (
id integer NOT NULL,
name citext NOT NULL,
description text,
language text,
fork boolean,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone,
external_id text,
external_service_type text,
external_service_id text,
enabled boolean DEFAULT true NOT NULL,
archived boolean DEFAULT false NOT NULL,
uri citext,
deleted_at timestamp with time zone,
sources jsonb DEFAULT '{}'::jsonb NOT NULL,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
CONSTRAINT check_name_nonempty CHECK ((name OPERATOR(<>) ''::citext)),
CONSTRAINT deleted_at_unused CHECK ((deleted_at IS NULL)),
CONSTRAINT repo_metadata_check CHECK ((jsonb_typeof(metadata) = 'object'::text)),
CONSTRAINT repo_sources_check CHECK ((jsonb_typeof(sources) = 'object'::text))
);
CREATE SEQUENCE repo_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE repo_id_seq OWNED BY repo.id;
CREATE TABLE saved_queries (
query text NOT NULL,
last_executed timestamp with time zone NOT NULL,
latest_result timestamp with time zone NOT NULL,
exec_duration_ns bigint NOT NULL
);
CREATE TABLE saved_searches (
id integer NOT NULL,
description text NOT NULL,
query text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
notify_owner boolean NOT NULL,
notify_slack boolean NOT NULL,
user_id integer,
org_id integer,
slack_webhook_url text,
CONSTRAINT user_or_org_id_not_null CHECK ((((user_id IS NOT NULL) AND (org_id IS NULL)) OR ((org_id IS NOT NULL) AND (user_id IS NULL))))
);
CREATE SEQUENCE saved_searches_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE saved_searches_id_seq OWNED BY saved_searches.id;
CREATE TABLE schema_migrations (
version bigint NOT NULL,
dirty boolean NOT NULL
);
CREATE TABLE settings (
id integer NOT NULL,
org_id integer,
contents text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
user_id integer,
author_user_id integer
);
CREATE TABLE settings_bkup_1514702776 (
id integer,
org_id integer,
author_user_id_old text,
contents text,
created_at timestamp with time zone,
user_id integer,
author_user_id integer
);
CREATE SEQUENCE settings_id_seq
START WITH 1