github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/db/migration/migrations/1510262030_initial_schema.up.sql (about) 1 BEGIN; 2 3 CREATE TYPE build_status AS ENUM ( 4 'pending', 5 'started', 6 'aborted', 7 'succeeded', 8 'failed', 9 'errored' 10 ); 11 12 13 14 CREATE TYPE container_stage AS ENUM ( 15 'check', 16 'get', 17 'run' 18 ); 19 20 21 22 CREATE TYPE container_state AS ENUM ( 23 'creating', 24 'created', 25 'destroying', 26 'failed' 27 ); 28 29 30 31 CREATE TYPE container_state_old AS ENUM ( 32 'creating', 33 'created', 34 'destroying' 35 ); 36 37 38 39 CREATE TYPE volume_state AS ENUM ( 40 'creating', 41 'created', 42 'destroying', 43 'failed' 44 ); 45 46 47 48 CREATE TYPE volume_state_old AS ENUM ( 49 'creating', 50 'created', 51 'destroying' 52 ); 53 54 55 56 CREATE TYPE worker_state AS ENUM ( 57 'running', 58 'stalled', 59 'landing', 60 'landed', 61 'retiring' 62 ); 63 64 65 CREATE TABLE base_resource_types ( 66 id integer NOT NULL, 67 name text NOT NULL 68 ); 69 70 71 72 CREATE SEQUENCE base_resource_types_id_seq 73 START WITH 1 74 INCREMENT BY 1 75 NO MINVALUE 76 NO MAXVALUE 77 CACHE 1; 78 79 80 81 ALTER SEQUENCE base_resource_types_id_seq OWNED BY base_resource_types.id; 82 83 84 85 CREATE TABLE build_events ( 86 build_id integer, 87 type character varying(32) NOT NULL, 88 payload text NOT NULL, 89 event_id integer NOT NULL, 90 version text NOT NULL 91 ); 92 93 94 95 CREATE TABLE build_image_resource_caches ( 96 resource_cache_id integer, 97 build_id integer NOT NULL 98 ); 99 100 101 102 CREATE TABLE build_inputs ( 103 build_id integer, 104 versioned_resource_id integer, 105 name text NOT NULL, 106 modified_time timestamp without time zone DEFAULT now() NOT NULL 107 ); 108 109 110 111 CREATE TABLE build_outputs ( 112 build_id integer, 113 versioned_resource_id integer, 114 explicit boolean DEFAULT false NOT NULL, 115 modified_time timestamp without time zone DEFAULT now() NOT NULL 116 ); 117 118 119 120 CREATE TABLE builds ( 121 id integer NOT NULL, 122 name text NOT NULL, 123 status build_status NOT NULL, 124 scheduled boolean DEFAULT false NOT NULL, 125 start_time timestamp with time zone, 126 end_time timestamp with time zone, 127 engine character varying(16), 128 engine_metadata text, 129 completed boolean DEFAULT false NOT NULL, 130 job_id integer, 131 reap_time timestamp with time zone, 132 team_id integer NOT NULL, 133 manually_triggered boolean DEFAULT false, 134 interceptible boolean DEFAULT true, 135 nonce text, 136 public_plan json DEFAULT '{}'::json, 137 pipeline_id integer 138 ); 139 140 141 142 CREATE SEQUENCE builds_id_seq 143 START WITH 1 144 INCREMENT BY 1 145 NO MINVALUE 146 NO MAXVALUE 147 CACHE 1; 148 149 150 151 ALTER SEQUENCE builds_id_seq OWNED BY builds.id; 152 153 154 155 CREATE TABLE cache_invalidator ( 156 last_invalidated timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL 157 ); 158 159 160 161 CREATE SEQUENCE config_version_seq 162 START WITH 1 163 INCREMENT BY 1 164 NO MINVALUE 165 NO MAXVALUE 166 CACHE 1; 167 168 169 170 CREATE TABLE containers ( 171 handle text NOT NULL, 172 build_id integer, 173 plan_id text, 174 pipeline_id integer, 175 resource_id integer, 176 worker_name text, 177 best_if_used_by timestamp without time zone, 178 id integer NOT NULL, 179 team_id integer, 180 state container_state DEFAULT 'creating'::container_state NOT NULL, 181 hijacked boolean DEFAULT false NOT NULL, 182 discontinued boolean DEFAULT false NOT NULL, 183 meta_type text DEFAULT ''::text NOT NULL, 184 meta_step_name text DEFAULT ''::text NOT NULL, 185 meta_attempt text DEFAULT ''::text NOT NULL, 186 meta_working_directory text DEFAULT ''::text NOT NULL, 187 meta_process_user text DEFAULT ''::text NOT NULL, 188 meta_pipeline_id integer DEFAULT 0 NOT NULL, 189 meta_job_id integer DEFAULT 0 NOT NULL, 190 meta_build_id integer DEFAULT 0 NOT NULL, 191 meta_pipeline_name text DEFAULT ''::text NOT NULL, 192 meta_job_name text DEFAULT ''::text NOT NULL, 193 meta_build_name text DEFAULT ''::text NOT NULL, 194 image_check_container_id integer, 195 image_get_container_id integer, 196 worker_resource_config_check_session_id integer 197 ); 198 199 200 201 CREATE SEQUENCE containers_id_seq 202 START WITH 1 203 INCREMENT BY 1 204 NO MINVALUE 205 NO MAXVALUE 206 CACHE 1; 207 208 209 210 ALTER SEQUENCE containers_id_seq OWNED BY containers.id; 211 212 213 214 CREATE TABLE independent_build_inputs ( 215 id integer NOT NULL, 216 job_id integer NOT NULL, 217 input_name text NOT NULL, 218 version_id integer NOT NULL, 219 first_occurrence boolean NOT NULL 220 ); 221 222 223 224 CREATE SEQUENCE independent_build_inputs_id_seq 225 START WITH 1 226 INCREMENT BY 1 227 NO MINVALUE 228 NO MAXVALUE 229 CACHE 1; 230 231 232 233 ALTER SEQUENCE independent_build_inputs_id_seq OWNED BY independent_build_inputs.id; 234 235 236 237 CREATE TABLE jobs ( 238 name text NOT NULL, 239 build_number_seq integer DEFAULT 0 NOT NULL, 240 paused boolean DEFAULT false, 241 id integer NOT NULL, 242 pipeline_id integer NOT NULL, 243 first_logged_build_id integer DEFAULT 0 NOT NULL, 244 inputs_determined boolean DEFAULT false NOT NULL, 245 max_in_flight_reached boolean DEFAULT false NOT NULL, 246 config text NOT NULL, 247 active boolean DEFAULT false NOT NULL, 248 interruptible boolean DEFAULT false NOT NULL, 249 nonce text 250 ); 251 252 253 254 CREATE SEQUENCE jobs_id_seq 255 START WITH 1 256 INCREMENT BY 1 257 NO MINVALUE 258 NO MAXVALUE 259 CACHE 1; 260 261 262 263 ALTER SEQUENCE jobs_id_seq OWNED BY jobs.id; 264 265 266 267 CREATE TABLE jobs_serial_groups ( 268 id integer NOT NULL, 269 serial_group text NOT NULL, 270 job_id integer 271 ); 272 273 274 275 CREATE SEQUENCE jobs_serial_groups_id_seq 276 START WITH 1 277 INCREMENT BY 1 278 NO MINVALUE 279 NO MAXVALUE 280 CACHE 1; 281 282 283 284 ALTER SEQUENCE jobs_serial_groups_id_seq OWNED BY jobs_serial_groups.id; 285 286 287 288 CREATE MATERIALIZED VIEW latest_completed_builds_per_job AS 289 WITH latest_build_ids_per_job AS ( 290 SELECT max(b_1.id) AS build_id 291 FROM (builds b_1 292 JOIN jobs j ON ((j.id = b_1.job_id))) 293 WHERE (b_1.status <> ALL (ARRAY['pending'::build_status, 'started'::build_status])) 294 GROUP BY b_1.job_id 295 ) 296 SELECT b.id, 297 b.name, 298 b.status, 299 b.scheduled, 300 b.start_time, 301 b.end_time, 302 b.engine, 303 b.engine_metadata, 304 b.completed, 305 b.job_id, 306 b.reap_time, 307 b.team_id, 308 b.manually_triggered, 309 b.interceptible, 310 b.nonce, 311 b.public_plan, 312 b.pipeline_id 313 FROM (builds b 314 JOIN latest_build_ids_per_job l ON ((l.build_id = b.id))) 315 WITH NO DATA; 316 317 REFRESH MATERIALIZED VIEW latest_completed_builds_per_job; 318 319 320 CREATE TABLE next_build_inputs ( 321 id integer NOT NULL, 322 job_id integer NOT NULL, 323 input_name text NOT NULL, 324 version_id integer NOT NULL, 325 first_occurrence boolean NOT NULL 326 ); 327 328 329 330 CREATE SEQUENCE next_build_inputs_id_seq 331 START WITH 1 332 INCREMENT BY 1 333 NO MINVALUE 334 NO MAXVALUE 335 CACHE 1; 336 337 338 339 ALTER SEQUENCE next_build_inputs_id_seq OWNED BY next_build_inputs.id; 340 341 342 343 CREATE MATERIALIZED VIEW next_builds_per_job AS 344 WITH latest_build_ids_per_job AS ( 345 SELECT min(b_1.id) AS build_id 346 FROM (builds b_1 347 JOIN jobs j ON ((j.id = b_1.job_id))) 348 WHERE (b_1.status = ANY (ARRAY['pending'::build_status, 'started'::build_status])) 349 GROUP BY b_1.job_id 350 ) 351 SELECT b.id, 352 b.name, 353 b.status, 354 b.scheduled, 355 b.start_time, 356 b.end_time, 357 b.engine, 358 b.engine_metadata, 359 b.completed, 360 b.job_id, 361 b.reap_time, 362 b.team_id, 363 b.manually_triggered, 364 b.interceptible, 365 b.nonce, 366 b.public_plan, 367 b.pipeline_id 368 FROM (builds b 369 JOIN latest_build_ids_per_job l ON ((l.build_id = b.id))) 370 WITH NO DATA; 371 372 REFRESH MATERIALIZED VIEW next_builds_per_job; 373 374 375 CREATE SEQUENCE one_off_name 376 START WITH 1 377 INCREMENT BY 1 378 NO MINVALUE 379 NO MAXVALUE 380 CACHE 1; 381 382 383 384 CREATE TABLE pipelines ( 385 version integer DEFAULT 0 NOT NULL, 386 id integer NOT NULL, 387 name text NOT NULL, 388 paused boolean DEFAULT false, 389 ordering integer DEFAULT 0 NOT NULL, 390 last_scheduled timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, 391 team_id integer NOT NULL, 392 public boolean DEFAULT false NOT NULL, 393 groups json 394 ); 395 396 397 398 CREATE SEQUENCE pipelines_id_seq 399 START WITH 1 400 INCREMENT BY 1 401 NO MINVALUE 402 NO MAXVALUE 403 CACHE 1; 404 405 406 407 ALTER SEQUENCE pipelines_id_seq OWNED BY pipelines.id; 408 409 410 411 CREATE TABLE pipes ( 412 id text NOT NULL, 413 url text, 414 team_id integer NOT NULL 415 ); 416 417 418 419 CREATE TABLE resource_cache_uses ( 420 resource_cache_id integer, 421 build_id integer, 422 container_id integer 423 ); 424 425 426 427 CREATE TABLE resource_caches ( 428 id integer NOT NULL, 429 resource_config_id integer, 430 version text NOT NULL, 431 params_hash text NOT NULL, 432 metadata text 433 ); 434 435 436 437 CREATE SEQUENCE resource_caches_id_seq 438 START WITH 1 439 INCREMENT BY 1 440 NO MINVALUE 441 NO MAXVALUE 442 CACHE 1; 443 444 445 446 ALTER SEQUENCE resource_caches_id_seq OWNED BY resource_caches.id; 447 448 449 450 CREATE TABLE resource_config_check_sessions ( 451 id integer NOT NULL, 452 resource_config_id integer, 453 expires_at timestamp with time zone 454 ); 455 456 457 458 CREATE SEQUENCE resource_config_check_sessions_id_seq 459 START WITH 1 460 INCREMENT BY 1 461 NO MINVALUE 462 NO MAXVALUE 463 CACHE 1; 464 465 466 467 ALTER SEQUENCE resource_config_check_sessions_id_seq OWNED BY resource_config_check_sessions.id; 468 469 470 471 CREATE TABLE resource_configs ( 472 id integer NOT NULL, 473 base_resource_type_id integer, 474 source_hash text NOT NULL, 475 resource_cache_id integer 476 ); 477 478 479 480 CREATE SEQUENCE resource_configs_id_seq 481 START WITH 1 482 INCREMENT BY 1 483 NO MINVALUE 484 NO MAXVALUE 485 CACHE 1; 486 487 488 489 ALTER SEQUENCE resource_configs_id_seq OWNED BY resource_configs.id; 490 491 492 493 CREATE TABLE resource_types ( 494 id integer NOT NULL, 495 pipeline_id integer, 496 name text NOT NULL, 497 type text NOT NULL, 498 version text, 499 last_checked timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, 500 config text NOT NULL, 501 active boolean DEFAULT false NOT NULL, 502 nonce text, 503 resource_config_id integer 504 ); 505 506 507 508 CREATE SEQUENCE resource_types_id_seq 509 START WITH 1 510 INCREMENT BY 1 511 NO MINVALUE 512 NO MAXVALUE 513 CACHE 1; 514 515 516 517 ALTER SEQUENCE resource_types_id_seq OWNED BY resource_types.id; 518 519 520 521 CREATE TABLE resources ( 522 name text NOT NULL, 523 check_error text, 524 paused boolean DEFAULT false, 525 id integer NOT NULL, 526 pipeline_id integer NOT NULL, 527 last_checked timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL, 528 config text NOT NULL, 529 active boolean DEFAULT false NOT NULL, 530 nonce text, 531 resource_config_id integer 532 ); 533 534 535 536 CREATE SEQUENCE resources_id_seq 537 START WITH 1 538 INCREMENT BY 1 539 NO MINVALUE 540 NO MAXVALUE 541 CACHE 1; 542 543 544 545 ALTER SEQUENCE resources_id_seq OWNED BY resources.id; 546 547 548 549 CREATE TABLE teams ( 550 id integer NOT NULL, 551 name text NOT NULL, 552 basic_auth json, 553 admin boolean DEFAULT false, 554 auth text, 555 nonce text, 556 CONSTRAINT constraint_teams_name_not_empty CHECK ((length(name) > 0)) 557 ); 558 559 560 561 CREATE SEQUENCE teams_id_seq 562 START WITH 1 563 INCREMENT BY 1 564 NO MINVALUE 565 NO MAXVALUE 566 CACHE 1; 567 568 569 570 ALTER SEQUENCE teams_id_seq OWNED BY teams.id; 571 572 573 574 CREATE MATERIALIZED VIEW transition_builds_per_job AS 575 WITH builds_before_transition AS ( 576 SELECT b_1.job_id, 577 max(b_1.id) AS max 578 FROM ((builds b_1 579 LEFT JOIN jobs j ON ((b_1.job_id = j.id))) 580 LEFT JOIN latest_completed_builds_per_job s ON ((b_1.job_id = s.job_id))) 581 WHERE ((b_1.status <> s.status) AND (b_1.status <> ALL (ARRAY['pending'::build_status, 'started'::build_status]))) 582 GROUP BY b_1.job_id 583 ) 584 SELECT DISTINCT ON (b.job_id) b.id, 585 b.name, 586 b.status, 587 b.scheduled, 588 b.start_time, 589 b.end_time, 590 b.engine, 591 b.engine_metadata, 592 b.completed, 593 b.job_id, 594 b.reap_time, 595 b.team_id, 596 b.manually_triggered, 597 b.interceptible, 598 b.nonce, 599 b.public_plan, 600 b.pipeline_id 601 FROM (builds b 602 LEFT JOIN builds_before_transition ON ((b.job_id = builds_before_transition.job_id))) 603 WHERE (((builds_before_transition.max IS NULL) AND (b.status <> ALL (ARRAY['pending'::build_status, 'started'::build_status]))) OR (b.id > builds_before_transition.max)) 604 ORDER BY b.job_id, b.id 605 WITH NO DATA; 606 607 608 REFRESH MATERIALIZED VIEW transition_builds_per_job; 609 610 611 CREATE TABLE versioned_resources ( 612 id integer NOT NULL, 613 version text NOT NULL, 614 metadata text NOT NULL, 615 type text NOT NULL, 616 enabled boolean DEFAULT true NOT NULL, 617 resource_id integer, 618 modified_time timestamp without time zone DEFAULT now() NOT NULL, 619 check_order integer DEFAULT 0 NOT NULL 620 ); 621 622 623 624 CREATE SEQUENCE versioned_resources_id_seq 625 START WITH 1 626 INCREMENT BY 1 627 NO MINVALUE 628 NO MAXVALUE 629 CACHE 1; 630 631 632 633 ALTER SEQUENCE versioned_resources_id_seq OWNED BY versioned_resources.id; 634 635 636 637 CREATE TABLE volumes ( 638 id integer NOT NULL, 639 handle text NOT NULL, 640 resource_version text, 641 resource_hash text, 642 worker_name text NOT NULL, 643 original_volume_handle text, 644 output_name text, 645 path text, 646 host_path_version text, 647 replicated_from text, 648 container_id integer, 649 team_id integer, 650 state volume_state DEFAULT 'creating'::volume_state NOT NULL, 651 parent_id integer, 652 parent_state volume_state, 653 worker_base_resource_type_id integer, 654 worker_resource_cache_id integer, 655 worker_task_cache_id integer, 656 CONSTRAINT cannot_invalidate_during_initialization CHECK ((((state = ANY (ARRAY['created'::volume_state, 'destroying'::volume_state, 'failed'::volume_state])) AND ((worker_resource_cache_id IS NULL) AND (worker_base_resource_type_id IS NULL) AND (worker_task_cache_id IS NULL) AND (container_id IS NULL))) OR ((worker_resource_cache_id IS NOT NULL) OR (worker_base_resource_type_id IS NOT NULL) OR (worker_task_cache_id IS NOT NULL) OR (container_id IS NOT NULL)))) 657 ); 658 659 660 661 CREATE SEQUENCE volumes_id_seq 662 START WITH 1 663 INCREMENT BY 1 664 NO MINVALUE 665 NO MAXVALUE 666 CACHE 1; 667 668 669 670 ALTER SEQUENCE volumes_id_seq OWNED BY volumes.id; 671 672 673 674 CREATE TABLE worker_base_resource_types ( 675 worker_name text, 676 base_resource_type_id integer, 677 image text NOT NULL, 678 version text NOT NULL, 679 id integer NOT NULL 680 ); 681 682 683 684 CREATE SEQUENCE worker_base_resource_types_id_seq 685 START WITH 1 686 INCREMENT BY 1 687 NO MINVALUE 688 NO MAXVALUE 689 CACHE 1; 690 691 692 693 ALTER SEQUENCE worker_base_resource_types_id_seq OWNED BY worker_base_resource_types.id; 694 695 696 697 CREATE TABLE worker_resource_caches ( 698 id integer NOT NULL, 699 worker_base_resource_type_id integer, 700 resource_cache_id integer 701 ); 702 703 704 705 CREATE SEQUENCE worker_resource_caches_id_seq 706 START WITH 1 707 INCREMENT BY 1 708 NO MINVALUE 709 NO MAXVALUE 710 CACHE 1; 711 712 713 714 ALTER SEQUENCE worker_resource_caches_id_seq OWNED BY worker_resource_caches.id; 715 716 717 718 CREATE TABLE worker_resource_config_check_sessions ( 719 id integer NOT NULL, 720 worker_base_resource_type_id integer, 721 resource_config_check_session_id integer, 722 team_id integer 723 ); 724 725 726 727 CREATE SEQUENCE worker_resource_config_check_sessions_id_seq 728 START WITH 1 729 INCREMENT BY 1 730 NO MINVALUE 731 NO MAXVALUE 732 CACHE 1; 733 734 735 736 ALTER SEQUENCE worker_resource_config_check_sessions_id_seq OWNED BY worker_resource_config_check_sessions.id; 737 738 739 740 CREATE TABLE worker_task_caches ( 741 id integer NOT NULL, 742 worker_name text, 743 job_id integer, 744 step_name text NOT NULL, 745 path text NOT NULL 746 ); 747 748 749 750 CREATE SEQUENCE worker_task_caches_id_seq 751 START WITH 1 752 INCREMENT BY 1 753 NO MINVALUE 754 NO MAXVALUE 755 CACHE 1; 756 757 758 759 ALTER SEQUENCE worker_task_caches_id_seq OWNED BY worker_task_caches.id; 760 761 762 763 CREATE TABLE workers ( 764 addr text, 765 expires timestamp with time zone, 766 active_containers integer DEFAULT 0, 767 resource_types text, 768 platform text, 769 tags text, 770 baggageclaim_url text DEFAULT ''::text, 771 name text NOT NULL, 772 http_proxy_url text, 773 https_proxy_url text, 774 no_proxy text, 775 start_time integer, 776 team_id integer, 777 state worker_state DEFAULT 'running'::worker_state NOT NULL, 778 version text, 779 CONSTRAINT addr_when_running CHECK ((((state <> 'stalled'::worker_state) AND (state <> 'landed'::worker_state) AND ((addr IS NOT NULL) OR (baggageclaim_url IS NOT NULL))) OR (((state = 'stalled'::worker_state) OR (state = 'landed'::worker_state)) AND (addr IS NULL) AND (baggageclaim_url IS NULL)))) 780 ); 781 782 783 784 ALTER TABLE ONLY base_resource_types ALTER COLUMN id SET DEFAULT nextval('base_resource_types_id_seq'::regclass); 785 786 787 788 ALTER TABLE ONLY builds ALTER COLUMN id SET DEFAULT nextval('builds_id_seq'::regclass); 789 790 791 792 ALTER TABLE ONLY containers ALTER COLUMN id SET DEFAULT nextval('containers_id_seq'::regclass); 793 794 795 796 ALTER TABLE ONLY independent_build_inputs ALTER COLUMN id SET DEFAULT nextval('independent_build_inputs_id_seq'::regclass); 797 798 799 800 ALTER TABLE ONLY jobs ALTER COLUMN id SET DEFAULT nextval('jobs_id_seq'::regclass); 801 802 803 804 ALTER TABLE ONLY jobs_serial_groups ALTER COLUMN id SET DEFAULT nextval('jobs_serial_groups_id_seq'::regclass); 805 806 807 808 ALTER TABLE ONLY next_build_inputs ALTER COLUMN id SET DEFAULT nextval('next_build_inputs_id_seq'::regclass); 809 810 811 812 ALTER TABLE ONLY pipelines ALTER COLUMN id SET DEFAULT nextval('pipelines_id_seq'::regclass); 813 814 815 816 ALTER TABLE ONLY resource_caches ALTER COLUMN id SET DEFAULT nextval('resource_caches_id_seq'::regclass); 817 818 819 820 ALTER TABLE ONLY resource_config_check_sessions ALTER COLUMN id SET DEFAULT nextval('resource_config_check_sessions_id_seq'::regclass); 821 822 823 824 ALTER TABLE ONLY resource_configs ALTER COLUMN id SET DEFAULT nextval('resource_configs_id_seq'::regclass); 825 826 827 828 ALTER TABLE ONLY resource_types ALTER COLUMN id SET DEFAULT nextval('resource_types_id_seq'::regclass); 829 830 831 832 ALTER TABLE ONLY resources ALTER COLUMN id SET DEFAULT nextval('resources_id_seq'::regclass); 833 834 835 836 ALTER TABLE ONLY teams ALTER COLUMN id SET DEFAULT nextval('teams_id_seq'::regclass); 837 838 839 840 ALTER TABLE ONLY versioned_resources ALTER COLUMN id SET DEFAULT nextval('versioned_resources_id_seq'::regclass); 841 842 843 844 ALTER TABLE ONLY volumes ALTER COLUMN id SET DEFAULT nextval('volumes_id_seq'::regclass); 845 846 847 848 ALTER TABLE ONLY worker_base_resource_types ALTER COLUMN id SET DEFAULT nextval('worker_base_resource_types_id_seq'::regclass); 849 850 851 852 ALTER TABLE ONLY worker_resource_caches ALTER COLUMN id SET DEFAULT nextval('worker_resource_caches_id_seq'::regclass); 853 854 855 856 ALTER TABLE ONLY worker_resource_config_check_sessions ALTER COLUMN id SET DEFAULT nextval('worker_resource_config_check_sessions_id_seq'::regclass); 857 858 859 860 ALTER TABLE ONLY worker_task_caches ALTER COLUMN id SET DEFAULT nextval('worker_task_caches_id_seq'::regclass); 861 862 863 864 ALTER TABLE ONLY base_resource_types 865 ADD CONSTRAINT base_resource_types_name_key UNIQUE (name); 866 867 868 869 ALTER TABLE ONLY base_resource_types 870 ADD CONSTRAINT base_resource_types_pkey PRIMARY KEY (id); 871 872 873 874 ALTER TABLE ONLY builds 875 ADD CONSTRAINT builds_pkey PRIMARY KEY (id); 876 877 878 879 ALTER TABLE ONLY workers 880 ADD CONSTRAINT constraint_workers_name_unique UNIQUE (name); 881 882 883 884 ALTER TABLE ONLY containers 885 ADD CONSTRAINT containers_handle_key UNIQUE (handle); 886 887 888 889 ALTER TABLE ONLY containers 890 ADD CONSTRAINT containers_pkey PRIMARY KEY (id); 891 892 893 894 ALTER TABLE ONLY independent_build_inputs 895 ADD CONSTRAINT independent_build_inputs_pkey PRIMARY KEY (id); 896 897 898 899 ALTER TABLE ONLY independent_build_inputs 900 ADD CONSTRAINT independent_build_inputs_unique_job_id_input_name UNIQUE (job_id, input_name); 901 902 903 904 ALTER TABLE ONLY jobs 905 ADD CONSTRAINT jobs_pkey PRIMARY KEY (id); 906 907 908 909 ALTER TABLE ONLY jobs_serial_groups 910 ADD CONSTRAINT jobs_serial_groups_pkey PRIMARY KEY (id); 911 912 913 914 ALTER TABLE ONLY jobs 915 ADD CONSTRAINT jobs_unique_pipeline_id_name UNIQUE (pipeline_id, name); 916 917 918 919 ALTER TABLE ONLY next_build_inputs 920 ADD CONSTRAINT next_build_inputs_pkey PRIMARY KEY (id); 921 922 923 924 ALTER TABLE ONLY next_build_inputs 925 ADD CONSTRAINT next_build_inputs_unique_job_id_input_name UNIQUE (job_id, input_name); 926 927 928 929 ALTER TABLE ONLY pipelines 930 ADD CONSTRAINT pipelines_name_team_id UNIQUE (name, team_id); 931 932 933 934 ALTER TABLE ONLY pipelines 935 ADD CONSTRAINT pipelines_pkey PRIMARY KEY (id); 936 937 938 939 ALTER TABLE ONLY pipes 940 ADD CONSTRAINT pipes_pkey PRIMARY KEY (id); 941 942 943 944 ALTER TABLE ONLY resource_caches 945 ADD CONSTRAINT resource_caches_pkey PRIMARY KEY (id); 946 947 948 949 ALTER TABLE ONLY resource_caches 950 ADD CONSTRAINT resource_caches_resource_config_id_version_params_hash_key UNIQUE (resource_config_id, version, params_hash); 951 952 953 954 ALTER TABLE ONLY resource_config_check_sessions 955 ADD CONSTRAINT resource_config_check_sessions_pkey PRIMARY KEY (id); 956 957 958 959 ALTER TABLE ONLY resource_configs 960 ADD CONSTRAINT resource_configs_pkey PRIMARY KEY (id); 961 962 963 964 ALTER TABLE ONLY resource_configs 965 ADD CONSTRAINT resource_configs_resource_cache_id_base_resource_type_id_so_key UNIQUE (resource_cache_id, base_resource_type_id, source_hash); 966 967 968 969 ALTER TABLE ONLY resource_types 970 ADD CONSTRAINT resource_types_pipeline_id_name_key UNIQUE (pipeline_id, name); 971 972 973 974 ALTER TABLE ONLY resource_types 975 ADD CONSTRAINT resource_types_pkey PRIMARY KEY (id); 976 977 978 979 ALTER TABLE ONLY resources 980 ADD CONSTRAINT resources_pkey PRIMARY KEY (id); 981 982 983 984 ALTER TABLE ONLY teams 985 ADD CONSTRAINT teams_pkey PRIMARY KEY (id); 986 987 988 989 ALTER TABLE ONLY resources 990 ADD CONSTRAINT unique_pipeline_id_name UNIQUE (pipeline_id, name); 991 992 993 994 ALTER TABLE ONLY versioned_resources 995 ADD CONSTRAINT versioned_resources_pkey PRIMARY KEY (id); 996 997 998 999 ALTER TABLE ONLY volumes 1000 ADD CONSTRAINT volumes_id_state_key UNIQUE (id, state); 1001 1002 1003 1004 ALTER TABLE ONLY volumes 1005 ADD CONSTRAINT volumes_pkey PRIMARY KEY (id); 1006 1007 1008 1009 ALTER TABLE ONLY volumes 1010 ADD CONSTRAINT volumes_worker_name_handle_key UNIQUE (worker_name, handle); 1011 1012 1013 1014 ALTER TABLE ONLY worker_base_resource_types 1015 ADD CONSTRAINT worker_base_resource_types_pkey PRIMARY KEY (id); 1016 1017 1018 1019 ALTER TABLE ONLY worker_base_resource_types 1020 ADD CONSTRAINT worker_base_resource_types_worker_name_base_resource_type_i_key UNIQUE (worker_name, base_resource_type_id); 1021 1022 1023 1024 ALTER TABLE ONLY worker_resource_caches 1025 ADD CONSTRAINT worker_resource_caches_pkey PRIMARY KEY (id); 1026 1027 1028 1029 ALTER TABLE ONLY worker_resource_config_check_sessions 1030 ADD CONSTRAINT worker_resource_config_check_sessions_pkey PRIMARY KEY (id); 1031 1032 1033 1034 ALTER TABLE ONLY worker_task_caches 1035 ADD CONSTRAINT worker_task_caches_pkey PRIMARY KEY (id); 1036 1037 1038 1039 ALTER TABLE ONLY workers 1040 ADD CONSTRAINT workers_addr_key UNIQUE (addr); 1041 1042 1043 1044 ALTER TABLE ONLY workers 1045 ADD CONSTRAINT workers_pkey PRIMARY KEY (name); 1046 1047 1048 1049 CREATE UNIQUE INDEX build_events_build_id_event_id ON build_events USING btree (build_id, event_id); 1050 1051 1052 1053 CREATE INDEX build_events_build_id_idx ON build_events USING btree (build_id); 1054 1055 1056 1057 CREATE INDEX build_image_resource_caches_build_id ON build_image_resource_caches USING btree (build_id); 1058 1059 1060 1061 CREATE INDEX build_image_resource_caches_resource_cache_id ON build_image_resource_caches USING btree (resource_cache_id); 1062 1063 1064 1065 CREATE INDEX build_inputs_build_id_idx ON build_inputs USING btree (build_id); 1066 1067 1068 1069 CREATE INDEX build_inputs_build_id_versioned_resource_id ON build_inputs USING btree (build_id, versioned_resource_id); 1070 1071 1072 1073 CREATE INDEX build_inputs_versioned_resource_id_idx ON build_inputs USING btree (versioned_resource_id); 1074 1075 1076 1077 CREATE INDEX build_outputs_build_id_idx ON build_outputs USING btree (build_id); 1078 1079 1080 1081 CREATE INDEX build_outputs_build_id_versioned_resource_id ON build_outputs USING btree (build_id, versioned_resource_id); 1082 1083 1084 1085 CREATE INDEX build_outputs_versioned_resource_id_idx ON build_outputs USING btree (versioned_resource_id); 1086 1087 1088 1089 CREATE INDEX builds_interceptible_completed ON builds USING btree (interceptible, completed); 1090 1091 1092 1093 CREATE INDEX builds_job_id ON builds USING btree (job_id); 1094 1095 1096 1097 CREATE INDEX builds_pipeline_id ON builds USING btree (pipeline_id); 1098 1099 1100 1101 CREATE INDEX builds_status ON builds USING btree (status); 1102 1103 1104 1105 CREATE INDEX builds_team_id ON builds USING btree (team_id); 1106 1107 1108 1109 CREATE INDEX containers_build_id ON containers USING btree (build_id); 1110 1111 1112 1113 CREATE INDEX containers_image_check_container_id ON containers USING btree (image_check_container_id); 1114 1115 1116 1117 CREATE INDEX containers_image_get_container_id ON containers USING btree (image_get_container_id); 1118 1119 1120 1121 CREATE INDEX containers_plan_id ON containers USING btree (plan_id); 1122 1123 1124 1125 CREATE INDEX containers_team_id ON containers USING btree (team_id); 1126 1127 1128 1129 CREATE INDEX containers_worker_name ON containers USING btree (worker_name); 1130 1131 1132 1133 CREATE INDEX containers_worker_resource_config_check_session_id ON containers USING btree (worker_resource_config_check_session_id); 1134 1135 1136 1137 CREATE INDEX independent_build_inputs_job_id ON independent_build_inputs USING btree (job_id); 1138 1139 1140 1141 CREATE INDEX independent_build_inputs_version_id ON independent_build_inputs USING btree (version_id); 1142 1143 1144 1145 CREATE UNIQUE INDEX index_teams_name_unique_case_insensitive ON teams USING btree (lower(name)); 1146 1147 1148 1149 CREATE INDEX jobs_pipeline_id ON jobs USING btree (pipeline_id); 1150 1151 1152 1153 CREATE INDEX jobs_serial_groups_job_id_idx ON jobs_serial_groups USING btree (job_id); 1154 1155 1156 1157 CREATE UNIQUE INDEX latest_completed_builds_per_job_id ON latest_completed_builds_per_job USING btree (id); 1158 1159 1160 1161 CREATE INDEX next_build_inputs_job_id ON next_build_inputs USING btree (job_id); 1162 1163 1164 1165 CREATE INDEX next_build_inputs_version_id ON next_build_inputs USING btree (version_id); 1166 1167 1168 1169 CREATE UNIQUE INDEX next_builds_per_job_id ON next_builds_per_job USING btree (id); 1170 1171 1172 1173 CREATE INDEX pipelines_team_id ON pipelines USING btree (team_id); 1174 1175 1176 1177 CREATE INDEX pipes_team_id ON pipes USING btree (team_id); 1178 1179 1180 1181 CREATE INDEX resource_cache_uses_build_id ON resource_cache_uses USING btree (build_id); 1182 1183 1184 1185 CREATE INDEX resource_cache_uses_container_id ON resource_cache_uses USING btree (container_id); 1186 1187 1188 1189 CREATE INDEX resource_cache_uses_resource_cache_id ON resource_cache_uses USING btree (resource_cache_id); 1190 1191 1192 1193 CREATE INDEX resource_caches_resource_config_id ON resource_caches USING btree (resource_config_id); 1194 1195 1196 1197 CREATE INDEX resource_config_check_sessions_resource_config_id ON resource_config_check_sessions USING btree (resource_config_id); 1198 1199 1200 1201 CREATE INDEX resource_configs_base_resource_type_id ON resource_configs USING btree (base_resource_type_id); 1202 1203 1204 1205 CREATE INDEX resource_configs_resource_cache_id ON resource_configs USING btree (resource_cache_id); 1206 1207 1208 1209 CREATE INDEX resource_types_pipeline_id ON resource_types USING btree (pipeline_id); 1210 1211 1212 1213 CREATE INDEX resource_types_resource_config_id ON resource_types USING btree (resource_config_id); 1214 1215 1216 1217 CREATE INDEX resources_pipeline_id ON resources USING btree (pipeline_id); 1218 1219 1220 1221 CREATE INDEX resources_resource_config_id ON resources USING btree (resource_config_id); 1222 1223 1224 1225 CREATE UNIQUE INDEX transition_builds_per_job_id ON transition_builds_per_job USING btree (id); 1226 1227 1228 1229 CREATE INDEX versioned_resources_resource_id_idx ON versioned_resources USING btree (resource_id); 1230 1231 1232 1233 CREATE UNIQUE INDEX versioned_resources_resource_id_type_version ON versioned_resources USING btree (resource_id, type, md5(version)); 1234 1235 1236 1237 CREATE INDEX volumes_container_id ON volumes USING btree (container_id); 1238 1239 1240 1241 CREATE UNIQUE INDEX volumes_handle ON volumes USING btree (handle); 1242 1243 1244 1245 CREATE INDEX volumes_parent_id ON volumes USING btree (parent_id); 1246 1247 1248 1249 CREATE INDEX volumes_team_id ON volumes USING btree (team_id); 1250 1251 1252 1253 CREATE INDEX volumes_worker_base_resource_type_id ON volumes USING btree (worker_base_resource_type_id); 1254 1255 1256 1257 CREATE INDEX volumes_worker_name ON volumes USING btree (worker_name); 1258 1259 1260 1261 CREATE INDEX volumes_worker_resource_cache_id ON volumes USING btree (worker_resource_cache_id); 1262 1263 1264 1265 CREATE UNIQUE INDEX volumes_worker_resource_cache_unique ON volumes USING btree (worker_resource_cache_id); 1266 1267 1268 1269 CREATE INDEX volumes_worker_task_cache_id ON volumes USING btree (worker_task_cache_id); 1270 1271 1272 1273 CREATE INDEX worker_base_resource_types_base_resource_type_id ON worker_base_resource_types USING btree (base_resource_type_id); 1274 1275 1276 1277 CREATE INDEX worker_base_resource_types_worker_name ON worker_base_resource_types USING btree (worker_name); 1278 1279 1280 1281 CREATE INDEX worker_resource_caches_resource_cache_id ON worker_resource_caches USING btree (resource_cache_id); 1282 1283 1284 1285 CREATE INDEX worker_resource_caches_worker_base_resource_type_id ON worker_resource_caches USING btree (worker_base_resource_type_id); 1286 1287 1288 1289 CREATE INDEX worker_resource_config_check_sessions_resource_config_check_ses ON worker_resource_config_check_sessions USING btree (resource_config_check_session_id); 1290 1291 1292 1293 CREATE INDEX worker_resource_config_check_sessions_worker_base_resource_type ON worker_resource_config_check_sessions USING btree (worker_base_resource_type_id); 1294 1295 1296 1297 CREATE INDEX worker_task_caches_job_id ON worker_task_caches USING btree (job_id); 1298 1299 1300 1301 CREATE INDEX worker_task_caches_worker_name ON worker_task_caches USING btree (worker_name); 1302 1303 1304 1305 CREATE INDEX workers_team_id ON workers USING btree (team_id); 1306 1307 1308 1309 ALTER TABLE ONLY build_image_resource_caches 1310 ADD CONSTRAINT build_image_resource_caches_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE; 1311 1312 1313 1314 ALTER TABLE ONLY build_image_resource_caches 1315 ADD CONSTRAINT build_image_resource_caches_resource_cache_id_fkey FOREIGN KEY (resource_cache_id) REFERENCES resource_caches(id) ON DELETE RESTRICT; 1316 1317 1318 1319 ALTER TABLE ONLY build_inputs 1320 ADD CONSTRAINT build_inputs_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE; 1321 1322 1323 1324 ALTER TABLE ONLY build_inputs 1325 ADD CONSTRAINT build_inputs_versioned_resource_id_fkey FOREIGN KEY (versioned_resource_id) REFERENCES versioned_resources(id) ON DELETE CASCADE; 1326 1327 1328 1329 ALTER TABLE ONLY build_outputs 1330 ADD CONSTRAINT build_outputs_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE; 1331 1332 1333 1334 ALTER TABLE ONLY build_outputs 1335 ADD CONSTRAINT build_outputs_versioned_resource_id_fkey FOREIGN KEY (versioned_resource_id) REFERENCES versioned_resources(id) ON DELETE CASCADE; 1336 1337 1338 1339 ALTER TABLE ONLY builds 1340 ADD CONSTRAINT builds_pipeline_id_fkey FOREIGN KEY (pipeline_id) REFERENCES pipelines(id) ON DELETE CASCADE; 1341 1342 1343 1344 ALTER TABLE ONLY builds 1345 ADD CONSTRAINT builds_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE; 1346 1347 1348 1349 ALTER TABLE ONLY containers 1350 ADD CONSTRAINT containers_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE SET NULL; 1351 1352 1353 1354 ALTER TABLE ONLY containers 1355 ADD CONSTRAINT containers_image_check_container_id_fkey FOREIGN KEY (image_check_container_id) REFERENCES containers(id) ON DELETE SET NULL; 1356 1357 1358 1359 ALTER TABLE ONLY containers 1360 ADD CONSTRAINT containers_image_get_container_id_fkey FOREIGN KEY (image_get_container_id) REFERENCES containers(id) ON DELETE SET NULL; 1361 1362 1363 1364 ALTER TABLE ONLY containers 1365 ADD CONSTRAINT containers_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE SET NULL; 1366 1367 1368 1369 ALTER TABLE ONLY containers 1370 ADD CONSTRAINT containers_worker_name_fkey FOREIGN KEY (worker_name) REFERENCES workers(name) ON DELETE CASCADE; 1371 1372 1373 1374 ALTER TABLE ONLY containers 1375 ADD CONSTRAINT containers_worker_resource_config_check_session_id_fkey FOREIGN KEY (worker_resource_config_check_session_id) REFERENCES worker_resource_config_check_sessions(id) ON DELETE SET NULL; 1376 1377 1378 1379 ALTER TABLE ONLY volumes 1380 ADD CONSTRAINT fkey_container_id FOREIGN KEY (container_id) REFERENCES containers(id) ON DELETE SET NULL; 1381 1382 1383 1384 ALTER TABLE ONLY jobs_serial_groups 1385 ADD CONSTRAINT fkey_job_id FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE; 1386 1387 1388 1389 ALTER TABLE ONLY builds 1390 ADD CONSTRAINT fkey_job_id FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE; 1391 1392 1393 1394 ALTER TABLE ONLY versioned_resources 1395 ADD CONSTRAINT fkey_resource_id FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE; 1396 1397 1398 1399 ALTER TABLE ONLY independent_build_inputs 1400 ADD CONSTRAINT independent_build_inputs_job_id_fkey FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE; 1401 1402 1403 1404 ALTER TABLE ONLY independent_build_inputs 1405 ADD CONSTRAINT independent_build_inputs_version_id_fkey FOREIGN KEY (version_id) REFERENCES versioned_resources(id) ON DELETE CASCADE; 1406 1407 1408 1409 ALTER TABLE ONLY jobs 1410 ADD CONSTRAINT jobs_pipeline_id_fkey FOREIGN KEY (pipeline_id) REFERENCES pipelines(id) ON DELETE CASCADE; 1411 1412 1413 1414 ALTER TABLE ONLY next_build_inputs 1415 ADD CONSTRAINT next_build_inputs_job_id_fkey FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE; 1416 1417 1418 1419 ALTER TABLE ONLY next_build_inputs 1420 ADD CONSTRAINT next_build_inputs_version_id_fkey FOREIGN KEY (version_id) REFERENCES versioned_resources(id) ON DELETE CASCADE; 1421 1422 1423 1424 ALTER TABLE ONLY pipelines 1425 ADD CONSTRAINT pipelines_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE; 1426 1427 1428 1429 ALTER TABLE ONLY pipes 1430 ADD CONSTRAINT pipes_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE; 1431 1432 1433 1434 ALTER TABLE ONLY resource_cache_uses 1435 ADD CONSTRAINT resource_cache_uses_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE CASCADE; 1436 1437 1438 1439 ALTER TABLE ONLY resource_cache_uses 1440 ADD CONSTRAINT resource_cache_uses_container_id_fkey FOREIGN KEY (container_id) REFERENCES containers(id) ON DELETE CASCADE; 1441 1442 1443 1444 ALTER TABLE ONLY resource_cache_uses 1445 ADD CONSTRAINT resource_cache_uses_resource_cache_id_fkey FOREIGN KEY (resource_cache_id) REFERENCES resource_caches(id) ON DELETE RESTRICT; 1446 1447 1448 1449 ALTER TABLE ONLY resource_caches 1450 ADD CONSTRAINT resource_caches_resource_config_id_fkey FOREIGN KEY (resource_config_id) REFERENCES resource_configs(id) ON DELETE RESTRICT; 1451 1452 1453 1454 ALTER TABLE ONLY resource_config_check_sessions 1455 ADD CONSTRAINT resource_config_check_sessions_resource_config_id_fkey FOREIGN KEY (resource_config_id) REFERENCES resource_configs(id) ON DELETE RESTRICT; 1456 1457 1458 1459 ALTER TABLE ONLY resource_configs 1460 ADD CONSTRAINT resource_configs_base_resource_type_id_fkey FOREIGN KEY (base_resource_type_id) REFERENCES base_resource_types(id) ON DELETE CASCADE; 1461 1462 1463 1464 ALTER TABLE ONLY resource_configs 1465 ADD CONSTRAINT resource_configs_resource_cache_id_fkey FOREIGN KEY (resource_cache_id) REFERENCES resource_caches(id) ON DELETE RESTRICT; 1466 1467 1468 1469 ALTER TABLE ONLY resource_types 1470 ADD CONSTRAINT resource_types_pipeline_id_fkey FOREIGN KEY (pipeline_id) REFERENCES pipelines(id) ON DELETE CASCADE; 1471 1472 1473 1474 ALTER TABLE ONLY resource_types 1475 ADD CONSTRAINT resource_types_resource_config_id_fkey FOREIGN KEY (resource_config_id) REFERENCES resource_configs(id) ON DELETE SET NULL; 1476 1477 1478 1479 ALTER TABLE ONLY resources 1480 ADD CONSTRAINT resources_pipeline_id_fkey FOREIGN KEY (pipeline_id) REFERENCES pipelines(id) ON DELETE CASCADE; 1481 1482 1483 1484 ALTER TABLE ONLY resources 1485 ADD CONSTRAINT resources_resource_config_id_fkey FOREIGN KEY (resource_config_id) REFERENCES resource_configs(id) ON DELETE SET NULL; 1486 1487 1488 1489 ALTER TABLE ONLY volumes 1490 ADD CONSTRAINT volumes_parent_id_fkey FOREIGN KEY (parent_id, parent_state) REFERENCES volumes(id, state) ON DELETE RESTRICT; 1491 1492 1493 1494 ALTER TABLE ONLY volumes 1495 ADD CONSTRAINT volumes_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE SET NULL; 1496 1497 1498 1499 ALTER TABLE ONLY volumes 1500 ADD CONSTRAINT volumes_worker_base_resource_type_id_fkey FOREIGN KEY (worker_base_resource_type_id) REFERENCES worker_base_resource_types(id) ON DELETE SET NULL; 1501 1502 1503 1504 ALTER TABLE ONLY volumes 1505 ADD CONSTRAINT volumes_worker_name_fkey FOREIGN KEY (worker_name) REFERENCES workers(name) ON DELETE CASCADE; 1506 1507 1508 1509 ALTER TABLE ONLY volumes 1510 ADD CONSTRAINT volumes_worker_resource_cache_id_fkey FOREIGN KEY (worker_resource_cache_id) REFERENCES worker_resource_caches(id) ON DELETE SET NULL; 1511 1512 1513 1514 ALTER TABLE ONLY volumes 1515 ADD CONSTRAINT volumes_worker_task_cache_id_fkey FOREIGN KEY (worker_task_cache_id) REFERENCES worker_task_caches(id) ON DELETE SET NULL; 1516 1517 1518 1519 ALTER TABLE ONLY worker_base_resource_types 1520 ADD CONSTRAINT worker_base_resource_types_base_resource_type_id_fkey FOREIGN KEY (base_resource_type_id) REFERENCES base_resource_types(id) ON DELETE RESTRICT; 1521 1522 1523 1524 ALTER TABLE ONLY worker_base_resource_types 1525 ADD CONSTRAINT worker_base_resource_types_worker_name_fkey FOREIGN KEY (worker_name) REFERENCES workers(name) ON DELETE CASCADE; 1526 1527 1528 1529 ALTER TABLE ONLY worker_resource_caches 1530 ADD CONSTRAINT worker_resource_caches_resource_cache_id_fkey FOREIGN KEY (resource_cache_id) REFERENCES resource_caches(id) ON DELETE CASCADE; 1531 1532 1533 1534 ALTER TABLE ONLY worker_resource_caches 1535 ADD CONSTRAINT worker_resource_caches_worker_base_resource_type_id_fkey FOREIGN KEY (worker_base_resource_type_id) REFERENCES worker_base_resource_types(id) ON DELETE CASCADE; 1536 1537 1538 1539 ALTER TABLE ONLY worker_resource_config_check_sessions 1540 ADD CONSTRAINT worker_resource_config_check__resource_config_check_sessio_fkey FOREIGN KEY (resource_config_check_session_id) REFERENCES resource_config_check_sessions(id) ON DELETE CASCADE; 1541 1542 1543 1544 ALTER TABLE ONLY worker_resource_config_check_sessions 1545 ADD CONSTRAINT worker_resource_config_check__worker_base_resource_type_id_fkey FOREIGN KEY (worker_base_resource_type_id) REFERENCES worker_base_resource_types(id) ON DELETE CASCADE; 1546 1547 1548 1549 ALTER TABLE ONLY worker_resource_config_check_sessions 1550 ADD CONSTRAINT worker_resource_config_check_sessions_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE; 1551 1552 1553 1554 ALTER TABLE ONLY worker_task_caches 1555 ADD CONSTRAINT worker_task_caches_job_id_fkey FOREIGN KEY (job_id) REFERENCES jobs(id) ON DELETE CASCADE; 1556 1557 1558 1559 ALTER TABLE ONLY worker_task_caches 1560 ADD CONSTRAINT worker_task_caches_worker_name_fkey FOREIGN KEY (worker_name) REFERENCES workers(name) ON DELETE CASCADE; 1561 1562 1563 1564 ALTER TABLE ONLY workers 1565 ADD CONSTRAINT workers_team_id_fkey FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE; 1566 1567 1568 COMMIT;