From d05f7a9be96db76466b7775f9203ecfc3642f46c Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 11:36:34 -0600 Subject: [PATCH 01/48] Squash update_interfaces_multiple_routers --- traffic_ops/app/db/create_tables.sql | 5 ++-- ...pdate_interfaces_multiple_routers.down.sql | 27 ------------------- ..._update_interfaces_multiple_routers.up.sql | 26 ------------------ 3 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index d2a4816422..6f3027abde 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -875,6 +875,8 @@ CREATE TABLE IF NOT EXISTS interface ( mtu bigint DEFAULT 1500 CHECK (mtu IS NULL OR mtu > 1280), name text NOT NULL CHECK (name != ''), server bigint NOT NULL, + router_host_name text NOT NULL DEFAULT '', + router_port_name text NOT NULL DEFAULT '', PRIMARY KEY (name, server) ); @@ -1387,8 +1389,6 @@ CREATE TABLE IF NOT EXISTS server ( ilo_ip_gateway text, ilo_username text, ilo_password text, - router_host_name text, - router_port_name text, guid text, last_updated timestamp with time zone NOT NULL DEFAULT now(), https_port bigint, @@ -3735,4 +3735,3 @@ GRANT ALL ON SCHEMA public TO PUBLIC; -- -- PostgreSQL database dump complete -- - diff --git a/traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.down.sql b/traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.down.sql deleted file mode 100644 index b37eade432..0000000000 --- a/traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.down.sql +++ /dev/null @@ -1,27 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE server ADD COLUMN router_host_name text DEFAULT ''; -ALTER TABLE server ADD COLUMN router_port_name text DEFAULT ''; - -UPDATE server s SET (router_host_name, router_port_name) = -(SELECT interface.router_host_name, interface.router_port_name FROM interface -JOIN ip_address ip ON ip.interface = name -JOIN server on ip.server = server.id -WHERE ip.service_address = true -AND s.id = ip.server AND s.id = interface.server LIMIT 1); - -ALTER TABLE interface DROP COLUMN router_host_name; -ALTER TABLE interface DROP COLUMN router_port_name; diff --git a/traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.up.sql b/traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.up.sql deleted file mode 100644 index 13a195b561..0000000000 --- a/traffic_ops/app/db/migrations/2021012700000000_update_interfaces_multiple_routers.up.sql +++ /dev/null @@ -1,26 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE interface ADD COLUMN router_host_name text NOT NULL DEFAULT ''; -ALTER TABLE interface ADD COLUMN router_port_name text NOT NULL DEFAULT ''; - -UPDATE interface -SET router_host_name = COALESCE(server.router_host_name, ''), -router_port_name = COALESCE(server.router_port_name, '') -FROM server -WHERE server = server.id; - -ALTER TABLE server DROP COLUMN router_host_name; -ALTER TABLE server DROP COLUMN router_port_name; From 49f16df26c73e795eb26775cc20ee7992971cfdf Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 11:38:29 -0600 Subject: [PATCH 02/48] Squash remove_tm_path --- .../2021012800000000_remove_tm_path.down.sql | 29 ------------------ .../2021012800000000_remove_tm_path.up.sql | 30 ------------------- 2 files changed, 59 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.up.sql diff --git a/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.down.sql b/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.down.sql deleted file mode 100644 index 0be4106c25..0000000000 --- a/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.down.sql +++ /dev/null @@ -1,29 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* -This migration removes the 'tm_path' property from the 'stats' property of the -'crconfig' column of stored CDN Snapshots, if it exists. - -When reverted, it will insert (if possible) a 'tm_path' value of -/api/4.0/cdns/{{CDN Name}}/snapshot -where 'CDN Name' is the name of the CDN snapshotted as determined by the -Snapshot data - NOT the linked CDN object. This is so it does not self-confilct -afterward regarding which CDN is named, even if the one to which it is linked -is wrong, somehow. -*/ - -UPDATE snapshot SET crconfig = jsonb_set(crconfig::jsonb, '{stats,tm_path}', ('"/api/4.0/cdns/' || (crconfig::jsonb -> 'stats' ->> 'CDN_name') || '/snapshot"')::jsonb) -WHERE crconfig::jsonb ? 'stats' AND (crconfig::jsonb -> 'stats') ? 'CDN_name'; diff --git a/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.up.sql b/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.up.sql deleted file mode 100644 index 6547fc59a9..0000000000 --- a/traffic_ops/app/db/migrations/2021012800000000_remove_tm_path.up.sql +++ /dev/null @@ -1,30 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -/* -This migration removes the 'tm_path' property from the 'stats' property of the -'crconfig' column of stored CDN Snapshots, if it exists. - -When reverted, it will insert (if possible) a 'tm_path' value of -/api/4.0/cdns/{{CDN Name}}/snapshot -where 'CDN Name' is the name of the CDN snapshotted as determined by the -Snapshot data - NOT the linked CDN object. This is so it does not self-confilct -afterward regarding which CDN is named, even if the one to which it is linked -is wrong, somehow. -*/ - -UPDATE snapshot -SET crconfig = crconfig::jsonb #- '{stats,tm_path}' -WHERE crconfig::jsonb ? 'stats' AND (crconfig::jsonb -> 'stats') ? 'tm_path'; From 49998c31471fff927a178df1e3783c7bdc8a9468 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 11:42:06 -0600 Subject: [PATCH 03/48] Squash change_mtu_check_interfaces --- traffic_ops/app/db/create_tables.sql | 6 +++++- ...0500000000_change_mtu_check_interfaces.down.sql | 14 -------------- ...020500000000_change_mtu_check_interfaces.up.sql | 14 -------------- 3 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 6f3027abde..b4bd33841c 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -872,7 +872,7 @@ ALTER SEQUENCE hwinfo_id_seq OWNED BY hwinfo.id; CREATE TABLE IF NOT EXISTS interface ( max_bandwidth bigint DEFAULT NULL CHECK (max_bandwidth IS NULL OR max_bandwidth >= 0), monitor boolean NOT NULL, - mtu bigint DEFAULT 1500 CHECK (mtu IS NULL OR mtu > 1280), + mtu bigint DEFAULT 1500, name text NOT NULL CHECK (name != ''), server bigint NOT NULL, router_host_name text NOT NULL DEFAULT '', @@ -880,6 +880,10 @@ CREATE TABLE IF NOT EXISTS interface ( PRIMARY KEY (name, server) ); +ALTER TABLE interface +ADD CONSTRAINT interface_mtu_check +CHECK (((mtu IS NULL) OR (mtu >= 1280))); + -- -- Name: ip_address; Type: TABLE; Schema: public; Owner: traffic_ops -- diff --git a/traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.down.sql b/traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.down.sql deleted file mode 100644 index 204170a48c..0000000000 --- a/traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.down.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE interface DROP CONSTRAINT interface_mtu_check; -ALTER TABLE interface ADD CONSTRAINT interface_mtu_check CHECK (((mtu IS NULL) OR (mtu > 1280))); diff --git a/traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.up.sql b/traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.up.sql deleted file mode 100644 index c68b3bd21f..0000000000 --- a/traffic_ops/app/db/migrations/2021020500000000_change_mtu_check_interfaces.up.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE interface DROP CONSTRAINT interface_mtu_check; -ALTER TABLE interface ADD CONSTRAINT interface_mtu_check CHECK (((mtu IS NULL) OR (mtu >= 1280))); From e8dff3d8afdcb78558edbad78548577a2e346a62 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 11:52:12 -0600 Subject: [PATCH 04/48] Squash cdn_notification --- traffic_ops/app/db/create_tables.sql | 32 +++++++++++++++++++ ...2021021900000000_cdn_notification.down.sql | 18 ----------- .../2021021900000000_cdn_notification.up.sql | 28 ---------------- 3 files changed, 32 insertions(+), 46 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021021900000000_cdn_notification.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021021900000000_cdn_notification.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index b4bd33841c..63b5ba96bb 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -462,6 +462,17 @@ ALTER TABLE cdn_id_seq OWNER TO traffic_ops; ALTER SEQUENCE cdn_id_seq OWNED BY cdn.id; +-- +-- Name: cdn_notification; Type: TABLE; Schema: public; Owner: traffic_ops + +CREATE TABLE cdn_notification ( + cdn text NOT NULL, + "user" text NOT NULL, + notification text, + last_updated timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT pk_cdn_notification PRIMARY KEY (cdn), +); + -- -- Name: coordinate; Type: TABLE; Schema: public: Owner: traffic_ops -- @@ -2868,6 +2879,7 @@ DECLARE 'cachegroup_parameter', 'capability', 'cdn', + 'cdn_notification', 'coordinate', 'deliveryservice', 'deliveryservice_regex', @@ -2941,6 +2953,26 @@ END$$; -- New code block to deallocate table_name variable to avoid identifier collision DO $$ BEGIN +IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_notification_cdn' AND table_name = 'cdn_notification') THEN + -- + -- Name: fk_notification_cdn; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops + -- + + ALTER TABLE ONLY cdn_notification + ADD CONSTRAINT fk_notification_cdn FOREIGN KEY (cdn) REFERENCES cdn(name) ON DELETE CASCADE ON UPDATE CASCADE; + +END IF; + +IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_notification_user' AND table_name = 'cdn_notification') THEN + -- + -- Name: fk_notification_user; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops + -- + + ALTER TABLE ONLY cdn_notification + ADD CONSTRAINT fk_notification_user FOREIGN KEY ("user") REFERENCES tm_user(username) ON DELETE CASCADE ON UPDATE CASCADE; + +END IF; + IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_atsprofile_atsparameters_atsparameters1' AND table_name = 'profile_parameter') THEN -- -- Name: fk_atsprofile_atsparameters_atsparameters1; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021021900000000_cdn_notification.down.sql b/traffic_ops/app/db/migrations/2021021900000000_cdn_notification.down.sql deleted file mode 100644 index 9a2b43168e..0000000000 --- a/traffic_ops/app/db/migrations/2021021900000000_cdn_notification.down.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -DROP TABLE IF EXISTS cdn_notification; diff --git a/traffic_ops/app/db/migrations/2021021900000000_cdn_notification.up.sql b/traffic_ops/app/db/migrations/2021021900000000_cdn_notification.up.sql deleted file mode 100644 index e2197981cc..0000000000 --- a/traffic_ops/app/db/migrations/2021021900000000_cdn_notification.up.sql +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -CREATE TABLE cdn_notification ( - cdn text NOT NULL, - "user" text NOT NULL, - notification text, - last_updated timestamp with time zone DEFAULT now() NOT NULL, - CONSTRAINT pk_cdn_notification PRIMARY KEY (cdn), - CONSTRAINT fk_notification_cdn FOREIGN KEY (cdn) REFERENCES cdn(name) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT fk_notification_user FOREIGN KEY ("user") REFERENCES tm_user(username) ON DELETE CASCADE ON UPDATE CASCADE -); -DROP TRIGGER IF EXISTS on_update_current_timestamp ON cdn_notification; -CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON cdn_notification FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated(); From 91c6aeaee328aea6f32608fa7b2e5fa1c8548915 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 13:25:01 -0600 Subject: [PATCH 05/48] Squash add_async_status_table --- traffic_ops/app/db/create_tables.sql | 42 +++++++++++++++++++ ...2300000000_add_async_status_table.down.sql | 17 -------- ...022300000000_add_async_status_table.up.sql | 33 --------------- 3 files changed, 42 insertions(+), 50 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 63b5ba96bb..38415d9a7d 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -334,6 +334,42 @@ ALTER TABLE asn_id_seq OWNER TO traffic_ops; ALTER SEQUENCE asn_id_seq OWNED BY asn.id; +-- +-- Name: async_status; Type: TABLE; Schema: public; Owner: traffic_ops +-- + +CREATE TABLE IF NOT EXISTS async_status ( + id bigint NOT NULL, + status TEXT NOT NULL, + message TEXT, + start_time timestamp with time zone DEFAULT now() NOT NULL, + end_time timestamp with time zone, + + CONSTRAINT async_status_pkey PRIMARY KEY (id) +); + +ALTER TABLE async_status OWNER TO traffic_ops; + +-- +-- Name: async_status_id_seq; Type: SEQUENCE; Schema: public; Owner: traffic_ops +-- + +CREATE SEQUENCE IF NOT EXISTS async_status_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE async_status_id_seq OWNER TO traffic_ops; + +-- +-- Name: async_status_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: traffic_ops +-- + +ALTER SEQUENCE async_status_id_seq OWNED BY async_status.id; + -- -- Name: cachegroup; Type: TABLE; Schema: public; Owner: traffic_ops -- @@ -1912,6 +1948,12 @@ END$$; ALTER TABLE ONLY asn ALTER COLUMN id SET DEFAULT nextval('asn_id_seq'::regclass); +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops +-- + +ALTER TABLE ONLY async_status ALTER COLUMN id SET DEFAULT nextval('async_status_id_seq'::regclass); + -- -- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.down.sql b/traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.down.sql deleted file mode 100644 index 00a37cf45f..0000000000 --- a/traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.down.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -DROP TABLE IF EXISTS async_status; -DROP SEQUENCE IF EXISTS async_status_id_seq; diff --git a/traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.up.sql b/traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.up.sql deleted file mode 100644 index 7e003593a5..0000000000 --- a/traffic_ops/app/db/migrations/2021022300000000_add_async_status_table.up.sql +++ /dev/null @@ -1,33 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -CREATE SEQUENCE IF NOT EXISTS async_status_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - -CREATE TABLE IF NOT EXISTS async_status ( - id bigint NOT NULL DEFAULT nextval('async_status_id_seq'::regclass), - status TEXT NOT NULL, - message TEXT, - start_time timestamp with time zone DEFAULT now() NOT NULL, - end_time timestamp with time zone, - - PRIMARY KEY (id) -); - -ALTER SEQUENCE async_status_id_seq OWNED BY async_status.id; From 4a2774c3f2e3f049d12ea76200c01c91dc7eabde Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 13:29:46 -0600 Subject: [PATCH 06/48] Squash server_capability_update_cascade --- traffic_ops/app/db/create_tables.sql | 4 ++-- ...000_server_capability_update_cascade.down.sql | 16 ---------------- ...00000_server_capability_update_cascade.up.sql | 16 ---------------- 3 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 38415d9a7d..ce44e01c17 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -3102,7 +3102,7 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constrain -- ALTER TABLE ONLY deliveryservices_required_capability - ADD CONSTRAINT fk_required_capability FOREIGN KEY (required_capability) REFERENCES server_capability(name) ON DELETE RESTRICT; + ADD CONSTRAINT fk_required_capability FOREIGN KEY (required_capability) REFERENCES server_capability(name) ON UPDATE CASCADE ON DELETE RESTRICT; END IF; IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'deliveryservice_topology_fkey' AND table_name = 'deliveryservice') THEN @@ -3129,7 +3129,7 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constrain -- ALTER TABLE ONLY server_server_capability - ADD CONSTRAINT fk_server_capability FOREIGN KEY (server_capability) REFERENCES server_capability(name) ON DELETE RESTRICT; + ADD CONSTRAINT fk_server_capability FOREIGN KEY (server_capability) REFERENCES server_capability(name) ON UPDATE CASCADE ON DELETE RESTRICT; END IF; IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_deliveryservice' AND table_name = 'deliveryservice_consistent_hash_query_param') THEN diff --git a/traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.down.sql b/traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.down.sql deleted file mode 100644 index 579d11bca2..0000000000 --- a/traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.down.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE public.server_server_capability DROP CONSTRAINT fk_server_capability; -ALTER TABLE public.deliveryservices_required_capability DROP CONSTRAINT fk_required_capability; -ALTER TABLE public.server_server_capability ADD CONSTRAINT fk_server_capability FOREIGN KEY (server_capability) REFERENCES server_capability(name) ON DELETE RESTRICT; -ALTER TABLE public.deliveryservices_required_capability ADD CONSTRAINT fk_required_capability FOREIGN KEY (required_capability) REFERENCES server_capability(name) ON DELETE RESTRICT; diff --git a/traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.up.sql b/traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.up.sql deleted file mode 100644 index c7529bf457..0000000000 --- a/traffic_ops/app/db/migrations/2021030300000000_server_capability_update_cascade.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE public.server_server_capability DROP CONSTRAINT fk_server_capability; -ALTER TABLE public.deliveryservices_required_capability DROP CONSTRAINT fk_required_capability; -ALTER TABLE public.server_server_capability ADD CONSTRAINT fk_server_capability FOREIGN KEY (server_capability) REFERENCES server_capability(name) ON UPDATE CASCADE ON DELETE RESTRICT; -ALTER TABLE public.deliveryservices_required_capability ADD CONSTRAINT fk_required_capability FOREIGN KEY (required_capability) REFERENCES server_capability(name) ON UPDATE CASCADE ON DELETE RESTRICT; From afecd6709d968cd5e37bf063f98dab665fed4c8d Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 13:39:39 -0600 Subject: [PATCH 07/48] Squash cdn_notifications_multiple --- traffic_ops/app/db/create_tables.sql | 29 +++++++++++++++++- ...000000_cdn_notifications_multiple.down.sql | 30 ------------------- ...00000000_cdn_notifications_multiple.up.sql | 30 ------------------- 3 files changed, 28 insertions(+), 61 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index ce44e01c17..655c4a455b 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -502,13 +502,34 @@ ALTER SEQUENCE cdn_id_seq OWNED BY cdn.id; -- Name: cdn_notification; Type: TABLE; Schema: public; Owner: traffic_ops CREATE TABLE cdn_notification ( + id bigint NOT NULL, cdn text NOT NULL, "user" text NOT NULL, notification text, last_updated timestamp with time zone DEFAULT now() NOT NULL, - CONSTRAINT pk_cdn_notification PRIMARY KEY (cdn), + CONSTRAINT pk_cdn_notification PRIMARY KEY (id) ); +-- +-- Name: cdn_notification_id_seq; Type: SEQUENCE; Schema: public; Owner: traffic_ops +-- + +CREATE SEQUENCE IF NOT EXISTS cdn_notification_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE cdn_notification_id_seq OWNER TO traffic_ops; + +-- +-- Name: cdn_notification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: traffic_ops +-- + +ALTER SEQUENCE cdn_notification_id_seq OWNED BY cdn.id; + -- -- Name: coordinate; Type: TABLE; Schema: public: Owner: traffic_ops -- @@ -1968,6 +1989,12 @@ ALTER TABLE ONLY cachegroup ALTER COLUMN id SET DEFAULT nextval('cachegroup_id_s ALTER TABLE ONLY cdn ALTER COLUMN id SET DEFAULT nextval('cdn_id_seq'::regclass); +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops +-- + +ALTER TABLE ONLY cdn_notification ALTER COLUMN id SET DEFAULT nextval('cdn_notification_id_seq'::regclass); + -- -- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.down.sql b/traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.down.sql deleted file mode 100644 index 1d2a91c90b..0000000000 --- a/traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.down.sql +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -DROP TABLE IF EXISTS cdn_notification; - -CREATE TABLE cdn_notification ( - cdn text NOT NULL, - "user" text NOT NULL, - notification text, - last_updated timestamp with time zone DEFAULT now() NOT NULL, - CONSTRAINT pk_cdn_notification PRIMARY KEY (cdn), - CONSTRAINT fk_notification_cdn FOREIGN KEY (cdn) REFERENCES cdn(name) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT fk_notification_user FOREIGN KEY ("user") REFERENCES tm_user(username) ON DELETE CASCADE ON UPDATE CASCADE -); -DROP TRIGGER IF EXISTS on_update_current_timestamp ON cdn_notification; -CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON cdn_notification FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated(); diff --git a/traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.up.sql b/traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.up.sql deleted file mode 100644 index 743adc8b09..0000000000 --- a/traffic_ops/app/db/migrations/2021031400000000_cdn_notifications_multiple.up.sql +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -DROP TABLE IF EXISTS cdn_notification; - -CREATE TABLE cdn_notification ( - id BIGSERIAL PRIMARY KEY, - cdn text NOT NULL, - "user" text NOT NULL, - notification text NOT NULL, - last_updated timestamp with time zone DEFAULT now() NOT NULL, - CONSTRAINT fk_notification_cdn FOREIGN KEY (cdn) REFERENCES cdn(name) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT fk_notification_user FOREIGN KEY ("user") REFERENCES tm_user(username) ON DELETE CASCADE ON UPDATE CASCADE -); -DROP TRIGGER IF EXISTS on_update_current_timestamp ON cdn_notification; -CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON cdn_notification FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated(); From b9c3c567afd9ecf26df4b8446651b3293681579a Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 13:42:55 -0600 Subject: [PATCH 08/48] Squash generate_uuid_for_xmpp_id_where_empty --- ...enerate_uuid_for_xmpp_id_where_empty.down.sql | 16 ---------------- ..._generate_uuid_for_xmpp_id_where_empty.up.sql | 16 ---------------- 2 files changed, 32 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.up.sql diff --git a/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.down.sql b/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.down.sql deleted file mode 100644 index 863ad28019..0000000000 --- a/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.down.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -UPDATE "server" s set xmpp_id = NULL WHERE s.xmpp_id IS NULL OR s.xmpp_id = ''; diff --git a/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.up.sql b/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.up.sql deleted file mode 100644 index 7541c74897..0000000000 --- a/traffic_ops/app/db/migrations/2021040819481469_generate_uuid_for_xmpp_id_where_empty.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -UPDATE "server" s set xmpp_id = host_name WHERE s.xmpp_id IS NULL OR s.xmpp_id = ''; From 5a33b76d4fb5facb41fd9fbde4052327a578e2c6 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 13:49:24 -0600 Subject: [PATCH 09/48] Squash dsrs_originals --- traffic_ops/app/db/create_tables.sql | 27 ++++++++- .../2021041200000000_dsrs_originals.down.sql | 30 ---------- .../2021041200000000_dsrs_originals.up.sql | 58 ------------------- 3 files changed, 25 insertions(+), 90 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 655c4a455b..8389db837e 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -690,9 +690,32 @@ CREATE TABLE IF NOT EXISTS deliveryservice_request ( id bigserial, last_edited_by_id bigint NOT NULL, last_updated timestamp with time zone NOT NULL DEFAULT now(), - deliveryservice jsonb NOT NULL, + deliveryservice jsonb DEFAULT NULL, status workflow_states NOT NULL, - CONSTRAINT deliveryservice_request_pkey PRIMARY KEY (id) + original jsonb DEFAULT NULL, + CONSTRAINT deliveryservice_request_pkey PRIMARY KEY (id), + CONSTRAINT appropriate_requested_and_original_for_change_type CHECK ( + (change_type = 'delete' AND original IS NOT NULL AND deliveryservice IS NULL) + OR + (change_type = 'create' AND original IS NULL AND deliveryservice IS NOT NULL) + OR ( + change_type = 'update' AND + deliveryservice IS NOT NULL AND + ( + ( + (status = 'complete' OR status = 'rejected' OR status = 'pending') + AND + original IS NOT NULL + ) + OR + ( + (status = 'draft' OR status = 'submitted') + AND + original IS NULL + ) + ) + ) + ) ); ALTER TABLE deliveryservice_request OWNER TO traffic_ops; diff --git a/traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.down.sql b/traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.down.sql deleted file mode 100644 index 4f3de1e769..0000000000 --- a/traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.down.sql +++ /dev/null @@ -1,30 +0,0 @@ --- syntax:postgresql -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE public.deliveryservice_request -DROP CONSTRAINT appropriate_requested_and_original_for_change_type; - -UPDATE public.deliveryservice_request -SET deliveryservice = original -WHERE deliveryservice IS NULL; - -ALTER TABLE public.deliveryservice_request -ALTER COLUMN deliveryservice -DROP DEFAULT; - -ALTER TABLE public.deliveryservice_request -ALTER COLUMN deliveryservice -SET NOT NULL; - -ALTER TABLE public.deliveryservice_request -DROP COLUMN original; diff --git a/traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.up.sql b/traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.up.sql deleted file mode 100644 index 19cd7eaf4e..0000000000 --- a/traffic_ops/app/db/migrations/2021041200000000_dsrs_originals.up.sql +++ /dev/null @@ -1,58 +0,0 @@ --- syntax:postgresql -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE public.deliveryservice_request -ADD COLUMN original jsonb DEFAULT NULL; - -UPDATE public.deliveryservice_request -SET original=deliveryservice -WHERE (status = 'complete' OR status = 'rejected' OR status = 'pending' OR change_type = 'delete') AND change_type != 'create'; - -ALTER TABLE public.deliveryservice_request -ALTER COLUMN deliveryservice -DROP NOT NULL; - -ALTER TABLE public.deliveryservice_request -ALTER COLUMN deliveryservice -SET DEFAULT NULL; - -UPDATE public.deliveryservice_request -SET deliveryservice=NULL -WHERE change_type='delete'; - -/* 'create' dsrs have no original, 'delete' dsrs have no requested, and only*/ -/* closed 'update' dsrs have originals. */ -ALTER TABLE public.deliveryservice_request -ADD CONSTRAINT appropriate_requested_and_original_for_change_type -CHECK ( - (change_type = 'delete' AND original IS NOT NULL AND deliveryservice IS NULL) - OR - (change_type = 'create' AND original IS NULL AND deliveryservice IS NOT NULL) - OR ( - change_type = 'update' AND - deliveryservice IS NOT NULL AND - ( - ( - (status = 'complete' OR status = 'rejected' OR status = 'pending') - AND - original IS NOT NULL - ) - OR - ( - (status = 'draft' OR status = 'submitted') - AND - original IS NULL - ) - ) - ) -); From 4b2154a985908f317fbfee2d33ee1cfeffaaf430 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 13:57:33 -0600 Subject: [PATCH 10/48] Squash add_cdn_lock --- traffic_ops/app/db/create_tables.sql | 36 +++++++++++++++++++ .../2021052400000000_add_cdn_lock.down.sql | 14 -------- .../2021052400000000_add_cdn_lock.up.sql | 25 ------------- 3 files changed, 36 insertions(+), 39 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 8389db837e..0989c475dc 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -498,6 +498,22 @@ ALTER TABLE cdn_id_seq OWNER TO traffic_ops; ALTER SEQUENCE cdn_id_seq OWNED BY cdn.id; +-- +-- Name: cdn_lock; Type: TABLE; Schema: public; Owner: traffic_ops +-- + +CREATE TABLE IF NOT EXISTS public.cdn_lock ( + username text NOT NULL, + cdn text NOT NULL, + message text, + soft boolean NOT NULL DEFAULT TRUE, + last_updated timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT pk_cdn_lock PRIMARY KEY ("cdn") +); + + +ALTER TABLE cdn_lock OWNER TO traffic_ops; + -- -- Name: cdn_notification; Type: TABLE; Schema: public; Owner: traffic_ops @@ -2971,6 +2987,7 @@ DECLARE 'cachegroup_parameter', 'capability', 'cdn', + 'cdn_lock', 'cdn_notification', 'coordinate', 'deliveryservice', @@ -3731,6 +3748,25 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint ADD CONSTRAINT origin_tenant_fkey FOREIGN KEY (tenant) REFERENCES tenant (id) ON DELETE RESTRICT; END IF; +IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fkey_lock_cdn' AND table_name = 'cdn_lock') THEN + -- + -- Name: fk_lock_cdn; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops + -- + + ALTER TABLE ONLY cdn_lock + ADD CONSTRAINT fk_lock_cdn FOREIGN KEY ("cdn") REFERENCES cdn(name) ON DELETE CASCADE ON UPDATE CASCADE; +END IF; + +IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fkey_lock_username' AND table_name = 'cdn_lock') THEN + -- + -- Name: fk_lock_username; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops + -- + + ALTER TABLE ONLY cdn_lock + ADD CONSTRAINT fk_lock_username FOREIGN KEY ("username") REFERENCES tm_user(username) ON DELETE CASCADE ON UPDATE CASCADE; +END IF; + + IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'cachegroup_coordinate_fkey' AND table_name = 'cachegroup') THEN -- -- Name: cachegroup_coordinate_fkey; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.down.sql b/traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.down.sql deleted file mode 100644 index 5fee7f2af3..0000000000 --- a/traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.down.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -DROP TRIGGER IF EXISTS on_update_current_timestamp ON public.cdn_lock; -DROP TABLE IF EXISTS public.cdn_lock; diff --git a/traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.up.sql b/traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.up.sql deleted file mode 100644 index c52e55b5a7..0000000000 --- a/traffic_ops/app/db/migrations/2021052400000000_add_cdn_lock.up.sql +++ /dev/null @@ -1,25 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -CREATE TABLE IF NOT EXISTS public.cdn_lock ( - username text NOT NULL, - cdn text NOT NULL, - message text, - soft boolean NOT NULL DEFAULT TRUE, - last_updated timestamp with time zone DEFAULT now() NOT NULL, - CONSTRAINT pk_cdn_lock PRIMARY KEY ("cdn"), - CONSTRAINT fk_lock_cdn FOREIGN KEY ("cdn") REFERENCES cdn(name) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT fk_lock_username FOREIGN KEY ("username") REFERENCES tm_user(username) ON DELETE CASCADE ON UPDATE CASCADE - ); - -DROP TRIGGER IF EXISTS on_update_current_timestamp ON public.cdn_lock; -CREATE TRIGGER on_update_current_timestamp BEFORE UPDATE ON public.cdn_lock FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated(); From be34e637df94aff2c0f8e3b14832c3498e04d3ff Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 14:16:59 -0600 Subject: [PATCH 11/48] Squash ds_tls_versions --- traffic_ops/app/db/create_tables.sql | 76 +++++++++++++++++++ .../2021061100000000_ds_tls_versions.down.sql | 30 -------- .../2021061100000000_ds_tls_versions.up.sql | 65 ---------------- 3 files changed, 76 insertions(+), 95 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 0989c475dc..4ac92ab9b4 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -143,6 +143,42 @@ LANGUAGE plpgsql; ALTER FUNCTION public.on_delete_current_timestamp_last_updated() OWNER TO traffic_ops; +-- +-- Name: update_ds_timestamp_on_insert(); Type: FUNCTION; Schema: public; Owner: traffic_ops +-- + +CREATE OR REPLACE FUNCTION update_ds_timestamp_on_insert() + RETURNS trigger + AS $$ +BEGIN + UPDATE deliveryservice + SET last_updated=now() + WHERE id IN ( + SELECT deliveryservice + FROM CAST(NEW AS deliveryservice_tls_version) + ); + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +-- +-- Name: update_ds_timestamp_on_delete(); Type: FUNCTION; Schema: public; Owner: traffic_ops +-- + +CREATE OR REPLACE FUNCTION update_ds_timestamp_on_delete() + RETURNS trigger + AS $$ +BEGIN + UPDATE deliveryservice + SET last_updated=now() + WHERE id IN ( + SELECT deliveryservice + FROM CAST(OLD AS deliveryservice_tls_version) + ); + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + SET default_tablespace = ''; SET default_with_oids = false; @@ -763,6 +799,35 @@ CREATE TABLE IF NOT EXISTS deliveryservice_server ( ALTER TABLE deliveryservice_server OWNER TO traffic_ops; +-- +-- Name: deliveryservice_tls_version; Type: TABLE; Schema: public; Owner: traffic_ops +-- + +CREATE TABLE IF NOT EXISTS deliveryservice_tls_version ( + deliveryservice bigint NOT NULL, + tls_version text NOT NULL, + CONSTRAINT deliveryservice_tls_version_pkey PRIMARY KEY (deliveryservice, tls_version), + CONSTRAINT deliveryservice_tls_version_tls_version_check CHECK (tls_version <> '') +); + +ALTER TABLE deliveryservice_tls_version OWNER TO traffic_ops; + +-- +-- Name: update_ds_timestamp_on_tls_version_insertion; Type: TRIGGER; Schema: public; Owner: traffic_ops +-- +DROP TRIGGER IF EXISTS update_ds_timestamp_on_tls_version_insertion on deliveryservice_tls_version; +CREATE TRIGGER update_ds_timestamp_on_tls_version_insertion + AFTER INSERT ON deliveryservice_tls_version + FOR EACH ROW EXECUTE PROCEDURE update_ds_timestamp_on_insert(); + +-- +-- Name: update_ds_timestamp_on_tls_version_delete; Type: TRIGGER; Schema: public; Owner: traffic_ops +-- +DROP TRIGGER IF EXISTS update_ds_timestamp_on_tls_version_delete on deliveryservice_tls_version; +CREATE TRIGGER update_ds_timestamp_on_tls_version_delete + AFTER DELETE ON deliveryservice_tls_version + FOR EACH ROW EXECUTE PROCEDURE update_ds_timestamp_on_delete(); + -- -- Name: deliveryservice_tmuser; Type: TABLE; Schema: public; Owner: traffic_ops -- @@ -3100,6 +3165,17 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint ADD CONSTRAINT deliveryservice_service_category_fkey FOREIGN KEY (service_category) REFERENCES service_category(name) ON UPDATE CASCADE; END IF; + +IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'deliveryservice_tls_version_deliveryservice_fkey' AND table_name = 'deliveryservice_tls_version') THEN + -- + -- Name: deliveryservice_tls_version_deliveryservice_fkey; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops + -- + + ALTER TABLE ONLY deliveryservice_tls_version + ADD CONSTRAINT deliveryservice_tls_version_deliveryservice_fkey FOREIGN KEY (deliveryservice) REFERENCES deliveryservice(id) ON DELETE CASCADE ON UPDATE CASCADE; +END IF; + + IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'ip_address_server_fkey' AND table_name = 'ip_address') THEN -- -- Name: ip_address_server_fkey; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.down.sql b/traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.down.sql deleted file mode 100644 index 46ce8c5aad..0000000000 --- a/traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.down.sql +++ /dev/null @@ -1,30 +0,0 @@ --- syntax:postgresql -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -UPDATE public.deliveryservice_request -SET - deliveryservice = deliveryservice - 'tlsVersions' -WHERE - deliveryservice IS NOT NULL; - -UPDATE public.deliveryservice_request -SET - original = original - 'tlsVersions' -WHERE - original IS NOT NULL; - -DROP TRIGGER IF EXISTS update_ds_timestamp_on_tls_version_insertion ON public.deliveryservice_tls_version; -DROP TRIGGER IF EXISTS update_ds_timestamp_on_tls_version_delete ON public.deliveryservice_tls_version; -DROP TABLE IF EXISTS public.deliveryservice_tls_version; -DROP FUNCTION IF EXISTS update_ds_timestamp_on_insert(); -DROP FUNCTION IF EXISTS update_ds_timestamp_on_delete(); diff --git a/traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.up.sql b/traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.up.sql deleted file mode 100644 index d49c6ba71f..0000000000 --- a/traffic_ops/app/db/migrations/2021061100000000_ds_tls_versions.up.sql +++ /dev/null @@ -1,65 +0,0 @@ --- syntax:postgresql -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -CREATE TABLE IF NOT EXISTS public.deliveryservice_tls_version ( - deliveryservice bigint NOT NULL REFERENCES public.deliveryservice(id) ON DELETE CASCADE ON UPDATE CASCADE, - tls_version text NOT NULL CHECK (tls_version <> ''), - PRIMARY KEY (deliveryservice, tls_version) -); - -CREATE OR REPLACE FUNCTION update_ds_timestamp_on_insert() - RETURNS trigger - AS $$ -BEGIN - UPDATE public.deliveryservice - SET last_updated=now() - WHERE id IN ( - SELECT deliveryservice - FROM CAST(NEW AS deliveryservice_tls_version) - ); - RETURN NULL; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION update_ds_timestamp_on_delete() - RETURNS trigger - AS $$ -BEGIN - UPDATE public.deliveryservice - SET last_updated=now() - WHERE id IN ( - SELECT deliveryservice - FROM CAST(OLD AS deliveryservice_tls_version) - ); - RETURN NULL; -END; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER update_ds_timestamp_on_tls_version_insertion - AFTER INSERT ON public.deliveryservice_tls_version - FOR EACH ROW EXECUTE PROCEDURE update_ds_timestamp_on_insert(); - -CREATE TRIGGER update_ds_timestamp_on_tls_version_delete - AFTER DELETE ON public.deliveryservice_tls_version - FOR EACH ROW EXECUTE PROCEDURE update_ds_timestamp_on_delete(); - -UPDATE public.deliveryservice_request -SET - deliveryservice = jsonb_set(deliveryservice, '{tlsVersions}', 'null') -WHERE - deliveryservice IS NOT NULL; -UPDATE public.deliveryservice_request -SET - original = jsonb_set(original, '{tlsVersions}', 'null') -WHERE - original IS NOT NULL; From 0d7dccdcc8486453b55c38db1a74c0fb5914e6c5 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 14:48:35 -0600 Subject: [PATCH 12/48] Squash remove_ds_mso_alg --- traffic_ops/app/db/create_tables.sql | 1 - .../2021070600000000_remove_ds_mso_alg.down.sql | 13 ------------- .../2021070600000000_remove_ds_mso_alg.up.sql | 13 ------------- 3 files changed, 27 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 4ac92ab9b4..f868cc3050 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -646,7 +646,6 @@ CREATE TABLE IF NOT EXISTS deliveryservice ( geo_provider smallint DEFAULT '0'::smallint, geo_limit_countries text, logs_enabled boolean DEFAULT false, - multi_site_origin_algorithm smallint, geolimit_redirect_url text, tenant_id bigint NOT NULL, routing_name text NOT NULL DEFAULT 'cdn', diff --git a/traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.down.sql b/traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.down.sql deleted file mode 100644 index b8005a7973..0000000000 --- a/traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.down.sql +++ /dev/null @@ -1,13 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE deliveryservice ADD COLUMN multi_site_origin_algorithm smallint; diff --git a/traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.up.sql b/traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.up.sql deleted file mode 100644 index cb8d7ed87b..0000000000 --- a/traffic_ops/app/db/migrations/2021070600000000_remove_ds_mso_alg.up.sql +++ /dev/null @@ -1,13 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -ALTER TABLE deliveryservice DROP COLUMN multi_site_origin_algorithm; From b99f75c8f97cd20100e6d374fcb017f835b1a1a1 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 14:50:14 -0600 Subject: [PATCH 13/48] Squash add_tm_user_last_authenticated --- traffic_ops/app/db/create_tables.sql | 1 + ...000_add_tm_user_last_authenticated.down.sql | 18 ------------------ ...00000_add_tm_user_last_authenticated.up.sql | 18 ------------------ 3 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index f868cc3050..ed2f4ea6cd 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -1895,6 +1895,7 @@ CREATE TABLE IF NOT EXISTS tm_user ( token text, registration_sent timestamp with time zone, tenant_id bigint NOT NULL, + last_authenticated timestamp with time zone, CONSTRAINT idx_89765_primary PRIMARY KEY (id) ); diff --git a/traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.down.sql b/traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.down.sql deleted file mode 100644 index ae586523bf..0000000000 --- a/traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.down.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE tm_user DROP COLUMN last_authenticated; diff --git a/traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.up.sql b/traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.up.sql deleted file mode 100644 index a7d493f635..0000000000 --- a/traffic_ops/app/db/migrations/2021070800000000_add_tm_user_last_authenticated.up.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE tm_user ADD COLUMN last_authenticated timestamp with time zone; From 6608f60e6f28291495a0f000c27c2b9cf93bcaee Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 14:57:42 -0600 Subject: [PATCH 14/48] Squash fix_indices --- traffic_ops/app/db/create_tables.sql | 4 ++-- .../2021080408053529_fix_indices.down.sql | 22 ------------------- .../2021080408053529_fix_indices.up.sql | 22 ------------------- 3 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021080408053529_fix_indices.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021080408053529_fix_indices.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index ed2f4ea6cd..3665e1b5fe 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -3014,14 +3014,14 @@ BEGIN IF table_name = 'topology' THEN EXECUTE FORMAT(' CREATE INDEX IF NOT EXISTS %s_last_updated_idx - ON %s_cachegroup (last_updated DESC NULLS LAST); + ON %s (last_updated DESC NULLS LAST); ', QUOTE_IDENT(table_name), QUOTE_IDENT(table_name) ); ELSIF table_name = 'phys_location' THEN EXECUTE FORMAT(' - CREATE INDEX IF NOT EXISTS pys_location_last_updated_idx + CREATE INDEX IF NOT EXISTS phys_location_last_updated_idx ON %s (last_updated DESC NULLS LAST); ', QUOTE_IDENT(table_name) diff --git a/traffic_ops/app/db/migrations/2021080408053529_fix_indices.down.sql b/traffic_ops/app/db/migrations/2021080408053529_fix_indices.down.sql deleted file mode 100644 index 031a2549c3..0000000000 --- a/traffic_ops/app/db/migrations/2021080408053529_fix_indices.down.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER INDEX phys_location_last_updated_idx RENAME TO pys_location_last_updated_idx; - -DROP INDEX topology_last_updated_idx; - -CREATE INDEX topology_last_updated_idx ON topology_cachegroup (last_updated DESC NULLS LAST); diff --git a/traffic_ops/app/db/migrations/2021080408053529_fix_indices.up.sql b/traffic_ops/app/db/migrations/2021080408053529_fix_indices.up.sql deleted file mode 100644 index ed0ea5599d..0000000000 --- a/traffic_ops/app/db/migrations/2021080408053529_fix_indices.up.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER INDEX pys_location_last_updated_idx RENAME TO phys_location_last_updated_idx; - -DROP INDEX topology_last_updated_idx; - -CREATE INDEX topology_last_updated_idx ON topology (last_updated DESC NULLS LAST); From cfcdda292241a5e7f82647eada43b02a2d38e72a Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:15:58 -0600 Subject: [PATCH 15/48] Squash le_dns_challenge_xml_id --- traffic_ops/app/db/create_tables.sql | 3 ++- ...0914220900_le_dns_challenge_xml_id.down.sql | 18 ------------------ ...090914220900_le_dns_challenge_xml_id.up.sql | 18 ------------------ 3 files changed, 2 insertions(+), 37 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 3665e1b5fe..c7ef118bd3 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -881,7 +881,8 @@ ALTER SEQUENCE division_id_seq OWNED BY division.id; CREATE TABLE IF NOT EXISTS dnschallenges ( fqdn text NOT NULL, - record text NOT NULL + record text NOT NULL, + xml_id text NOT NULL ); -- diff --git a/traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.down.sql b/traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.down.sql deleted file mode 100644 index d2e7e6171d..0000000000 --- a/traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.down.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE dnschallenges DROP COLUMN IF EXISTS xml_id; diff --git a/traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.up.sql b/traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.up.sql deleted file mode 100644 index 64df6a05b3..0000000000 --- a/traffic_ops/app/db/migrations/2021090914220900_le_dns_challenge_xml_id.up.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE dnschallenges ADD COLUMN xml_id text NOT NULL; From 4c981bae9da4842e664e2d66cd44f580f3539ae1 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:17:25 -0600 Subject: [PATCH 16/48] Squash roles_and_permissions --- traffic_ops/app/db/create_tables.sql | 11 +------ ...10210014200_roles_and_permissions.down.sql | 31 ------------------- ...1110210014200_roles_and_permissions.up.sql | 31 ------------------- 3 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index c7ef118bd3..163a11ce94 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -1494,7 +1494,7 @@ ALTER SEQUENCE region_id_seq OWNED BY region.id; CREATE TABLE IF NOT EXISTS role ( id bigint, name text NOT NULL, - description text, + description text NOT NULL, priv_level bigint NOT NULL, last_updated timestamp with time zone NOT NULL DEFAULT now(), CONSTRAINT role_name_unique UNIQUE (name), @@ -3907,15 +3907,6 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint ADD CONSTRAINT fk_role_id FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE CASCADE; END IF; -IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_cap_name' AND table_name = 'role_capability') THEN - -- - -- Name: fk_cap_name; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops - -- - - ALTER TABLE ONLY role_capability - ADD CONSTRAINT fk_cap_name FOREIGN KEY (cap_name) REFERENCES capability (name) ON DELETE RESTRICT; -END IF; - IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'snapshot_cdn_fkey' AND table_name = 'snapshot') THEN -- -- Name: snapshot_cdn_fkey; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.down.sql b/traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.down.sql deleted file mode 100644 index 163d227fef..0000000000 --- a/traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.down.sql +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE ONLY public.role -ALTER COLUMN "description" -DROP NOT NULL; - -DELETE FROM public.role_capability -WHERE cap_name NOT IN ( - SELECT DISTINCT "name" - FROM public.capability -); - -ALTER TABLE ONLY public.role_capability -ADD CONSTRAINT fk_cap_name -FOREIGN KEY (cap_name) -REFERENCES public.capability (name) ON DELETE RESTRICT; diff --git a/traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.up.sql b/traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.up.sql deleted file mode 100644 index 5b748e475d..0000000000 --- a/traffic_ops/app/db/migrations/2021110210014200_roles_and_permissions.up.sql +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -UPDATE public.role -SET "description"='' -WHERE "description" IS NULL; - -ALTER TABLE public.role -ALTER COLUMN "description" -SET NOT NULL; - -ALTER TABLE public.role_capability -DROP CONSTRAINT fk_cap_name; - -INSERT INTO public.role("name", "description", priv_level) -VALUES ('admin', 'Has access to everything.', 30) -ON CONFLICT ("name") DO NOTHING; From d83756adb6e14ff00be107702ce7b9d5b7e19bef Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:18:12 -0600 Subject: [PATCH 17/48] Squash no_null_username --- traffic_ops/app/db/create_tables.sql | 2 +- ...2021110210031500_no_null_username.down.sql | 20 ------------------- .../2021110210031500_no_null_username.up.sql | 20 ------------------- 3 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021110210031500_no_null_username.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021110210031500_no_null_username.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 163a11ce94..cddc132a88 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -1874,7 +1874,7 @@ CREATE TABLE IF NOT EXISTS tenant ( CREATE TABLE IF NOT EXISTS tm_user ( id bigint NOT NULL, - username text, + username text NOT NULL, public_ssh_key text, role bigint, uid bigint, diff --git a/traffic_ops/app/db/migrations/2021110210031500_no_null_username.down.sql b/traffic_ops/app/db/migrations/2021110210031500_no_null_username.down.sql deleted file mode 100644 index 82ab284af9..0000000000 --- a/traffic_ops/app/db/migrations/2021110210031500_no_null_username.down.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE ONLY public.tm_user -ALTER COLUMN username -DROP NOT NULL; diff --git a/traffic_ops/app/db/migrations/2021110210031500_no_null_username.up.sql b/traffic_ops/app/db/migrations/2021110210031500_no_null_username.up.sql deleted file mode 100644 index 734baf825b..0000000000 --- a/traffic_ops/app/db/migrations/2021110210031500_no_null_username.up.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE ONLY public.tm_user -ALTER COLUMN username -SET NOT NULL; From 77592a02f5002e779c0217545ab09fd33358f3de Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:21:09 -0600 Subject: [PATCH 18/48] Squash add_job_start_time_idx --- traffic_ops/app/db/create_tables.sql | 8 ++++++++ ...10210060800_add_job_start_time_idx.down.sql | 18 ------------------ ...1110210060800_add_job_start_time_idx.up.sql | 18 ------------------ 3 files changed, 8 insertions(+), 36 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index cddc132a88..ec9970bf8f 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -2535,6 +2535,14 @@ IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND c CREATE INDEX IF NOT EXISTS idx_89593_fk_job_user_id1 ON job USING btree (job_user); END IF; +IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND column_name = 'start_time') THEN + -- + -- Name: job_start_time_idx; Type: INDEX; Schema: public; Owner: traffic_ops + -- + + CREATE INDEX IF NOT EXISTS job_start_time_idx ON job (start_time DESC NULLS LAST); +END IF; + IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'log' AND column_name = 'tm_user') THEN -- -- Name: idx_89634_fk_log_1; Type: INDEX; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.down.sql b/traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.down.sql deleted file mode 100644 index bef55a7ef1..0000000000 --- a/traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.down.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -DROP INDEX job_start_time_idx; diff --git a/traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.up.sql b/traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.up.sql deleted file mode 100644 index 1d6cb5364b..0000000000 --- a/traffic_ops/app/db/migrations/2021110210060800_add_job_start_time_idx.up.sql +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -CREATE INDEX job_start_time_idx ON job (start_time DESC NULLS LAST); From 06bb4b04bf105e4b5f4e229fdd4c4442ac82972d Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:22:41 -0600 Subject: [PATCH 19/48] Squash remove_user_role --- traffic_ops/app/db/create_tables.sql | 36 ++----------------- ...2021110210075100_remove_user_role.down.sql | 36 ------------------- .../2021110210075100_remove_user_role.up.sql | 21 ----------- 3 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021110210075100_remove_user_role.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021110210075100_remove_user_role.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index ec9970bf8f..89fc510a07 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -2040,18 +2040,6 @@ ALTER TABLE type_id_seq OWNER TO traffic_ops; ALTER SEQUENCE type_id_seq OWNED BY type.id; --- --- Name: user_role; Type: TABLE; Schema: public; Owner: traffic_ops --- - -CREATE TABLE IF NOT EXISTS user_role ( - user_id bigint NOT NULL, - role_id bigint NOT NULL, - last_updated timestamp with time zone NOT NULL DEFAULT now() -); - -ALTER TABLE user_role OWNER TO traffic_ops; - DO $$ BEGIN IF NOT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'profile_type_values' @@ -2988,8 +2976,7 @@ DO $$ 'topology', 'topology_cachegroup', 'topology_cachegroup_parents', - 'type', - 'user_role' + 'type' ] AS VARCHAR[]); table_name TEXT; trigger_name TEXT := 'on_delete_current_timestamp'; @@ -3101,8 +3088,7 @@ DECLARE 'topology', 'topology_cachegroup', 'topology_cachegroup_parents', - 'type', - 'user_role' + 'type' ] AS VARCHAR[]); table_name TEXT; trigger_name TEXT := 'on_update_current_timestamp'; @@ -3941,24 +3927,6 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint ALTER TABLE ONLY tm_user ADD CONSTRAINT fk_tenantid FOREIGN KEY (tenant_id) REFERENCES tenant (id) MATCH FULL; END IF; - -IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_user_id' AND table_name = 'user_role') THEN - -- - -- Name: fk_user_1; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops - -- - - ALTER TABLE ONLY user_role - ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES tm_user (id) ON DELETE CASCADE; -END IF; - -IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_role_id' AND table_name = 'user_role') THEN - -- - -- Name: fk_role_id; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops - -- - - ALTER TABLE ONLY user_role - ADD CONSTRAINT fk_role_id FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE RESTRICT; -END IF; END$$; diff --git a/traffic_ops/app/db/migrations/2021110210075100_remove_user_role.down.sql b/traffic_ops/app/db/migrations/2021110210075100_remove_user_role.down.sql deleted file mode 100644 index a544787495..0000000000 --- a/traffic_ops/app/db/migrations/2021110210075100_remove_user_role.down.sql +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -CREATE TABLE IF NOT EXISTS user_role ( -user_id bigint NOT NULL, -role_id bigint NOT NULL, -last_updated timestamp with time zone NOT NULL DEFAULT now() -); - -ALTER TABLE user_role OWNER TO traffic_ops; - -CREATE OR REPLACE FUNCTION create_constraint_if_not_exists (c_name text, t_name text, constraint_string text) -RETURNS void AS -$$ -BEGIN - IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = c_name AND table_name = t_name) then execute constraint_string; -END IF; -END; -$$ LANGUAGE PLPGSQL; - -SELECT create_constraint_if_not_exists('fk_user_id', 'user_role', 'ALTER TABLE ONLY user_role ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES tm_user (id) ON DELETE CASCADE;'); -SELECT create_constraint_if_not_exists('fk_role_id', 'user_role', 'ALTER TABLE ONLY user_role ADD CONSTRAINT fk_role_id FOREIGN KEY (role_id) REFERENCES role (id) ON DELETE RESTRICT;'); diff --git a/traffic_ops/app/db/migrations/2021110210075100_remove_user_role.up.sql b/traffic_ops/app/db/migrations/2021110210075100_remove_user_role.up.sql deleted file mode 100644 index 660eb4795e..0000000000 --- a/traffic_ops/app/db/migrations/2021110210075100_remove_user_role.up.sql +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE user_role DROP CONSTRAINT fk_user_id; -ALTER TABLE user_role DROP CONSTRAINT fk_role_id; - -DROP TABLE IF EXISTS user_role; From d60b657ea13f0cedbec5738aa0d6ce52a42acc02 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:23:24 -0600 Subject: [PATCH 20/48] Squash add_permissions --- .../2021110210085600_add_permissions.down.sql | 138 --------------- .../2021110210085600_add_permissions.up.sql | 164 ------------------ 2 files changed, 302 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021110210085600_add_permissions.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021110210085600_add_permissions.up.sql diff --git a/traffic_ops/app/db/migrations/2021110210085600_add_permissions.down.sql b/traffic_ops/app/db/migrations/2021110210085600_add_permissions.down.sql deleted file mode 100644 index b4bbf458c2..0000000000 --- a/traffic_ops/app/db/migrations/2021110210085600_add_permissions.down.sql +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - --- remove from role_capability table -DELETE FROM public.role_capability WHERE cap_name='ASN:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='ASN:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='ASN:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='CACHE-GROUP:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='CACHE-GROUP:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='CACHE-GROUP:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='CDN-LOCK:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='CDN-LOCK:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='CDN-SNAPSHOT:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='CDN:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='CDN:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='CDN:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='COORDINATE:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='COORDINATE:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='COORDINATE:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='DELIVERY-SERVICE-SAFE:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='DELIVERY-SERVICE:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='DELIVERY-SERVICE:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='DIVISION:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='DIVISION:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='DIVISION:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='DNS-SEC:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='ISO:GENERATE'; -DELETE FROM public.role_capability WHERE cap_name='ORIGIN:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='ORIGIN:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='ORIGIN:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='PARAMETER:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='PARAMETER:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='PARAMETER:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='PHYSICAL-LOCATION:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='PHYSICAL-LOCATION:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='PHYSICAL-LOCATION:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='PROFILE:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='PROFILE:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='PROFILE:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='REGION:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='REGION:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='REGION:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CAPABILITY:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CAPABILITY:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CAPABILITY:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER:QUEUE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVICE-CATEGORY:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVICE-CATEGORY:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='SERVICE-CATEGORY:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='STATIC-DN:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='STATIC-DN:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='STATIC-DN:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='STATUS:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='STATUS:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='STATUS:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='TENANT:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='TENANT:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='TENANT:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='TOPOLOGY:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='TOPOLOGY:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='TOPOLOGY:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='TYPE:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='TYPE:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='TYPE:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='USER:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='USER:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CHECK:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CHECK:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='STAT:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION-RESOLVER:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION-RESOLVER:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='DELIVERY-SERVICE:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='JOB:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='JOB:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='JOB:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='DS-REQUEST:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='DS-REQUEST:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='DS-REQUEST:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='STEERING:CREATE'; -DELETE FROM public.role_capability WHERE cap_name='STEERING:UPDATE'; -DELETE FROM public.role_capability WHERE cap_name='STEERING:DELETE'; -DELETE FROM public.role_capability WHERE cap_name='ASN:READ'; -DELETE FROM public.role_capability WHERE cap_name='ASYNC-STATUS:READ'; -DELETE FROM public.role_capability WHERE cap_name='CACHE-GROUP:READ'; -DELETE FROM public.role_capability WHERE cap_name='CAPABILITY:READ'; -DELETE FROM public.role_capability WHERE cap_name='CDN-SNAPSHOT:READ'; -DELETE FROM public.role_capability WHERE cap_name='CDN:READ'; -DELETE FROM public.role_capability WHERE cap_name='COORDINATE:READ'; -DELETE FROM public.role_capability WHERE cap_name='DELIVERY-SERVICE:READ'; -DELETE FROM public.role_capability WHERE cap_name='DIVISION:READ'; -DELETE FROM public.role_capability WHERE cap_name='DS-REQUEST:READ'; -DELETE FROM public.role_capability WHERE cap_name='DS-SECURITY-KEY:READ'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION:READ'; -DELETE FROM public.role_capability WHERE cap_name='FEDERATION-RESOLVER:READ'; -DELETE FROM public.role_capability WHERE cap_name='ISO:READ'; -DELETE FROM public.role_capability WHERE cap_name='JOB:READ'; -DELETE FROM public.role_capability WHERE cap_name='LOG:READ'; -DELETE FROM public.role_capability WHERE cap_name='MONITOR-CONFIG:READ'; -DELETE FROM public.role_capability WHERE cap_name='ORIGIN:READ'; -DELETE FROM public.role_capability WHERE cap_name='PARAMETER:READ'; -DELETE FROM public.role_capability WHERE cap_name='PHYSICAL-LOCATION:READ'; -DELETE FROM public.role_capability WHERE cap_name='PLUGIN-READ'; -DELETE FROM public.role_capability WHERE cap_name='PROFILE:READ'; -DELETE FROM public.role_capability WHERE cap_name='REGION:READ'; -DELETE FROM public.role_capability WHERE cap_name='ROLE:READ'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CAPABILITY:READ'; -DELETE FROM public.role_capability WHERE cap_name='SERVER:READ'; -DELETE FROM public.role_capability WHERE cap_name='SERVICE-CATEGORY:READ'; -DELETE FROM public.role_capability WHERE cap_name='STATIC-DN:READ'; -DELETE FROM public.role_capability WHERE cap_name='STATUS:READ'; -DELETE FROM public.role_capability WHERE cap_name='SERVER-CHECK:READ'; -DELETE FROM public.role_capability WHERE cap_name='STEERING:READ'; -DELETE FROM public.role_capability WHERE cap_name='STAT:READ'; -DELETE FROM public.role_capability WHERE cap_name='TENANT:READ'; -DELETE FROM public.role_capability WHERE cap_name='TOPOLOGY:READ'; -DELETE FROM public.role_capability WHERE cap_name='TRAFFIC-VAULT:READ'; -DELETE FROM public.role_capability WHERE cap_name='TYPE:READ'; -DELETE FROM public.role_capability WHERE cap_name='USER:READ'; diff --git a/traffic_ops/app/db/migrations/2021110210085600_add_permissions.up.sql b/traffic_ops/app/db/migrations/2021110210085600_add_permissions.up.sql deleted file mode 100644 index 7a489db9ee..0000000000 --- a/traffic_ops/app/db/migrations/2021110210085600_add_permissions.up.sql +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - --- add built-in roles -INSERT INTO public.role (name, description, priv_level) VALUES ('operations', 'Has all reads and most write capabilities', 20) ON CONFLICT (name) DO NOTHING; -INSERT INTO public.role (name, description, priv_level) VALUES ('read-only', 'Has access to all read capabilities', 10) ON CONFLICT (name) DO NOTHING; -INSERT INTO public.role (name, description, priv_level) values ('disallowed', 'Block all access', 0) ON CONFLICT (name) DO NOTHING; -INSERT INTO public.role (name, description, priv_level) VALUES ('portal','Portal User', 2) ON CONFLICT DO NOTHING; -INSERT INTO public.role (name, description, priv_level) VALUES ('steering','Steering User', 15) ON CONFLICT DO NOTHING; -INSERT INTO public.role (name, description, priv_level) VALUES ('federation','Role for Secondary CZF', 15) ON CONFLICT DO NOTHING; - --- add permissions to roles in order of decreasing priv level -INSERT INTO public.role_capability SELECT id, perm FROM public.role CROSS JOIN (VALUES -('ASN:CREATE'), -('ASN:DELETE'), -('ASN:UPDATE'), -('CACHE-GROUP:CREATE'), -('CACHE-GROUP:DELETE'), -('CACHE-GROUP:UPDATE'), -('CDN-LOCK:CREATE'), -('CDN-LOCK:DELETE'), -('CDN-SNAPSHOT:CREATE'), -('CDN:CREATE'), -('CDN:DELETE'), -('CDN:UPDATE'), -('COORDINATE:CREATE'), -('COORDINATE:UPDATE'), -('COORDINATE:DELETE'), -('DELIVERY-SERVICE-SAFE:UPDATE'), -('DELIVERY-SERVICE:CREATE'), -('DELIVERY-SERVICE:DELETE'), -('DIVISION:CREATE'), -('DIVISION:DELETE'), -('DIVISION:UPDATE'), -('DNS-SEC:UPDATE'), -('ISO:GENERATE'), -('ORIGIN:CREATE'), -('ORIGIN:DELETE'), -('ORIGIN:UPDATE'), -('PARAMETER:CREATE'), -('PARAMETER:DELETE'), -('PARAMETER:UPDATE'), -('PHYSICAL-LOCATION:CREATE'), -('PHYSICAL-LOCATION:DELETE'), -('PHYSICAL-LOCATION:UPDATE'), -('PROFILE:CREATE'), -('PROFILE:DELETE'), -('PROFILE:UPDATE'), -('REGION:CREATE'), -('REGION:DELETE'), -('REGION:UPDATE'), -('SERVER-CAPABILITY:CREATE'), -('SERVER-CAPABILITY:DELETE'), -('SERVER-CAPABILITY:UPDATE'), -('SERVER:CREATE'), -('SERVER:DELETE'), -('SERVER:QUEUE'), -('SERVER:UPDATE'), -('SERVICE-CATEGORY:CREATE'), -('SERVICE-CATEGORY:DELETE'), -('SERVICE-CATEGORY:UPDATE'), -('STATIC-DN:CREATE'), -('STATIC-DN:DELETE'), -('STATIC-DN:UPDATE'), -('STATUS:CREATE'), -('STATUS:DELETE'), -('STATUS:UPDATE'), -('TENANT:CREATE'), -('TENANT:DELETE'), -('TENANT:UPDATE'), -('TOPOLOGY:CREATE'), -('TOPOLOGY:DELETE'), -('TOPOLOGY:UPDATE'), -('TYPE:CREATE'), -('TYPE:DELETE'), -('TYPE:UPDATE'), -('USER:CREATE'), -('USER:UPDATE'), -('SERVER-CHECK:CREATE'), -('SERVER-CHECK:DELETE')) AS perms(perm) -WHERE priv_level >= 20 ON CONFLICT DO NOTHING; - -INSERT INTO public.role_capability SELECT id, perm FROM public.role CROSS JOIN (VALUES -('FEDERATION:CREATE'), -('FEDERATION:UPDATE'), -('FEDERATION:DELETE'), -('FEDERATION-RESOLVER:CREATE'), -('FEDERATION-RESOLVER:DELETE'), -('DELIVERY-SERVICE:UPDATE'), -('JOB:CREATE'), -('JOB:UPDATE'), -('JOB:DELETE'), -('DS-REQUEST:UPDATE'), -('DS-REQUEST:CREATE'), -('DS-REQUEST:DELETE'), -('STEERING:CREATE'), -('STEERING:UPDATE'), -('STEERING:DELETE')) AS perms(perm) -WHERE priv_level >= 15 ON CONFLICT DO NOTHING; - -INSERT INTO public.role_capability SELECT id, perm FROM public.role CROSS JOIN (VALUES -('ASN:READ'), -('ASYNC-STATUS:READ'), -('CACHE-GROUP:READ'), -('CAPABILITY:READ'), -('CDN-SNAPSHOT:READ'), -('CDN:READ'), -('COORDINATE:READ'), -('DELIVERY-SERVICE:READ'), -('DIVISION:READ'), -('DS-REQUEST:READ'), -('DS-SECURITY-KEY:READ'), -('FEDERATION:READ'), -('FEDERATION-RESOLVER:READ'), -('ISO:READ'), -('JOB:READ'), -('LOG:READ'), -('MONITOR-CONFIG:READ'), -('ORIGIN:READ'), -('PARAMETER:READ'), -('PHYSICAL-LOCATION:READ'), -('PLUGIN-READ'), -('PROFILE:READ'), -('REGION:READ'), -('ROLE:READ'), -('SERVER-CAPABILITY:READ'), -('SERVER:READ'), -('SERVICE-CATEGORY:READ'), -('STATIC-DN:READ'), -('STATUS:READ'), -('SERVER-CHECK:READ'), -('STEERING:READ'), -('STAT:READ'), -('TENANT:READ'), -('TOPOLOGY:READ'), -('TRAFFIC-VAULT:READ'), -('TYPE:READ'), -('USER:READ'), -('STAT:CREATE')) AS perms(perm) -WHERE priv_level >= 10 ON CONFLICT DO NOTHING; - -INSERT INTO public.role_capability -SELECT role, perm -FROM public.tm_user -CROSS JOIN (VALUES -('SERVER-CHECK:CREATE'), -('SERVER-CHECK:DELETE'), -('SERVER-CHECK:READ'), -('SERVER:READ')) AS perms(perm) -WHERE username = 'extension' ON CONFLICT DO NOTHING; From 71de1a233a46f4fc617df22073ca28a24e5af45b Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:48:44 -0600 Subject: [PATCH 21/48] Squash refetch --- traffic_ops/app/db/create_tables.sql | 135 +--------------- .../2021110211525600_refetch.down.sql | 145 ------------------ .../2021110211525600_refetch.up.sql | 61 -------- 3 files changed, 2 insertions(+), 339 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021110211525600_refetch.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021110211525600_refetch.up.sql diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 89fc510a07..eeaa587dc0 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -1100,63 +1100,20 @@ CREATE TRIGGER before_update_ip_address_trigger CREATE TABLE IF NOT EXISTS job ( id bigint NOT NULL, - agent bigint, - object_type text, - object_name text, - keyword text NOT NULL, - parameters text, + ttl_hr integer, asset_url text NOT NULL, - asset_type text NOT NULL, - status bigint NOT NULL, start_time timestamp with time zone NOT NULL, entered_time timestamp with time zone NOT NULL, job_user bigint NOT NULL, last_updated timestamp with time zone NOT NULL DEFAULT now(), job_deliveryservice bigint, + invalidation_type text NOT NULL DEFAULT 'REFRESH', CONSTRAINT idx_89593_primary PRIMARY KEY (id) ); ALTER TABLE job OWNER TO traffic_ops; --- --- Name: job_agent; Type: TABLE; Schema: public; Owner: traffic_ops --- - -CREATE TABLE IF NOT EXISTS job_agent ( - id bigint NOT NULL, - name text, - description text, - active integer DEFAULT 0 NOT NULL, - last_updated timestamp with time zone NOT NULL DEFAULT now(), - CONSTRAINT job_agent_name_unique UNIQUE (name), - CONSTRAINT idx_89603_primary PRIMARY KEY (id) -); - - -ALTER TABLE job_agent OWNER TO traffic_ops; - --- --- Name: job_agent_id_seq; Type: SEQUENCE; Schema: public; Owner: traffic_ops --- - -CREATE SEQUENCE IF NOT EXISTS job_agent_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE job_agent_id_seq OWNER TO traffic_ops; - --- --- Name: job_agent_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: traffic_ops --- - -ALTER SEQUENCE job_agent_id_seq OWNED BY job_agent.id; - - -- -- Name: job_id_seq; Type: SEQUENCE; Schema: public; Owner: traffic_ops -- @@ -1177,42 +1134,6 @@ ALTER TABLE job_id_seq OWNER TO traffic_ops; ALTER SEQUENCE job_id_seq OWNED BY job.id; --- --- Name: job_status; Type: TABLE; Schema: public; Owner: traffic_ops --- - -CREATE TABLE IF NOT EXISTS job_status ( - id bigint NOT NULL, - name text, - description text, - last_updated timestamp with time zone NOT NULL DEFAULT now(), - CONSTRAINT job_status_name_unique UNIQUE (name), - CONSTRAINT idx_89624_primary PRIMARY KEY (id) -); - - -ALTER TABLE job_status OWNER TO traffic_ops; - --- --- Name: job_status_id_seq; Type: SEQUENCE; Schema: public; Owner: traffic_ops --- - -CREATE SEQUENCE IF NOT EXISTS job_status_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE job_status_id_seq OWNER TO traffic_ops; - --- --- Name: job_status_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: traffic_ops --- - -ALTER SEQUENCE job_status_id_seq OWNED BY job_status.id; - CREATE TABLE IF NOT EXISTS last_deleted ( table_name text NOT NULL PRIMARY KEY, last_updated timestamp with time zone NOT NULL DEFAULT now() @@ -2131,20 +2052,6 @@ ALTER TABLE ONLY hwinfo ALTER COLUMN id SET DEFAULT nextval('hwinfo_id_seq'::reg ALTER TABLE ONLY job ALTER COLUMN id SET DEFAULT nextval('job_id_seq'::regclass); --- --- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops --- - -ALTER TABLE ONLY job_agent ALTER COLUMN id SET DEFAULT nextval('job_agent_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops --- - -ALTER TABLE ONLY job_status ALTER COLUMN id SET DEFAULT nextval('job_status_id_seq'::regclass); - - -- -- Name: id; Type: DEFAULT; Schema: public; Owner: traffic_ops -- @@ -2491,14 +2398,6 @@ IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'hwinfo' AN CREATE UNIQUE INDEX IF NOT EXISTS idx_89583_serverid ON hwinfo USING btree (serverid, description); END IF; -IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND column_name = 'agent') THEN - -- - -- Name: idx_89593_fk_job_agent_id1; Type: INDEX; Schema: public; Owner: traffic_ops - -- - - CREATE INDEX IF NOT EXISTS idx_89593_fk_job_agent_id1 ON job USING btree (agent); -END IF; - IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND column_name = 'job_deliveryservice') THEN -- -- Name: idx_89593_fk_job_deliveryservice1; Type: INDEX; Schema: public; Owner: traffic_ops @@ -2507,14 +2406,6 @@ IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND c CREATE INDEX IF NOT EXISTS idx_89593_fk_job_deliveryservice1 ON job USING btree (job_deliveryservice); END IF; -IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND column_name = 'status') THEN - -- - -- Name: idx_89593_fk_job_status_id1; Type: INDEX; Schema: public; Owner: traffic_ops - -- - - CREATE INDEX IF NOT EXISTS idx_89593_fk_job_status_id1 ON job USING btree (status); -END IF; - IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'job' AND column_name = 'job_user') THEN -- -- Name: idx_89593_fk_job_user_id1; Type: INDEX; Schema: public; Owner: traffic_ops @@ -2948,8 +2839,6 @@ DO $$ 'federation_tmuser', 'hwinfo', 'job', - 'job_agent', - 'job_status', 'log', 'origin', 'parameter', @@ -3065,8 +2954,6 @@ DECLARE 'federation_tmuser', 'hwinfo', 'job', - 'job_agent', - 'job_status', 'log', 'origin', 'parameter', @@ -3540,15 +3427,6 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint ADD CONSTRAINT interface_server_fkey FOREIGN KEY (server) REFERENCES server(id) ON DELETE CASCADE ON UPDATE CASCADE; END IF; -IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_job_agent_id1' AND table_name = 'job') THEN - -- - -- Name: fk_job_agent_id1; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops - -- - - ALTER TABLE ONLY job - ADD CONSTRAINT fk_job_agent_id1 FOREIGN KEY (agent) REFERENCES job_agent(id) ON DELETE CASCADE; -END IF; - IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_job_deliveryservice1' AND table_name = 'job') THEN -- -- Name: fk_job_deliveryservice1; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops @@ -3558,15 +3436,6 @@ IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint ADD CONSTRAINT fk_job_deliveryservice1 FOREIGN KEY (job_deliveryservice) REFERENCES deliveryservice(id) ON DELETE CASCADE ON UPDATE CASCADE; END IF; -IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_job_status_id1' AND table_name = 'job') THEN - -- - -- Name: fk_job_status_id1; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops - -- - - ALTER TABLE ONLY job - ADD CONSTRAINT fk_job_status_id1 FOREIGN KEY (status) REFERENCES job_status(id); -END IF; - IF NOT EXISTS (SELECT FROM information_schema.table_constraints WHERE constraint_name = 'fk_job_user_id1' AND table_name = 'job') THEN -- -- Name: fk_job_user_id1; Type: FK CONSTRAINT; Schema: public; Owner: traffic_ops diff --git a/traffic_ops/app/db/migrations/2021110211525600_refetch.down.sql b/traffic_ops/app/db/migrations/2021110211525600_refetch.down.sql deleted file mode 100644 index 452b1bab62..0000000000 --- a/traffic_ops/app/db/migrations/2021110211525600_refetch.down.sql +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - --- Revert - -/** - * Restore job_agent table with constraints and data. - */ - -CREATE TABLE public.job_agent ( - id bigserial NOT NULL, - "name" text NULL, - description text NULL, - active int4 NOT NULL DEFAULT 0, - last_updated timestamptz NOT NULL DEFAULT now(), - CONSTRAINT idx_job_agent_id_primary PRIMARY KEY (id), - CONSTRAINT job_agent_name_unique UNIQUE (name) -); -CREATE INDEX job_agent_last_updated_idx ON public.job_agent USING btree (last_updated DESC NULLS LAST); - --- Table Triggers - -create trigger on_delete_current_timestamp after -delete - on - public.job_agent for each row execute function on_delete_current_timestamp_last_updated('job_agent'); -create trigger on_update_current_timestamp before -update - on - public.job_agent for each row execute function on_update_current_timestamp_last_updated(); - --- Permissions - -ALTER TABLE public.job_agent OWNER TO traffic_ops; -GRANT ALL ON TABLE public.job_agent TO traffic_ops; - --- Data - -INSERT INTO public.job_agent (name, description, active) -VALUES ('Example', 'Description of Purge Agent', 1) -ON CONFLICT (name) DO NOTHING; - -/** - * Restore job_status table with constraints and data - */ - -CREATE TABLE public.job_status ( - id bigserial NOT NULL, - "name" text NULL, - description text NULL, - last_updated timestamptz NOT NULL DEFAULT now(), - CONSTRAINT idx_job_status_id_primary PRIMARY KEY (id), - CONSTRAINT job_status_name_unique UNIQUE (name) -); -CREATE INDEX job_status_last_updated_idx ON public.job_status USING btree (last_updated DESC NULLS LAST); - --- Table Triggers - -create trigger on_delete_current_timestamp after -delete - on - public.job_status for each row execute function on_delete_current_timestamp_last_updated('job_status'); -create trigger on_update_current_timestamp before -update - on - public.job_status for each row execute function on_update_current_timestamp_last_updated(); - --- Permissions - -ALTER TABLE public.job_status OWNER TO traffic_ops; -GRANT ALL ON TABLE public.job_status TO traffic_ops; - --- Data - -INSERT INTO job_status (name, description) -VALUES ('PENDING', 'Job is queued, but has not been picked up by any agents yet'), -('IN_PROGRESS', 'Job is being processed by agents'), -('COMPLETED', 'Job has finished'), -('CANCELLED', 'Job was cancelled') -ON CONFLICT (name) DO NOTHING; - -/** - * Restore job table with constraints and data - */ - --- Restore table -ALTER TABLE public.job -ADD COLUMN IF NOT EXISTS agent int8 NULL, -ADD COLUMN IF NOT EXISTS object_type text NULL, -ADD COLUMN IF NOT EXISTS object_name text NULL, -ADD COLUMN IF NOT EXISTS keyword text NULL, -ADD COLUMN IF NOT EXISTS asset_type text NULL, -ADD COLUMN IF NOT EXISTS status int8 NULL; - -ALTER TABLE public.job -DROP COLUMN IF EXISTS invalidation_type CASCADE; - --- Restore indices and foreign key constraints -CREATE INDEX idx_job_fk_job_agent_id ON public.job USING btree (agent); -ALTER TABLE public.job ADD CONSTRAINT job_fk_job_agent_id FOREIGN KEY (agent) REFERENCES public.job_agent(id) ON DELETE CASCADE; - -CREATE INDEX idx_job_fk_job_status_id ON public.job USING btree (status); -ALTER TABLE public.job ADD CONSTRAINT job_fk_job_status_id FOREIGN KEY (status) REFERENCES public.job_status(id); - --- Restore data -UPDATE public.job -SET agent = 1; - -UPDATE public.job -SET status = ( - SELECT id FROM public.job_status WHERE name = 'PENDING' -); -ALTER TABLE public.job -ALTER COLUMN status SET NOT NULL; - -UPDATE public.job -SET keyword = 'PURGE'; -ALTER TABLE public.job -ALTER COLUMN keyword SET NOT NULL; - -UPDATE public.job -SET asset_type = 'file'; -ALTER TABLE public.job -ALTER COLUMN asset_type SET NOT NULL; - -ALTER TABLE public.job -RENAME COLUMN ttl_hr TO parameters; - -ALTER TABLE public.job -ALTER COLUMN parameters TYPE TEXT -USING CONCAT('TTL:', parameters, 'h'); diff --git a/traffic_ops/app/db/migrations/2021110211525600_refetch.up.sql b/traffic_ops/app/db/migrations/2021110211525600_refetch.up.sql deleted file mode 100644 index bab872e31b..0000000000 --- a/traffic_ops/app/db/migrations/2021110211525600_refetch.up.sql +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - --- Migrate - -/** - * Alter job_agent table and data - */ - -DROP TABLE IF EXISTS public.job_agent CASCADE; - -/** - * Alter job_status table and data - */ - -DROP TABLE IF EXISTS public.job_status CASCADE; - -/** - * Alter job table and data - */ - -ALTER TABLE public.job -DROP COLUMN IF EXISTS agent CASCADE, -DROP COLUMN IF EXISTS object_type CASCADE, -DROP COLUMN IF EXISTS object_name CASCADE, -DROP COLUMN IF EXISTS keyword CASCADE, -DROP COLUMN IF EXISTS asset_type CASCADE, -DROP COLUMN IF EXISTS status CASCADE; - -ALTER TABLE public.job -ADD COLUMN IF NOT EXISTS invalidation_type text NOT NULL DEFAULT 'REFRESH'; - -/* - * If the asset_url contains the temporary fix for refetch - * (adding ##REFETCH## to the end of the url) then assign the - * correct invalidation_type. - */ -UPDATE public.job -SET invalidation_type = 'REFETCH' -WHERE asset_url LIKE '%##REFETCH##%'; - -ALTER TABLE public.job -RENAME COLUMN parameters TO ttl_hr; - -ALTER TABLE public.job -ALTER COLUMN ttl_hr TYPE integer -USING CAST(substring(ttl_hr,'TTL:([0-9]+)h') AS integer); From dcb8046a942449b672c3c5eabd2862ae47f0e55c Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:53:33 -0600 Subject: [PATCH 22/48] Squash admin_all_permission --- ...111212042120_admin_all_permission.down.sql | 45 ------------------- ...21111212042120_admin_all_permission.up.sql | 34 -------------- 2 files changed, 79 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.up.sql diff --git a/traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.down.sql b/traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.down.sql deleted file mode 100644 index 139c165066..0000000000 --- a/traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.down.sql +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -DELETE FROM public.role_capability -WHERE role_id = ( - SELECT id - FROM public.role - WHERE "name" = 'admin' -); - -INSERT INTO public.role_capability (role_id, cap_name) -SELECT r.id, perms.perm -FROM public.role r -CROSS JOIN ( - SELECT DISTINCT cap_name AS perm - FROM public.role_capability -) AS perms -WHERE "name" = 'admin'; - -INSERT INTO public.role_capability (role_id, cap_name) -SELECT r.id, perms.perm -FROM public.role r -CROSS JOIN ( - VALUES ('all-read'), ('all-write') -) AS perms(perm) -WHERE "name" = 'admin' -ON CONFLICT DO NOTHING; - -UPDATE public.role -SET "description" = 'Has access to everything.' -WHERE "name" = 'admin'; diff --git a/traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.up.sql b/traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.up.sql deleted file mode 100644 index 0ecc97447c..0000000000 --- a/traffic_ops/app/db/migrations/2021111212042120_admin_all_permission.up.sql +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -DELETE FROM public.role_capability -WHERE role_id = ( - SELECT id - FROM public.role - WHERE "name" = 'admin' -); - -INSERT INTO public.role_capability (role_id, cap_name) -SELECT id, 'ALL' -FROM public.role -WHERE "name" = 'admin'; - -UPDATE public.role -SET - "description" = 'Has access to everything - cannot be modified or deleted', - priv_level = 30 -WHERE "name" = 'admin'; From efa1b22d58cd372ee0dd348f7e24f68af95b6e68 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:55:40 -0600 Subject: [PATCH 23/48] Squash add_secure_param_read_permission --- ..._add_secure_param_read_permission.down.sql | 20 ------------------ ...00_add_secure_param_read_permission.up.sql | 21 ------------------- 2 files changed, 41 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.down.sql delete mode 100644 traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.up.sql diff --git a/traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.down.sql b/traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.down.sql deleted file mode 100644 index 467f812aa1..0000000000 --- a/traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.down.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - --- delete secure parameter read permission - -DELETE FROM public.role_capability WHERE cap_name='PARAMETER-SECURE:READ'; diff --git a/traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.up.sql b/traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.up.sql deleted file mode 100644 index a3f50f50ca..0000000000 --- a/traffic_ops/app/db/migrations/2021121013164700_add_secure_param_read_permission.up.sql +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - --- add secure parameter read permission to roles with priv level >= 30 -INSERT INTO public.role_capability SELECT id, perm FROM public.role CROSS JOIN (VALUES -('PARAMETER-SECURE:READ')) AS perms(perm) -WHERE priv_level >= 30 ON CONFLICT DO NOTHING; From 3ac16cd76a0343c01e380b59acccc941b3d866dc Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 16:56:28 -0600 Subject: [PATCH 24/48] Squash remove_null_last_authenticated --- ...00_remove_null_last_authenticated.down.sql | 16 --------------- ...1600_remove_null_last_authenticated.up.sql | 20 ------------------- 2 files changed, 36 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.down.sql delete mode 100644 traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.up.sql diff --git a/traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.down.sql b/traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.down.sql deleted file mode 100644 index 084106c81e..0000000000 --- a/traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.down.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ diff --git a/traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.up.sql b/traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.up.sql deleted file mode 100644 index 651c9f5044..0000000000 --- a/traffic_ops/app/db/migrations/2022010715281600_remove_null_last_authenticated.up.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -UPDATE public.tm_user -SET last_authenticated = now() -WHERE last_authenticated IS NULL; From 42e1db2c0b602823e492a65be3488a2e2629fe29 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 17:02:37 -0600 Subject: [PATCH 25/48] Squash add_expiration_and_provider_to_sslkeys --- .../app/db/trafficvault/create_tables.sql | 3 ++- ...xpiration_and_provider_to_sslkeys.down.sql | 19 ------------------- ..._expiration_and_provider_to_sslkeys.up.sql | 19 ------------------- 3 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.down.sql delete mode 100644 traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.up.sql diff --git a/traffic_ops/app/db/trafficvault/create_tables.sql b/traffic_ops/app/db/trafficvault/create_tables.sql index 20c2a559b0..77d647166e 100644 --- a/traffic_ops/app/db/trafficvault/create_tables.sql +++ b/traffic_ops/app/db/trafficvault/create_tables.sql @@ -76,6 +76,8 @@ CREATE TABLE IF NOT EXISTS sslkey ( deliveryservice text NOT NULL, cdn text NOT NULL, version text NOT NULL, + provider text, + expiration timestamp with time zone NOT NULL DEFAULT now(), last_updated timestamp with time zone DEFAULT now() NOT NULL ); @@ -210,4 +212,3 @@ CREATE TRIGGER url_sig_key_last_updated -- -- PostgreSQL database dump complete -- - diff --git a/traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.down.sql b/traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.down.sql deleted file mode 100644 index f8d9bd40a5..0000000000 --- a/traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.down.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE sslkey DROP COLUMN provider; -ALTER TABLE sslkey DROP COLUMN expiration; diff --git a/traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.up.sql b/traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.up.sql deleted file mode 100644 index 5650d0cf9b..0000000000 --- a/traffic_ops/app/db/trafficvault/migrations/2021101310511200_add_expiration_and_provider_to_sslkeys.up.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE sslkey ADD COLUMN IF NOT EXISTS provider text; -ALTER TABLE sslkey ADD COLUMN IF NOT EXISTS expiration timestamp with time zone NOT NULL DEFAULT now(); From 29bf16887c4d5550b9a4d2f2fc653e9e1452b5a6 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 28 Apr 2022 17:04:27 -0600 Subject: [PATCH 26/48] Squash set_provider_not_null --- .../app/db/trafficvault/create_tables.sql | 2 +- ...21011532000_set_provider_not_null.down.sql | 20 ---------------- ...1121011532000_set_provider_not_null.up.sql | 23 ------------------- 3 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.down.sql delete mode 100644 traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.up.sql diff --git a/traffic_ops/app/db/trafficvault/create_tables.sql b/traffic_ops/app/db/trafficvault/create_tables.sql index 77d647166e..4e4786b607 100644 --- a/traffic_ops/app/db/trafficvault/create_tables.sql +++ b/traffic_ops/app/db/trafficvault/create_tables.sql @@ -76,7 +76,7 @@ CREATE TABLE IF NOT EXISTS sslkey ( deliveryservice text NOT NULL, cdn text NOT NULL, version text NOT NULL, - provider text, + provider text NOT NULL, expiration timestamp with time zone NOT NULL DEFAULT now(), last_updated timestamp with time zone DEFAULT now() NOT NULL ); diff --git a/traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.down.sql b/traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.down.sql deleted file mode 100644 index 82fa54b353..0000000000 --- a/traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.down.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -ALTER TABLE ONLY sslkey -ALTER COLUMN provider -DROP NOT NULL; diff --git a/traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.up.sql b/traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.up.sql deleted file mode 100644 index ac75a24150..0000000000 --- a/traffic_ops/app/db/trafficvault/migrations/2021121011532000_set_provider_not_null.up.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -UPDATE sslkey -SET provider = COALESCE(provider, ''); - -ALTER TABLE ONLY sslkey -ALTER COLUMN provider -SET NOT NULL; From c1f609b65561fa6d8637f86d4a850fc8a00d654e Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 17 May 2022 15:20:56 -0600 Subject: [PATCH 27/48] Fix cdn_notification primary key constraint name --- traffic_ops/app/db/create_tables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index eeaa587dc0..ffe77f68e3 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -559,7 +559,7 @@ CREATE TABLE cdn_notification ( "user" text NOT NULL, notification text, last_updated timestamp with time zone DEFAULT now() NOT NULL, - CONSTRAINT pk_cdn_notification PRIMARY KEY (id) + CONSTRAINT cdn_notification_pkey PRIMARY KEY (id) ); -- From 32b5d91214fa50b31610f46095dcbc17a13bd670 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 17 May 2022 15:23:14 -0600 Subject: [PATCH 28/48] Fix sslkey table column order --- traffic_ops/app/db/trafficvault/create_tables.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traffic_ops/app/db/trafficvault/create_tables.sql b/traffic_ops/app/db/trafficvault/create_tables.sql index 4e4786b607..3743e73dba 100644 --- a/traffic_ops/app/db/trafficvault/create_tables.sql +++ b/traffic_ops/app/db/trafficvault/create_tables.sql @@ -76,9 +76,9 @@ CREATE TABLE IF NOT EXISTS sslkey ( deliveryservice text NOT NULL, cdn text NOT NULL, version text NOT NULL, + last_updated timestamp with time zone DEFAULT now() NOT NULL, provider text NOT NULL, - expiration timestamp with time zone NOT NULL DEFAULT now(), - last_updated timestamp with time zone DEFAULT now() NOT NULL + expiration timestamp with time zone NOT NULL DEFAULT now() ); From 7e221612ccc74cb1f050c68555f87513a2f47e26 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 17 May 2022 15:24:54 -0600 Subject: [PATCH 29/48] Fix incorrect column owner for cdn_notification_id_seq --- traffic_ops/app/db/create_tables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index ffe77f68e3..cec6c75536 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -580,7 +580,7 @@ ALTER TABLE cdn_notification_id_seq OWNER TO traffic_ops; -- Name: cdn_notification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: traffic_ops -- -ALTER SEQUENCE cdn_notification_id_seq OWNED BY cdn.id; +ALTER SEQUENCE cdn_notification_id_seq OWNED BY cdn_notification.id; -- -- Name: coordinate; Type: TABLE; Schema: public: Owner: traffic_ops From f632881481ad3b77068f0b8bc6c33e5197a42076 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 18 May 2022 15:08:46 -0600 Subject: [PATCH 30/48] Fix incorrect cdn_notification table owner --- traffic_ops/app/db/create_tables.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index cec6c75536..bd7b37b31c 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -562,6 +562,8 @@ CREATE TABLE cdn_notification ( CONSTRAINT cdn_notification_pkey PRIMARY KEY (id) ); +ALTER TABLE cdn_notification OWNER TO traffic_ops; + -- -- Name: cdn_notification_id_seq; Type: SEQUENCE; Schema: public; Owner: traffic_ops -- From 068c2bfece9d8ccc80e7a91217ee21556d11ca0b Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Fri, 20 May 2022 15:07:51 -0600 Subject: [PATCH 31/48] re-add now-unseeded Roles --- traffic_ops/app/db/seeds.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql index 63d909cf63..f8732545b6 100644 --- a/traffic_ops/app/db/seeds.sql +++ b/traffic_ops/app/db/seeds.sql @@ -79,6 +79,9 @@ INSERT INTO public.role ("name", "description", priv_level) VALUES ('admin', 'Ha INSERT INTO public.role ("name", "description", priv_level) VALUES ('operations', 'Has all reads and most write capabilities', 20) ON CONFLICT ("name") DO NOTHING; INSERT INTO public.role ("name", "description", priv_level) VALUES ('read-only', 'Has access to all read capabilities', 10) ON CONFLICT ("name") DO NOTHING; INSERT INTO public.role ("name", "description", priv_level) VALUES ('disallowed', 'Block all access', 0) ON CONFLICT ("name") DO NOTHING; +INSERT INTO public.role ("name", "description", priv_level) VALUES ('portal','Portal User', 2) ON CONFLICT DO NOTHING; +INSERT INTO public.role ("name", "description", priv_level) VALUES ('steering','Steering User', 15) ON CONFLICT DO NOTHING; +INSERT INTO public.role ("name", "description", priv_level) VALUES ('federation','Role for Secondary CZF', 15) ON CONFLICT DO NOTHING; -- roles_capabilities -- out of the box, the admin role has ALL capabilities From 93c98cbadc7260f6afe3529a6dd8822126a8bf0b Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Fri, 20 May 2022 15:09:58 -0600 Subject: [PATCH 32/48] Fix erroneously dropping 'NOT NULL' constraint --- traffic_ops/app/db/create_tables.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index bd7b37b31c..9e132d1c29 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -557,7 +557,7 @@ CREATE TABLE cdn_notification ( id bigint NOT NULL, cdn text NOT NULL, "user" text NOT NULL, - notification text, + notification text NOT NULL, last_updated timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT cdn_notification_pkey PRIMARY KEY (id) ); From 6766c24e0abf0bf5eedeaeee9f1c0b675ff85385 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Fri, 20 May 2022 15:13:26 -0600 Subject: [PATCH 33/48] Squash init and trafficvault init --- .github/actions/todb-tests/entrypoint.sh | 4 ++ traffic_ops/app/db/create_tables.sql | 1 + .../migrations/00000000000000_init.down.sql | 23 ----------- .../db/migrations/00000000000000_init.up.sql | 38 ------------------- .../migrations/2021042200000000_init.down.sql | 16 -------- .../migrations/2021042200000000_init.up.sql | 16 -------- 6 files changed, 5 insertions(+), 93 deletions(-) delete mode 100644 traffic_ops/app/db/migrations/00000000000000_init.down.sql delete mode 100644 traffic_ops/app/db/migrations/00000000000000_init.up.sql delete mode 100644 traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.down.sql delete mode 100644 traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.up.sql diff --git a/.github/actions/todb-tests/entrypoint.sh b/.github/actions/todb-tests/entrypoint.sh index c0cff50ee7..08e66c2922 100755 --- a/.github/actions/todb-tests/entrypoint.sh +++ b/.github/actions/todb-tests/entrypoint.sh @@ -32,6 +32,10 @@ CODE=0; migration_dirs=(traffic_ops/app/db/migrations traffic_ops/app/db/trafficvault/migrations); for migration_dir in ${migration_dirs[@]}; do + if ! [[ -d "$migration_dir" ]]; then + echo "No migrations exist at $migration_dir - skipping!" >&2; + continue; + fi pushd $migration_dir; # Ensure proper order diff --git a/traffic_ops/app/db/create_tables.sql b/traffic_ops/app/db/create_tables.sql index 9e132d1c29..c3aa89a655 100644 --- a/traffic_ops/app/db/create_tables.sql +++ b/traffic_ops/app/db/create_tables.sql @@ -37,6 +37,7 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; SET search_path = public, pg_catalog; + -- -- Name: on_update_current_timestamp_last_updated(); Type: FUNCTION; Schema: public; Owner: traffic_ops -- diff --git a/traffic_ops/app/db/migrations/00000000000000_init.down.sql b/traffic_ops/app/db/migrations/00000000000000_init.down.sql deleted file mode 100644 index 2f7de2483a..0000000000 --- a/traffic_ops/app/db/migrations/00000000000000_init.down.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -/* Rolling back the init migration already truncates the schema_migrations table - * without needing to do so explicitly. - */ - -ALTER TABLE IF EXISTS goose_db_version_unused - RENAME TO goose_db_version; diff --git a/traffic_ops/app/db/migrations/00000000000000_init.up.sql b/traffic_ops/app/db/migrations/00000000000000_init.up.sql deleted file mode 100644 index 7e8a022ac4..0000000000 --- a/traffic_ops/app/db/migrations/00000000000000_init.up.sql +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -CREATE OR REPLACE FUNCTION fast_forward_schema_migrations_version() - RETURNS TRIGGER - LANGUAGE PLPGSQL -AS $$ -BEGIN - IF EXISTS (SELECT FROM information_schema.columns WHERE table_name = 'goose_db_version') THEN - UPDATE schema_migrations SET "version" = (SELECT version_id FROM goose_db_version - ORDER BY TSTAMP DESC - LIMIT 1); - ALTER TABLE goose_db_version - RENAME TO goose_db_version_unused; - END IF; - DROP TRIGGER fast_forward_schema_migrations_trigger ON schema_migrations; - DROP FUNCTION fast_forward_schema_migrations_version(); - RETURN NULL; -END$$; - -CREATE TRIGGER fast_forward_schema_migrations_trigger - AFTER UPDATE - ON schema_migrations - EXECUTE PROCEDURE fast_forward_schema_migrations_version(); diff --git a/traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.down.sql b/traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.down.sql deleted file mode 100644 index e5b092ffa4..0000000000 --- a/traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.down.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -SELECT; diff --git a/traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.up.sql b/traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.up.sql deleted file mode 100644 index e5b092ffa4..0000000000 --- a/traffic_ops/app/db/trafficvault/migrations/2021042200000000_init.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -SELECT; From 52c19f71485299234979dccf1707776d3353281a Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 13:53:19 -0600 Subject: [PATCH 34/48] Fix attempting to run migrations when there are no migrations --- traffic_ops/app/db/admin.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index 2be3f2046a..3fafe0fbe3 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -394,7 +394,10 @@ func runFirstMigration() error { } func runMigrations() { - migratedFromGoose := initMigrate() + migratedFromGoose, migrationsShouldRun := initMigrate() + if !migrationsShouldRun { + return + } if !TrafficVault && DBVersion == LastSquashedMigrationTimestamp && !DBVersionDirty { if migrateErr := runFirstMigration(); migrateErr != nil { die(fmt.Sprintf("Error migrating from DB version %d to %d: %s", LastSquashedMigrationTimestamp, FirstMigrationTimestamp, migrateErr.Error())) @@ -679,7 +682,13 @@ func main() { } } -func initMigrate() bool { +// initMigrate initializes Migrate and returns whether a migration from Goose to +// Migrate was performed during said initialization and whether or not there are +// any actual migrations to run. +// +// If the second return value is false, then the global "Migrate" variable IS +// NOT SET so the caller must skip all migrations. +func initMigrate() (bool, bool) { var err error ConnectionString = fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=%s", DBDriver, DBUser, DBPassword, HostIP, HostPort, DBName, SSLMode) if TrafficVault { @@ -687,11 +696,11 @@ func initMigrate() bool { } else { Migrate, err = migrate.New("file:"+dbMigrationsDir, ConnectionString) } - if err != nil { + if err != nil && !errors.Is(err, os.ErrNotExist) { die("Starting Migrate: " + err.Error()) } Migrate.Log = &Log{} - return maybeMigrateFromGoose() + return maybeMigrateFromGoose(), err == nil } // Log represents the logger From a46d032a09a2ec7914931ae77c0aa061a7021b50 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:06:04 -0600 Subject: [PATCH 35/48] unexport things that don't need to be exported --- traffic_ops/app/db/admin.go | 296 ++++++++++++++++++------------------ 1 file changed, 152 insertions(+), 144 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index 3fafe0fbe3..571b6b778c 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -41,68 +41,72 @@ import ( "gopkg.in/yaml.v2" ) -type DBConfig struct { - Development EnvConfig `yaml:"development"` - Test EnvConfig `yaml:"test"` - Integration EnvConfig `yaml:"integration"` - Production EnvConfig `yaml:"production"` +type dbConfig struct { + Development envConfig `yaml:"development"` + Test envConfig `yaml:"test"` + Integration envConfig `yaml:"integration"` + Production envConfig `yaml:"production"` } -type EnvConfig struct { +type envConfig struct { Driver string `yaml:"driver"` Open string `yaml:"open"` } -func (conf DBConfig) getEnvironmentConfig(env string) (EnvConfig, error) { +func (conf dbConfig) getEnvironmentConfig(env string) (envConfig, error) { switch env { - case EnvDevelopment: + case envDevelopment: return conf.Development, nil - case EnvTest: + case envTest: return conf.Test, nil - case EnvIntegration: + case envIntegration: return conf.Integration, nil - case EnvProduction: + case envProduction: return conf.Production, nil default: - return EnvConfig{}, errors.New("invalid environment: " + env) + return envConfig{}, errors.New("invalid environment: " + env) } } +// the possible environments to use const ( - // the possible environments to use - EnvDevelopment = "development" - EnvTest = "test" - EnvIntegration = "integration" - EnvProduction = "production" - - // keys in the database config's "open" string value - HostKey = "host" - PortKey = "port" - UserKey = "user" - PasswordKey = "password" - DBNameKey = "dbname" - SSLModeKey = "sslmode" - - // available commands - CmdCreateDB = "createdb" - CmdDropDB = "dropdb" - CmdCreateMigration = "create_migration" - CmdCreateUser = "create_user" - CmdDropUser = "drop_user" - CmdShowUsers = "show_users" - CmdReset = "reset" - CmdUpgrade = "upgrade" - CmdMigrate = "migrate" - CmdUp = "up" - CmdDown = "down" - CmdRedo = "redo" + envDevelopment = "development" + envTest = "test" + envIntegration = "integration" + envProduction = "production" +) + +// keys in the database config's "open" string value +const ( + hostKey = "host" + portKey = "port" + userKey = "user" + passwordKey = "password" + dbNameKey = "dbname" + sslModeKey = "sslmode" +) + +// available commands +const ( + cmdCreateDB = "createdb" + cmdDropDB = "dropdb" + cmdCreateMigration = "create_migration" + cmdCreateUser = "create_user" + cmdDropUser = "drop_user" + cmdShowUsers = "show_users" + cmdReset = "reset" + cmdUpgrade = "upgrade" + cmdMigrate = "migrate" + cmdUp = "up" + cmdDown = "down" + cmdRedo = "redo" // Deprecated: Migrate only tracks migration timestamp and dirty status, not a status for each migration. // Use CmdDBVersion to check the migration timestamp and dirty status. - CmdStatus = "status" - CmdDBVersion = "dbversion" - CmdSeed = "seed" - CmdLoadSchema = "load_schema" - CmdPatch = "patch" + cmdStatus = "status" + cmdDBVersion = "dbversion" + cmdSeed = "seed" + cmdLoadSchema = "load_schema" + cmdPatch = "patch" ) // Default file system paths for TODB files. @@ -125,34 +129,38 @@ const ( // Default connection information const ( - defaultEnvironment = EnvDevelopment + defaultEnvironment = envDevelopment defaultDBSuperUser = "postgres" ) const ( - LastSquashedMigrationTimestamp uint = 2021012200000000 // 2021012200000000_max_request_header_bytes_default_zero.sql - FirstMigrationTimestamp uint = 2021012700000000 // 2021012700000000_update_interfaces_multiple_routers.up.sql + // 2021012200000000_max_request_header_bytes_default_zero.sql + lastSquashedMigrationTimestamp uint = 2021012200000000 + // 2021012700000000_update_interfaces_multiple_routers.up.sql + firstMigrationTimestamp uint = 2021012700000000 +) + +// globals that are passed in via CLI flags and used in commands +var ( + environment string + trafficVault bool + dbVersion uint + dbVersionDirty bool ) +// globals that are parsed out of DBConfigFile and used in commands var ( - // globals that are passed in via CLI flags and used in commands - Environment string - TrafficVault bool - DBVersion uint - DBVersionDirty bool - - // globals that are parsed out of DBConfigFile and used in commands - ConnectionString string - DBDriver string - DBName string - DBSuperUser = defaultDBSuperUser - DBUser string - DBPassword string - HostIP string - HostPort string - SSLMode string - Migrate *migrate.Migrate - MigrationName string + connectionString string + dbDriver string + dbName string + dbSuperUser = defaultDBSuperUser + dbUser string + dbPassword string + hostIP string + hostPort string + sslMode string + migrateInstance *migrate.Migrate + migrationName string ) // Actual TODB file paths. @@ -173,7 +181,7 @@ var ( func parseDBConfig() error { var cfgPath string - if TrafficVault { + if trafficVault { cfgPath = trafficVaultDBConfigPath } else { cfgPath = dbConfigPath @@ -183,18 +191,18 @@ func parseDBConfig() error { return fmt.Errorf("reading DB conf '%s': %w", cfgPath, err) } - dbConfig := DBConfig{} + dbConfig := dbConfig{} err = yaml.Unmarshal(confBytes, &dbConfig) if err != nil { return errors.New("unmarshalling DB conf yaml: " + err.Error()) } - envConfig, err := dbConfig.getEnvironmentConfig(Environment) + envConfig, err := dbConfig.getEnvironmentConfig(environment) if err != nil { return errors.New("getting environment config: " + err.Error()) } - DBDriver = envConfig.Driver + dbDriver = envConfig.Driver // parse the 'open' string into a map open := make(map[string]string) pairs := strings.Split(envConfig.Open, " ") @@ -210,13 +218,13 @@ func parseDBConfig() error { } ok := false - stringPointers := []*string{&HostIP, &HostPort, &DBUser, &DBPassword, &DBName, &SSLMode} - keys := []string{HostKey, PortKey, UserKey, PasswordKey, DBNameKey, SSLModeKey} + stringPointers := []*string{&hostIP, &hostPort, &dbUser, &dbPassword, &dbName, &sslMode} + keys := []string{hostKey, portKey, userKey, passwordKey, dbNameKey, sslModeKey} for index, stringPointer := range stringPointers { key := keys[index] *stringPointer, ok = open[key] if !ok { - return errors.New("unable to get '" + key + "' for environment '" + Environment + "'") + return errors.New("unable to get '" + key + "' for environment '" + environment + "'") } } @@ -224,7 +232,7 @@ func parseDBConfig() error { } func createDB() { - dbExistsCmd := exec.Command("psql", "-h", HostIP, "-U", DBSuperUser, "-p", HostPort, "-tAc", "SELECT 1 FROM pg_database WHERE datname='"+DBName+"'") + dbExistsCmd := exec.Command("psql", "-h", hostIP, "-U", dbSuperUser, "-p", hostPort, "-tAc", "SELECT 1 FROM pg_database WHERE datname='"+dbName+"'") stderr := bytes.Buffer{} dbExistsCmd.Stderr = &stderr out, err := dbExistsCmd.Output() @@ -233,24 +241,24 @@ func createDB() { fmt.Fprintln(os.Stderr, "unable to check if DB already exists: "+err.Error()+", stderr: "+stderr.String()) } if len(out) > 0 { - fmt.Println("Database " + DBName + " already exists") + fmt.Println("Database " + dbName + " already exists") return } - createDBCmd := exec.Command("createdb", "-h", HostIP, "-p", HostPort, "-U", DBSuperUser, "-e", "--owner", DBUser, DBName) + createDBCmd := exec.Command("createdb", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-e", "--owner", dbUser, dbName) out, err = createDBCmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { - die("Can't create db " + DBName + ": " + err.Error()) + die("Can't create db " + dbName + ": " + err.Error()) } } func dropDB() { - fmt.Println("Dropping database: " + DBName) - cmd := exec.Command("dropdb", "-h", HostIP, "-p", HostPort, "-U", DBSuperUser, "-e", "--if-exists", DBName) + fmt.Println("Dropping database: " + dbName) + cmd := exec.Command("dropdb", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-e", "--if-exists", dbName) out, err := cmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { - die("Can't drop db " + DBName + ": " + err.Error()) + die("Can't drop db " + dbName + ": " + err.Error()) } } @@ -281,7 +289,7 @@ func createMigration() { formattedMigrationTime := migrationTime.Format("20060102150405") + fmt.Sprintf("%02d", migrationTime.Nanosecond()%100) for _, direction := range []string{"up", "down"} { var migrationFile *os.File - basename := fmt.Sprintf("%s_%s.%s.sql", formattedMigrationTime, MigrationName, direction) + basename := fmt.Sprintf("%s_%s.%s.sql", formattedMigrationTime, migrationName, direction) filename := filepath.Join(dbMigrationsDir, basename) if migrationFile, err = os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0644); err != nil { die("Creating migration " + filename + ": " + err.Error()) @@ -295,8 +303,8 @@ func createMigration() { } func createUser() { - fmt.Println("Creating user: " + DBUser) - userExistsCmd := exec.Command("psql", "-h", HostIP, "-U", DBSuperUser, "-p", HostPort, "-tAc", "SELECT 1 FROM pg_roles WHERE rolname='"+DBUser+"'") + fmt.Println("Creating user: " + dbUser) + userExistsCmd := exec.Command("psql", "-h", hostIP, "-U", dbSuperUser, "-p", hostPort, "-tAc", "SELECT 1 FROM pg_roles WHERE rolname='"+dbUser+"'") stderr := bytes.Buffer{} userExistsCmd.Stderr = &stderr out, err := userExistsCmd.Output() @@ -305,28 +313,28 @@ func createUser() { fmt.Fprintln(os.Stderr, "unable to check if user already exists: "+err.Error()+", stderr: "+stderr.String()) } if len(out) > 0 { - fmt.Println("User " + DBUser + " already exists") + fmt.Println("User " + dbUser + " already exists") return } - createUserCmd := exec.Command("psql", "-h", HostIP, "-p", HostPort, "-U", DBSuperUser, "-etAc", "CREATE USER "+DBUser+" WITH LOGIN ENCRYPTED PASSWORD '"+DBPassword+"'") + createUserCmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-etAc", "CREATE USER "+dbUser+" WITH LOGIN ENCRYPTED PASSWORD '"+dbPassword+"'") out, err = createUserCmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { - die("Can't create user " + DBUser) + die("Can't create user " + dbUser) } } func dropUser() { - cmd := exec.Command("dropuser", "-h", HostIP, "-p", HostPort, "-U", DBSuperUser, "-i", "-e", DBUser) + cmd := exec.Command("dropuser", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-i", "-e", dbUser) out, err := cmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { - die("Can't drop user " + DBUser) + die("Can't drop user " + dbUser) } } func showUsers() { - cmd := exec.Command("psql", "-h", HostIP, "-p", HostPort, "-U", DBSuperUser, "-ec", `\du`) + cmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-ec", `\du`) out, err := cmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { @@ -344,7 +352,7 @@ func reset() { func upgrade() { runMigrations() - if !TrafficVault { + if !trafficVault { seed() patch() } @@ -352,17 +360,17 @@ func upgrade() { func maybeMigrateFromGoose() bool { var versionErr error - DBVersion, DBVersionDirty, versionErr = Migrate.Version() + dbVersion, dbVersionDirty, versionErr = migrateInstance.Version() if versionErr == nil { return false } if versionErr != migrate.ErrNilVersion { die("Error running migrate version: " + versionErr.Error()) } - if err := Migrate.Steps(1); err != nil { + if err := migrateInstance.Steps(1); err != nil { die("Error migrating to Migrate from Goose: " + err.Error()) } - DBVersion, DBVersionDirty, _ = Migrate.Version() + dbVersion, dbVersionDirty, _ = migrateInstance.Version() return true } @@ -373,21 +381,21 @@ func runFirstMigration() error { if sourceDriverErr != nil { return fmt.Errorf("opening the migration source driver: " + sourceDriverErr.Error()) } - dbDriver, dbDriverErr := database.Open(ConnectionString) + dbDriver, dbDriverErr := database.Open(connectionString) if dbDriverErr != nil { return fmt.Errorf("opening the dbdriver: " + dbDriverErr.Error()) } - firstMigration, firstMigrationName, migrationReadErr := sourceDriver.ReadUp(FirstMigrationTimestamp) + firstMigration, firstMigrationName, migrationReadErr := sourceDriver.ReadUp(firstMigrationTimestamp) if migrationReadErr != nil { return fmt.Errorf("reading migration %s: %s", firstMigrationName, migrationReadErr.Error()) } - if setDirtyVersionErr := dbDriver.SetVersion(int(FirstMigrationTimestamp), true); setDirtyVersionErr != nil { + if setDirtyVersionErr := dbDriver.SetVersion(int(firstMigrationTimestamp), true); setDirtyVersionErr != nil { return fmt.Errorf("setting the dirty version: %s", setDirtyVersionErr.Error()) } if migrateErr := dbDriver.Run(firstMigration); migrateErr != nil { return fmt.Errorf("running the migration: %s", migrateErr.Error()) } - if setVersionErr := dbDriver.SetVersion(int(FirstMigrationTimestamp), false); setVersionErr != nil { + if setVersionErr := dbDriver.SetVersion(int(firstMigrationTimestamp), false); setVersionErr != nil { return fmt.Errorf("setting the version after successfully running the migration: %s", setVersionErr.Error()) } return nil @@ -398,12 +406,12 @@ func runMigrations() { if !migrationsShouldRun { return } - if !TrafficVault && DBVersion == LastSquashedMigrationTimestamp && !DBVersionDirty { + if !trafficVault && dbVersion == lastSquashedMigrationTimestamp && !dbVersionDirty { if migrateErr := runFirstMigration(); migrateErr != nil { - die(fmt.Sprintf("Error migrating from DB version %d to %d: %s", LastSquashedMigrationTimestamp, FirstMigrationTimestamp, migrateErr.Error())) + die(fmt.Sprintf("Error migrating from DB version %d to %d: %s", lastSquashedMigrationTimestamp, firstMigrationTimestamp, migrateErr.Error())) } } - if upErr := Migrate.Up(); upErr == migrate.ErrNoChange { + if upErr := migrateInstance.Up(); errors.Is(upErr, migrate.ErrNoChange) { if !migratedFromGoose { println(upErr.Error()) } @@ -418,37 +426,37 @@ func runUp() { func down() { initMigrate() - if err := Migrate.Steps(-1); err != nil { + if err := migrateInstance.Steps(-1); err != nil { die("Error running migrate down: " + err.Error()) } } func redo() { initMigrate() - if downErr := Migrate.Steps(-1); downErr != nil { + if downErr := migrateInstance.Steps(-1); downErr != nil { die("Error running migrate down 1 in 'redo': " + downErr.Error()) } - if upErr := Migrate.Steps(1); upErr != nil { + if upErr := migrateInstance.Steps(1); upErr != nil { die("Error running migrate up 1 in 'redo': " + upErr.Error()) } } // Deprecated: Migrate does not track migration status of past migrations. Use dbversion() to check the migration timestamp and dirty status. func status() { - dbVersion() + getDBVersion() } -func dbVersion() { +func getDBVersion() { initMigrate() - fmt.Printf("dbversion %d", DBVersion) - if DBVersionDirty { + fmt.Printf("dbversion %d", dbVersion) + if dbVersionDirty { fmt.Printf(" (dirty)") } println() } func seed() { - if TrafficVault { + if trafficVault { die("seed not supported for trafficvault environment") } fmt.Println("Seeding database w/ required data.") @@ -456,9 +464,9 @@ func seed() { if err != nil { die("unable to read '" + dbSeedsPath + "': " + err.Error()) } - cmd := exec.Command("psql", "-h", HostIP, "-p", HostPort, "-d", DBName, "-U", DBUser, "-e", "-v", "ON_ERROR_STOP=1") + cmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-d", dbName, "-U", dbUser, "-e", "-v", "ON_ERROR_STOP=1") cmd.Stdin = bytes.NewBuffer(seedsBytes) - cmd.Env = append(os.Environ(), "PGPASSWORD="+DBPassword) + cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword) out, err := cmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { @@ -469,16 +477,16 @@ func seed() { func loadSchema() { fmt.Println("Creating database tables.") schemaPath := dbSchemaPath - if TrafficVault { + if trafficVault { schemaPath = trafficVaultSchemaPath } schemaBytes, err := ioutil.ReadFile(schemaPath) if err != nil { die("unable to read '" + schemaPath + "': " + err.Error()) } - cmd := exec.Command("psql", "-h", HostIP, "-p", HostPort, "-d", DBName, "-U", DBUser, "-e", "-v", "ON_ERROR_STOP=1") + cmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-d", dbName, "-U", dbUser, "-e", "-v", "ON_ERROR_STOP=1") cmd.Stdin = bytes.NewBuffer(schemaBytes) - cmd.Env = append(os.Environ(), "PGPASSWORD="+DBPassword) + cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword) out, err := cmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { @@ -487,7 +495,7 @@ func loadSchema() { } func patch() { - if TrafficVault { + if trafficVault { die("patch not supported for trafficvault environment") } fmt.Println("Patching database with required data fixes.") @@ -495,9 +503,9 @@ func patch() { if err != nil { die("unable to read '" + dbPatchesPath + "': " + err.Error()) } - cmd := exec.Command("psql", "-h", HostIP, "-p", HostPort, "-d", DBName, "-U", DBUser, "-e", "-v", "ON_ERROR_STOP=1") + cmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-d", dbName, "-U", dbUser, "-e", "-v", "ON_ERROR_STOP=1") cmd.Stdin = bytes.NewBuffer(patchesBytes) - cmd.Env = append(os.Environ(), "PGPASSWORD="+DBPassword) + cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword) out, err := cmd.CombinedOutput() fmt.Printf("%s", out) if err != nil { @@ -623,11 +631,11 @@ func main() { flag.StringVar(&shortSeeds, "S", "", "Provide a path to a seeds statements file, instead of using the default (./db/seeds.sql)") flag.StringVar(&longSeeds, "seeds", "", "Provide a path to a seeds statements file, instead of using the default (./db/seeds.sql)") - flag.BoolVar(&TrafficVault, "v", false, "Perform operations for Traffic Vault instead of the Traffic Ops database") - flag.BoolVar(&TrafficVault, "trafficvault", false, "Perform operations for Traffic Vault instead of the Traffic Ops database") + flag.BoolVar(&trafficVault, "v", false, "Perform operations for Traffic Vault instead of the Traffic Ops database") + flag.BoolVar(&trafficVault, "trafficvault", false, "Perform operations for Traffic Vault instead of the Traffic Ops database") flag.Parse() - if TrafficVault { + if trafficVault { collapse(shortCfg, longCfg, "config", defaultTrafficVaultDBConfigPath, &trafficVaultDBConfigPath) collapse(shortMigrations, longMigrations, "migrations-dir", defaultTrafficVaultMigrationsPath, &trafficVaultMigrationsPath) collapse(shortSchema, longSchema, "schema", defaultTrafficVaultSchemaPath, &trafficVaultSchemaPath) @@ -636,19 +644,19 @@ func main() { collapse(shortMigrations, longMigrations, "migrations-dir", defaultDBMigrationsPath, &dbMigrationsDir) collapse(shortSchema, longSchema, "schema", defaultDBSchemaPath, &dbSchemaPath) } - collapse(shortEnv, longEnv, "environment", defaultEnvironment, &Environment) + collapse(shortEnv, longEnv, "environment", defaultEnvironment, &environment) collapse(shortPatches, longPatches, "patches", defaultDBPatchesPath, &dbPatchesPath) collapse(shortSeeds, longSeeds, "seeds", defaultDBSeedsPath, &dbSeedsPath) - if flag.Arg(0) == CmdCreateMigration { + if flag.Arg(0) == cmdCreateMigration { if len(flag.Args()) != 2 { die(usage()) } - MigrationName = flag.Arg(1) + migrationName = flag.Arg(1) } else if len(flag.Args()) != 1 || flag.Arg(0) == "" { die(usage()) } - if Environment == "" { + if environment == "" { die(usage()) } if err := parseDBConfig(); err != nil { @@ -656,23 +664,23 @@ func main() { } commands := make(map[string]func()) - commands[CmdCreateDB] = createDB - commands[CmdDropDB] = dropDB - commands[CmdCreateMigration] = createMigration - commands[CmdCreateUser] = createUser - commands[CmdDropUser] = dropUser - commands[CmdShowUsers] = showUsers - commands[CmdReset] = reset - commands[CmdUpgrade] = upgrade - commands[CmdMigrate] = runMigrations - commands[CmdUp] = runUp - commands[CmdDown] = down - commands[CmdRedo] = redo - commands[CmdStatus] = status - commands[CmdDBVersion] = dbVersion - commands[CmdSeed] = seed - commands[CmdLoadSchema] = loadSchema - commands[CmdPatch] = patch + commands[cmdCreateDB] = createDB + commands[cmdDropDB] = dropDB + commands[cmdCreateMigration] = createMigration + commands[cmdCreateUser] = createUser + commands[cmdDropUser] = dropUser + commands[cmdShowUsers] = showUsers + commands[cmdReset] = reset + commands[cmdUpgrade] = upgrade + commands[cmdMigrate] = runMigrations + commands[cmdUp] = runUp + commands[cmdDown] = down + commands[cmdRedo] = redo + commands[cmdStatus] = status + commands[cmdDBVersion] = getDBVersion + commands[cmdSeed] = seed + commands[cmdLoadSchema] = loadSchema + commands[cmdPatch] = patch userCmd := flag.Arg(0) if cmd, ok := commands[userCmd]; ok { @@ -690,16 +698,16 @@ func main() { // NOT SET so the caller must skip all migrations. func initMigrate() (bool, bool) { var err error - ConnectionString = fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=%s", DBDriver, DBUser, DBPassword, HostIP, HostPort, DBName, SSLMode) - if TrafficVault { - Migrate, err = migrate.New("file:"+trafficVaultMigrationsPath, ConnectionString) + connectionString = fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=%s", dbDriver, dbUser, dbPassword, hostIP, hostPort, dbName, sslMode) + if trafficVault { + migrateInstance, err = migrate.New("file:"+trafficVaultMigrationsPath, connectionString) } else { - Migrate, err = migrate.New("file:"+dbMigrationsDir, ConnectionString) + migrateInstance, err = migrate.New("file:"+dbMigrationsDir, connectionString) } if err != nil && !errors.Is(err, os.ErrNotExist) { die("Starting Migrate: " + err.Error()) } - Migrate.Log = &Log{} + migrateInstance.Log = &Log{} return maybeMigrateFromGoose(), err == nil } From 29c6c218666754b9d8c18f6ca92dafd95f84c317 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:09:41 -0600 Subject: [PATCH 36/48] Wrap errors, compare with errors.Is instead of ==, actually check errors --- traffic_ops/app/db/admin.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index 571b6b778c..6227bf1076 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -294,8 +294,8 @@ func createMigration() { if migrationFile, err = os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0644); err != nil { die("Creating migration " + filename + ": " + err.Error()) } - defer log.Close(migrationFile, "Closing migration "+filename) - if migrationFile.Write([]byte(apacheLicense2)); err != nil { + defer log.Close(migrationFile, "closing migration "+filename) + if _, err = migrationFile.Write([]byte(apacheLicense2)); err != nil { die("Writing content to migration " + filename + ": " + err.Error()) } fmt.Printf("Created migration %s\n", filename) @@ -364,7 +364,7 @@ func maybeMigrateFromGoose() bool { if versionErr == nil { return false } - if versionErr != migrate.ErrNilVersion { + if !errors.Is(versionErr, migrate.ErrNilVersion) { die("Error running migrate version: " + versionErr.Error()) } if err := migrateInstance.Steps(1); err != nil { @@ -387,16 +387,16 @@ func runFirstMigration() error { } firstMigration, firstMigrationName, migrationReadErr := sourceDriver.ReadUp(firstMigrationTimestamp) if migrationReadErr != nil { - return fmt.Errorf("reading migration %s: %s", firstMigrationName, migrationReadErr.Error()) + return fmt.Errorf("reading migration %s: %w", firstMigrationName, migrationReadErr) } if setDirtyVersionErr := dbDriver.SetVersion(int(firstMigrationTimestamp), true); setDirtyVersionErr != nil { - return fmt.Errorf("setting the dirty version: %s", setDirtyVersionErr.Error()) + return fmt.Errorf("setting the dirty version: %w", setDirtyVersionErr) } if migrateErr := dbDriver.Run(firstMigration); migrateErr != nil { - return fmt.Errorf("running the migration: %s", migrateErr.Error()) + return fmt.Errorf("running the migration: %w", migrateErr) } if setVersionErr := dbDriver.SetVersion(int(firstMigrationTimestamp), false); setVersionErr != nil { - return fmt.Errorf("setting the version after successfully running the migration: %s", setVersionErr.Error()) + return fmt.Errorf("setting the version after successfully running the migration: %w", setVersionErr) } return nil } From faea0e45b37944ed7af01d02a8f6af91b5a81016 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:15:44 -0600 Subject: [PATCH 37/48] Ensure terminating newlines from subprocess output --- traffic_ops/app/db/admin.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index 6227bf1076..ec4b222759 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -246,7 +246,7 @@ func createDB() { } createDBCmd := exec.Command("createdb", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-e", "--owner", dbUser, dbName) out, err = createDBCmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't create db " + dbName + ": " + err.Error()) } @@ -256,7 +256,7 @@ func dropDB() { fmt.Println("Dropping database: " + dbName) cmd := exec.Command("dropdb", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-e", "--if-exists", dbName) out, err := cmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't drop db " + dbName + ": " + err.Error()) } @@ -318,7 +318,7 @@ func createUser() { } createUserCmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-etAc", "CREATE USER "+dbUser+" WITH LOGIN ENCRYPTED PASSWORD '"+dbPassword+"'") out, err = createUserCmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't create user " + dbUser) } @@ -327,7 +327,7 @@ func createUser() { func dropUser() { cmd := exec.Command("dropuser", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-i", "-e", dbUser) out, err := cmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't drop user " + dbUser) } @@ -336,7 +336,7 @@ func dropUser() { func showUsers() { cmd := exec.Command("psql", "-h", hostIP, "-p", hostPort, "-U", dbSuperUser, "-ec", `\du`) out, err := cmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't show users") } @@ -468,7 +468,7 @@ func seed() { cmd.Stdin = bytes.NewBuffer(seedsBytes) cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword) out, err := cmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't patch database w/ required data") } @@ -488,7 +488,7 @@ func loadSchema() { cmd.Stdin = bytes.NewBuffer(schemaBytes) cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword) out, err := cmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Println(string(out)) if err != nil { die("Can't create database tables") } @@ -507,7 +507,7 @@ func patch() { cmd.Stdin = bytes.NewBuffer(patchesBytes) cmd.Env = append(os.Environ(), "PGPASSWORD="+dbPassword) out, err := cmd.CombinedOutput() - fmt.Printf("%s", out) + fmt.Printf(string(out)) if err != nil { die("Can't patch database w/ required data") } From 9b30072969b22ee0b59da37b28f055d9c7e54f7b Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:16:27 -0600 Subject: [PATCH 38/48] print errors to stderr --- traffic_ops/app/db/admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index ec4b222759..be6d47a1e7 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -413,7 +413,7 @@ func runMigrations() { } if upErr := migrateInstance.Up(); errors.Is(upErr, migrate.ErrNoChange) { if !migratedFromGoose { - println(upErr.Error()) + fmt.Fprintln(os.Stderr, upErr.Error()) } } else if upErr != nil { die("Error running migrate up: " + upErr.Error()) From e0d69dadb0d2488e4556073e1813d510b8fee1a0 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:18:12 -0600 Subject: [PATCH 39/48] Don't use a print function that shouldn't be used refer to https://go.dev/ref/spec#Bootstrapping --- traffic_ops/app/db/admin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index be6d47a1e7..148dbec3a6 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -452,7 +452,7 @@ func getDBVersion() { if dbVersionDirty { fmt.Printf(" (dirty)") } - println() + fmt.Println() } func seed() { From 8c157786edd6f9ef406ae0559f8145504b795b85 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:18:21 -0600 Subject: [PATCH 40/48] Simplify --- traffic_ops/app/db/admin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index 148dbec3a6..03c6d0acfb 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -298,7 +298,7 @@ func createMigration() { if _, err = migrationFile.Write([]byte(apacheLicense2)); err != nil { die("Writing content to migration " + filename + ": " + err.Error()) } - fmt.Printf("Created migration %s\n", filename) + fmt.Println("Created migration ", filename) } } @@ -595,7 +595,6 @@ func collapse(o1, o2, name, def string, dest *string) { die("conflicting definitions of '" + name + "' - must be specified only once\n" + usage()) } *dest = o1 - return } func main() { From e73991cfa2b67441df3be451963bbad9d8f3037b Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 24 May 2022 14:21:27 -0600 Subject: [PATCH 41/48] Fix comments not ending with a period --- traffic_ops/app/db/admin.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index 03c6d0acfb..dba422488a 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -68,7 +68,7 @@ func (conf dbConfig) getEnvironmentConfig(env string) (envConfig, error) { } } -// the possible environments to use +// the possible environments to use. const ( envDevelopment = "development" envTest = "test" @@ -76,7 +76,7 @@ const ( envProduction = "production" ) -// keys in the database config's "open" string value +// keys in the database config's "open" string value. const ( hostKey = "host" portKey = "port" @@ -86,7 +86,7 @@ const ( sslModeKey = "sslmode" ) -// available commands +// available commands. const ( cmdCreateDB = "createdb" cmdDropDB = "dropdb" @@ -127,20 +127,20 @@ const ( defaultTrafficVaultSchemaPath = defaultTrafficVaultDir + "create_tables.sql" ) -// Default connection information +// Default connection information. const ( defaultEnvironment = envDevelopment defaultDBSuperUser = "postgres" ) const ( - // 2021012200000000_max_request_header_bytes_default_zero.sql + // 2021012200000000_max_request_header_bytes_default_zero.sql. lastSquashedMigrationTimestamp uint = 2021012200000000 - // 2021012700000000_update_interfaces_multiple_routers.up.sql + // 2021012700000000_update_interfaces_multiple_routers.up.sql. firstMigrationTimestamp uint = 2021012700000000 ) -// globals that are passed in via CLI flags and used in commands +// globals that are passed in via CLI flags and used in commands. var ( environment string trafficVault bool @@ -148,7 +148,7 @@ var ( dbVersionDirty bool ) -// globals that are parsed out of DBConfigFile and used in commands +// globals that are parsed out of DBConfigFile and used in commands. var ( connectionString string dbDriver string From 29ab8d511b1142cfe6acdc546052c1e8dd5a7d32 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 1 Jun 2022 10:15:16 -0600 Subject: [PATCH 42/48] Fix segmentation fault in admin --- traffic_ops/app/db/admin.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/traffic_ops/app/db/admin.go b/traffic_ops/app/db/admin.go index dba422488a..01529c8eae 100644 --- a/traffic_ops/app/db/admin.go +++ b/traffic_ops/app/db/admin.go @@ -703,11 +703,14 @@ func initMigrate() (bool, bool) { } else { migrateInstance, err = migrate.New("file:"+dbMigrationsDir, connectionString) } - if err != nil && !errors.Is(err, os.ErrNotExist) { + if errors.Is(err, os.ErrNotExist) { + return false, false + } + if err != nil { die("Starting Migrate: " + err.Error()) } migrateInstance.Log = &Log{} - return maybeMigrateFromGoose(), err == nil + return maybeMigrateFromGoose(), true } // Log represents the logger From ef6a1a9a6a159517a785eab6947b21047ca7d8f8 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 1 Jun 2022 10:19:06 -0600 Subject: [PATCH 43/48] Fix incorrect initial db version in db tests --- traffic_ops_db/test/docker/run-db-test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/traffic_ops_db/test/docker/run-db-test.sh b/traffic_ops_db/test/docker/run-db-test.sh index 30e81844ef..3e435ecbd7 100755 --- a/traffic_ops_db/test/docker/run-db-test.sh +++ b/traffic_ops_db/test/docker/run-db-test.sh @@ -84,7 +84,10 @@ for d in $(get_db_dumps); do done cd "$TO_DIR" -old_db_version=0 +# This NEEDS to be updated if migrations are squashed. It should be the +# timestamp of the oldest extant migration. +# TODO: this can be determined automatically from an inspection of the migrations dir +old_db_version=2022011112591400 if [[ "$db_is_empty" = false ]]; then old_db_version=$(get_current_db_version) From 95a5198974613e0cd8faaaa0db76c8b566775b52 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Wed, 1 Jun 2022 11:37:44 -0600 Subject: [PATCH 44/48] Fix checking for wrong timestamp to find out if db is empty --- traffic_ops_db/test/docker/run-db-test.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/traffic_ops_db/test/docker/run-db-test.sh b/traffic_ops_db/test/docker/run-db-test.sh index 3e435ecbd7..a31d53cbaa 100755 --- a/traffic_ops_db/test/docker/run-db-test.sh +++ b/traffic_ops_db/test/docker/run-db-test.sh @@ -87,7 +87,9 @@ cd "$TO_DIR" # This NEEDS to be updated if migrations are squashed. It should be the # timestamp of the oldest extant migration. # TODO: this can be determined automatically from an inspection of the migrations dir -old_db_version=2022011112591400 +FIRST_MIGRATION=2022011112591400 + +old_db_version=$FIRST_MIGRATION if [[ "$db_is_empty" = false ]]; then old_db_version=$(get_current_db_version) @@ -95,7 +97,7 @@ if [[ "$db_is_empty" = false ]]; then fi # reset the DB if it is empty (i.e. no db.dump was provided) -if [[ "$old_db_version" -eq 0 ]]; then +if [[ "$old_db_version" -eq $FIRST_MIGRATION ]]; then db_is_empty=true ./db/admin --env=production reset || { echo "DB reset failed!"; exit 1; } fi From 0cde9c38a57d52298b6a54cbbd89e4363c5f953d Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 2 Jun 2022 09:30:59 -0600 Subject: [PATCH 45/48] Remove duplicated script content --- traffic_ops/app/db/patches.sql | 92 ---------------------------------- 1 file changed, 92 deletions(-) diff --git a/traffic_ops/app/db/patches.sql b/traffic_ops/app/db/patches.sql index 9f62862aff..1cb657fd95 100644 --- a/traffic_ops/app/db/patches.sql +++ b/traffic_ops/app/db/patches.sql @@ -11,95 +11,3 @@ See the License for the specific language governing permissions and limitations under the License. */ - - --- THIS FILE INCLUDES POST-MIGRATION DATA FIXES REQUIRED OF TRAFFIC OPS - --- Mapping roles and capabilities: (used to be in a migration) - --- For role 'federation' -INSERT INTO role_capability (role_id, cap_name) -SELECT id, perm -FROM public.role -CROSS JOIN ( VALUES - ('DELIVERY-SERVICE:READ'), - ('DELIVERY-SERVICE:UPDATE'), - ('FEDERATION:CREATE'), - ('FEDERATION:UPDATE'), - ('FEDERATION:DELETE'), - ('FEDERATION-RESOLVER:CREATE'), - ('FEDERATION-RESOLVER:DELETE') -) AS perms(perm) -WHERE "name" = 'federation' -ON CONFLICT DO NOTHING; - --- For role 'portal' -INSERT INTO role_capability (role_id, cap_name) -SELECT id, perm -FROM public.role -CROSS JOIN ( VALUES - ('ASN:READ'), - ('ASYNC-STATUS:READ'), - ('CACHE-GROUP:READ'), - ('CAPABILITY:READ'), - ('CDN-SNAPSHOT:READ'), - ('CDN:READ'), - ('COORDINATE:READ'), - ('DELIVERY-SERVICE:READ'), - ('DELIVERY-SERVICE:UPDATE'), - ('DIVISION:READ'), - ('DS-REQUEST:CREATE'), - ('DS-REQUEST:DELETE'), - ('DS-REQUEST:READ'), - ('DS-REQUEST:UPDATE'), - ('DS-SECURITY-KEY:READ'), - ('FEDERATION-RESOLVER:READ'), - ('FEDERATION:READ'), - ('ISO:READ'), - ('JOB:CREATE'), - ('JOB:DELETE'), - ('JOB:READ'), - ('JOB:UPDATE'), - ('LOG:READ'), - ('MONITOR-CONFIG:READ'), - ('ORIGIN:READ'), - ('PARAMETER:READ'), - ('PHYSICAL-LOCATION:READ'), - ('PLUGIN-READ'), - ('PROFILE:READ'), - ('REGION:READ'), - ('ROLE:READ'), - ('SERVER-CAPABILITY:READ'), - ('SERVER-CHECK:READ'), - ('SERVER:READ'), - ('SERVICE-CATEGORY:READ'), - ('STAT:CREATE'), - ('STAT:READ'), - ('STATIC-DN:READ'), - ('STATUS:READ'), - ('STEERING:CREATE'), - ('STEERING:DELETE'), - ('STEERING:READ'), - ('STEERING:UPDATE'), - ('TENANT:READ'), - ('TOPOLOGY:READ'), - ('TRAFFIC-VAULT:READ'), - ('TYPE:READ'), - ('USER:READ') -) AS perms(perm) -WHERE "name" = 'portal' -ON CONFLICT DO NOTHING; - --- For role 'steering' -INSERT INTO role_capability (role_id, cap_name) -SELECT id, perm -FROM public.role -CROSS JOIN ( VALUES - ('DELIVERY-SERVICE:READ'), - ('DELIVERY-SERVICE:UPDATE'), - ('STEERING:CREATE'), - ('STEERING:DELETE'), - ('STEERING:UPDATE') -) AS perms(perm) -WHERE "name" = 'steering' -ON CONFLICT DO NOTHING; From d5d43f9e57e9273044602064b5d53f254b894c69 Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 2 Jun 2022 09:35:37 -0600 Subject: [PATCH 46/48] Add back missing Permissions --- traffic_ops/app/db/seeds.sql | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql index f8732545b6..c1b3f5618e 100644 --- a/traffic_ops/app/db/seeds.sql +++ b/traffic_ops/app/db/seeds.sql @@ -91,6 +91,11 @@ FROM public.role WHERE "name" = 'admin' ON CONFLICT DO NOTHING; +INSERT INTO public.role_capability +SELECT id, 'DELIVERY-SERVICE-SAFE:UPDATE' +FROM public.role +WHERE "name" in ('operations', 'read-only', 'portal', 'federation', 'steering'); + -- Using role 'read-only' INSERT INTO public.role_capability SELECT id, perm @@ -135,7 +140,7 @@ CROSS JOIN ( VALUES ('USER:READ'), ('STAT:CREATE') ) AS perms(perm) -WHERE "name" IN ('operations', 'read-only') +WHERE "name" IN ('operations', 'read-only', 'federation', 'steering') ON CONFLICT DO NOTHING; -- Traditionally the 'portal'/'federations'/'steering' Role(s) @@ -159,7 +164,7 @@ CROSS JOIN ( VALUES ('STEERING:UPDATE'), ('STEERING:DELETE') ) AS perms(perm) -WHERE "name" = 'operations' +WHERE "name" IN ('operations', 'federation', 'steering') ON CONFLICT DO NOTHING; -- Using role 'operations' From b56b11fc75f92642d92b90f14efb06b86b3b9a4a Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Thu, 2 Jun 2022 16:33:47 -0600 Subject: [PATCH 47/48] add back missing "portal" user Permissions --- traffic_ops/app/db/seeds.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql index c1b3f5618e..3c4a1e3b31 100644 --- a/traffic_ops/app/db/seeds.sql +++ b/traffic_ops/app/db/seeds.sql @@ -140,7 +140,7 @@ CROSS JOIN ( VALUES ('USER:READ'), ('STAT:CREATE') ) AS perms(perm) -WHERE "name" IN ('operations', 'read-only', 'federation', 'steering') +WHERE "name" IN ('operations', 'portal', 'read-only', 'federation', 'steering') ON CONFLICT DO NOTHING; -- Traditionally the 'portal'/'federations'/'steering' Role(s) @@ -164,7 +164,7 @@ CROSS JOIN ( VALUES ('STEERING:UPDATE'), ('STEERING:DELETE') ) AS perms(perm) -WHERE "name" IN ('operations', 'federation', 'steering') +WHERE "name" IN ('operations', 'portal', 'federation', 'steering') ON CONFLICT DO NOTHING; -- Using role 'operations' From 6aafee02b6e215e9a345c2cb825d5f99f3c2568d Mon Sep 17 00:00:00 2001 From: ocket8888 Date: Tue, 14 Jun 2022 14:41:20 -0600 Subject: [PATCH 48/48] Fix extra Permissions given to 'portal' users --- traffic_ops/app/db/seeds.sql | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql index 3c4a1e3b31..9f35ed7340 100644 --- a/traffic_ops/app/db/seeds.sql +++ b/traffic_ops/app/db/seeds.sql @@ -148,11 +148,6 @@ INSERT INTO public.role_capability SELECT id, perm FROM public.role CROSS JOIN ( VALUES - ('FEDERATION:CREATE'), - ('FEDERATION:UPDATE'), - ('FEDERATION:DELETE'), - ('FEDERATION-RESOLVER:CREATE'), - ('FEDERATION-RESOLVER:DELETE'), ('DELIVERY-SERVICE:UPDATE'), ('JOB:CREATE'), ('JOB:UPDATE'), @@ -167,6 +162,20 @@ CROSS JOIN ( VALUES WHERE "name" IN ('operations', 'portal', 'federation', 'steering') ON CONFLICT DO NOTHING; +-- Federation and Steering Role Permissions (also given to operators). +INSERT INTO public.role_capability +SELECT id, perm +FROM public.role +CROSS JOIN ( VALUES + ('FEDERATION:CREATE'), + ('FEDERATION:UPDATE'), + ('FEDERATION:DELETE'), + ('FEDERATION-RESOLVER:CREATE'), + ('FEDERATION-RESOLVER:DELETE') +) AS perms(perm) +WHERE "name" IN ('operations', 'federation', 'steering') +ON CONFLICT DO NOTHING; + -- Using role 'operations' INSERT INTO public.role_capability SELECT id, perm