From 08e3aaafe3738007f868ec9c34df6b05649223eb Mon Sep 17 00:00:00 2001 From: dtookey Date: Mon, 7 Aug 2023 12:29:08 -0400 Subject: [PATCH] Added a review_contributions table for the different reviewed statuses --- src/sql/0-run-first/contributions.sql | 42 ++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/sql/0-run-first/contributions.sql b/src/sql/0-run-first/contributions.sql index 8edd566..e56baf2 100644 --- a/src/sql/0-run-first/contributions.sql +++ b/src/sql/0-run-first/contributions.sql @@ -91,7 +91,7 @@ SELECT CONCAT(users.email) AS `Technician`, project_lifecycle.project_number AS `ProjectNumber`, project_lifecycle.timestamp, new_value AS `ActionType`, - 'RDU' AS `Region`, + 'RDU' AS `Region`, clients.name AS `Client`, ap.description AS `Description` FROM users @@ -120,3 +120,43 @@ WHERE id IN (SELECT bad_rows.id ALTER TABLE fa_contributions DROP COLUMN IF EXISTS id; + + +#########################REVIEW Contributions############################################################################# +DROP TABLE IF EXISTS review_contributions; + + +CREATE TABLE review_contributions AS +SELECT CONCAT(users.email) AS `Technician`, + project_lifecycle.project_number AS `ProjectNumber`, + Date(project_lifecycle.timestamp) as `DateStamp`, + new_value AS `ActionType`, + SUBSTR(project_lifecycle.project_number, 0, 3) AS `Region`, + clients.name AS `Client`, + ap.description AS `Description` +FROM users + INNER JOIN project_lifecycle ON pkey = modifier + INNER JOIN projects ap on project_lifecycle.project_number = ap.refnum + INNER JOIN contacts on ap.contact_fkey = contacts.pkey + INNER JOIN clients on contacts.cl_fkey = clients.pkey +WHERE project_lifecycle.new_value IN ('+READY_FOR_REVIEW', '+READY_FOR_REVIEW2'); + + +ALTER TABLE review_contributions + ADD COLUMN IF NOT EXISTS id INT AUTO_INCREMENT KEY FIRST; + + +DELETE +FROM review_contributions +WHERE id IN (SELECT bad_rows.id + FROM review_contributions AS bad_rows + INNER JOIN (SELECT review_contributions.`ProjectNumber`, MAX(id) as min_id + FROM review_contributions + GROUP BY review_contributions.`ProjectNumber` + HAVING count(*) > 1) AS good_rows + ON good_rows.`ProjectNumber` = + bad_rows.`ProjectNumber` + AND good_rows.min_id <> bad_rows.id); + +ALTER TABLE review_contributions + DROP COLUMN IF EXISTS id;