You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ma...@apache.org on 2022/03/22 20:26:31 UTC

[trafficcontrol] branch master updated: Remove unused `deliveryservice_tmuser` table (#6430)

This is an automated email from the ASF dual-hosted git repository.

mattjackson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 43b6ca5  Remove unused `deliveryservice_tmuser` table (#6430)
43b6ca5 is described below

commit 43b6ca52a3f4efd3b3f3cbda84b3d7a03ea08f1e
Author: ocket8888 <oc...@apache.org>
AuthorDate: Tue Mar 22 14:26:22 2022 -0600

    Remove unused `deliveryservice_tmuser` table (#6430)
    
    * Remove unused deliveryservice_tmuser table from database
    
    * Remove references to removed table from various testing frameworks
    
    * update CHANGELOG
---
 CHANGELOG.md                                       |  1 +
 cache-config/testing/ort-tests/tcdata/todb.go      | 14 -------
 ...12431414_remove_unused_ds_tmuser_table.down.sql | 49 ++++++++++++++++++++++
 ...1612431414_remove_unused_ds_tmuser_table.up.sql | 18 ++++++++
 traffic_ops/app/db/seeds.sql                       |  1 -
 traffic_ops/testing/api/v2/todb_test.go            | 14 -------
 traffic_ops/testing/api/v3/todb_test.go            | 14 -------
 traffic_ops/testing/api/v4/todb_test.go            | 14 -------
 8 files changed, 68 insertions(+), 57 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 26a8225..a217fa3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Updated the CDNs Traffic Portal page to use a more performant AG-Grid-based table.
 - Updated the Profiles Traffic Portal page to use a more performant AG-Grid-based table.
 - Updated Go version to 1.18
+- Removed the unused `deliveryservice_tmuser` table from Traffic Ops database
 
 ## [6.1.0] - 2022-01-18
 ### Added
diff --git a/cache-config/testing/ort-tests/tcdata/todb.go b/cache-config/testing/ort-tests/tcdata/todb.go
index 6915798..d1df501 100644
--- a/cache-config/testing/ort-tests/tcdata/todb.go
+++ b/cache-config/testing/ort-tests/tcdata/todb.go
@@ -198,19 +198,6 @@ INSERT INTO tenant (name, active, parent_id, last_updated) VALUES ('badtenant',
 	return nil
 }
 
-// SetupDeliveryServiceTmUsers ...
-func SetupDeliveryServiceTmUsers(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice_tmuser (deliveryservice, tm_user_id, last_updated) VALUES (100, (SELECT id FROM tm_user where username = 'admin') , '2018-01-19 21:19:32.372969');
-`
-	err := execSQL(db, sqlStmt)
-	if err != nil {
-		return execError(sqlStmt, err)
-	}
-	return nil
-}
-
 // SetupJobs ...
 func SetupJobs(db *sql.DB) error {
 
@@ -268,7 +255,6 @@ func (r *TCData) Teardown(db *sql.DB) error {
 	DELETE FROM job;
 	DELETE FROM log;
 	DELETE FROM asn;
-	DELETE FROM deliveryservice_tmuser;
 	DELETE FROM tm_user;
 	DELETE FROM role;
 	DELETE FROM capability;
diff --git a/traffic_ops/app/db/migrations/2022031612431414_remove_unused_ds_tmuser_table.down.sql b/traffic_ops/app/db/migrations/2022031612431414_remove_unused_ds_tmuser_table.down.sql
new file mode 100644
index 0000000..53dba14
--- /dev/null
+++ b/traffic_ops/app/db/migrations/2022031612431414_remove_unused_ds_tmuser_table.down.sql
@@ -0,0 +1,49 @@
+/*
+ * 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 public.deliveryservice_tmuser (
+	deliveryservice bigint NOT NULL,
+	tm_user_id bigint NOT NULL,
+	last_updated timestamp with time zone NOT NULL DEFAULT now(),
+	CONSTRAINT idx_89525_primary PRIMARY KEY (deliveryservice, tm_user_id)
+);
+
+CREATE INDEX idx_89525_fk_tm_userid
+ON public.deliveryservice_tmuser
+USING btree (tm_user_id);
+
+CREATE TRIGGER on_delete_current_timestamp
+AFTER DELETE ON public.deliveryservice_tmuser
+FOR EACH ROW EXECUTE PROCEDURE on_delete_current_timestamp_last_updated('public.deliveryservice_tmuser');
+
+CREATE TRIGGER on_update_current_timestamp
+BEFORE UPDATE ON public.deliveryservice_tmuser
+FOR EACH ROW EXECUTE PROCEDURE on_update_current_timestamp_last_updated('public.deliveryservice_tmuser');
+
+ALTER TABLE ONLY public.deliveryservice_tmuser
+ADD CONSTRAINT fk_tm_user_ds
+FOREIGN KEY (deliveryservice)
+REFERENCES deliveryservice(id)
+ON UPDATE CASCADE
+ON DELETE CASCADE;
+
+ALTER TABLE ONLY public.deliveryservice_tmuser
+ADD CONSTRAINT fk_tm_user_id
+FOREIGN KEY (tm_user_id)
+REFERENCES tm_user(id)
+ON UPDATE CASCADE
+ON DELETE CASCADE;
diff --git a/traffic_ops/app/db/migrations/2022031612431414_remove_unused_ds_tmuser_table.up.sql b/traffic_ops/app/db/migrations/2022031612431414_remove_unused_ds_tmuser_table.up.sql
new file mode 100644
index 0000000..dcfbbf0
--- /dev/null
+++ b/traffic_ops/app/db/migrations/2022031612431414_remove_unused_ds_tmuser_table.up.sql
@@ -0,0 +1,18 @@
+/*
+ * 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 public.deliveryservice_tmuser CASCADE;
diff --git a/traffic_ops/app/db/seeds.sql b/traffic_ops/app/db/seeds.sql
index 29d5c34..63d909c 100644
--- a/traffic_ops/app/db/seeds.sql
+++ b/traffic_ops/app/db/seeds.sql
@@ -399,7 +399,6 @@ INSERT INTO public.last_deleted (table_name) VALUES ('deliveryservice_regex') ON
 INSERT INTO public.last_deleted (table_name) VALUES ('deliveryservice_request') ON CONFLICT (table_name) DO NOTHING;
 INSERT INTO public.last_deleted (table_name) VALUES ('deliveryservice_request_comment') ON CONFLICT (table_name) DO NOTHING;
 INSERT INTO public.last_deleted (table_name) VALUES ('deliveryservice_server') ON CONFLICT (table_name) DO NOTHING;
-INSERT INTO public.last_deleted (table_name) VALUES ('deliveryservice_tmuser') ON CONFLICT (table_name) DO NOTHING;
 INSERT INTO public.last_deleted (table_name) VALUES ('division') ON CONFLICT (table_name) DO NOTHING;
 INSERT INTO public.last_deleted (table_name) VALUES ('federation') ON CONFLICT (table_name) DO NOTHING;
 INSERT INTO public.last_deleted (table_name) VALUES ('federation_deliveryservice') ON CONFLICT (table_name) DO NOTHING;
diff --git a/traffic_ops/testing/api/v2/todb_test.go b/traffic_ops/testing/api/v2/todb_test.go
index 297fbd9..d8ea487 100644
--- a/traffic_ops/testing/api/v2/todb_test.go
+++ b/traffic_ops/testing/api/v2/todb_test.go
@@ -204,19 +204,6 @@ INSERT INTO tenant (name, active, parent_id, last_updated) VALUES ('badtenant',
 	return nil
 }
 
-// SetupDeliveryServiceTmUsers ...
-func SetupDeliveryServiceTmUsers(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice_tmuser (deliveryservice, tm_user_id, last_updated) VALUES (100, (SELECT id FROM tm_user where username = 'admin') , '2018-01-19 21:19:32.372969');
-`
-	err := execSQL(db, sqlStmt)
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
 // SetupJobs ...
 func SetupJobs(db *sql.DB) error {
 
@@ -274,7 +261,6 @@ func Teardown(db *sql.DB) error {
 	DELETE FROM job;
 	DELETE FROM log;
 	DELETE FROM asn;
-	DELETE FROM deliveryservice_tmuser;
 	DELETE FROM tm_user;
 	DELETE FROM role;
 	DELETE FROM capability;
diff --git a/traffic_ops/testing/api/v3/todb_test.go b/traffic_ops/testing/api/v3/todb_test.go
index 601dceb..26a7539 100644
--- a/traffic_ops/testing/api/v3/todb_test.go
+++ b/traffic_ops/testing/api/v3/todb_test.go
@@ -204,19 +204,6 @@ INSERT INTO tenant (name, active, parent_id, last_updated) VALUES ('badtenant',
 	return nil
 }
 
-// SetupDeliveryServiceTmUsers ...
-func SetupDeliveryServiceTmUsers(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice_tmuser (deliveryservice, tm_user_id, last_updated) VALUES (100, (SELECT id FROM tm_user where username = 'admin') , '2018-01-19 21:19:32.372969');
-`
-	err := execSQL(db, sqlStmt)
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
 // SetupJobs ...
 func SetupJobs(db *sql.DB) error {
 
@@ -274,7 +261,6 @@ func Teardown(db *sql.DB) error {
 	DELETE FROM job;
 	DELETE FROM log;
 	DELETE FROM asn;
-	DELETE FROM deliveryservice_tmuser;
 	DELETE FROM tm_user;
 	DELETE FROM role;
 	DELETE FROM capability;
diff --git a/traffic_ops/testing/api/v4/todb_test.go b/traffic_ops/testing/api/v4/todb_test.go
index 60e833f..697f35d 100644
--- a/traffic_ops/testing/api/v4/todb_test.go
+++ b/traffic_ops/testing/api/v4/todb_test.go
@@ -336,19 +336,6 @@ INSERT INTO tenant (name, active, parent_id, last_updated) VALUES ('badtenant',
 	return nil
 }
 
-// SetupDeliveryServiceTmUsers ...
-func SetupDeliveryServiceTmUsers(db *sql.DB) error {
-
-	sqlStmt := `
-INSERT INTO deliveryservice_tmuser (deliveryservice, tm_user_id, last_updated) VALUES (100, (SELECT id FROM tm_user where username = 'admin') , '2018-01-19 21:19:32.372969');
-`
-	err := execSQL(db, sqlStmt)
-	if err != nil {
-		return fmt.Errorf("exec failed %v", err)
-	}
-	return nil
-}
-
 // SetupJobs ...
 func SetupJobs(db *sql.DB) error {
 
@@ -406,7 +393,6 @@ func Teardown(db *sql.DB) error {
 	DELETE FROM job;
 	DELETE FROM log;
 	DELETE FROM asn;
-	DELETE FROM deliveryservice_tmuser;
 	DELETE FROM tm_user;
 	DELETE FROM role;
 	DELETE FROM capability;