From 0cdc75925a3efbe652e5b5bf7f1051ca6aab03a2 Mon Sep 17 00:00:00 2001 From: dtookey Date: Tue, 12 Apr 2022 16:08:46 -0400 Subject: [PATCH] first stab at durations.sql --- src/sql/0-run-first/1-sanitize.sql | 7 ++- src/sql/0-run-first/durations.sql | 70 ++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/sql/0-run-first/durations.sql diff --git a/src/sql/0-run-first/1-sanitize.sql b/src/sql/0-run-first/1-sanitize.sql index 5e3cef6..841584a 100644 --- a/src/sql/0-run-first/1-sanitize.sql +++ b/src/sql/0-run-first/1-sanitize.sql @@ -6,7 +6,10 @@ CREATE INDEX billing_refnum ON billing (refNumber); -- noinspection SqlWithoutWhere UPDATE users SET hash = ''; -DELETE FROM project_lifecycle WHERE project_number = 'EVENT'; +ALTER TABLE project_lifecycle ADD COLUMN id INT AUTO_INCREMENT KEY FIRST; +CREATE OR REPLACE INDEX lifecycle_timestamp on project_lifecycle (timestamp); +CREATE OR REPLACE INDEX lifecycle_newval on project_lifecycle (new_value); UPDATE project_lifecycle SET new_value = '+CREATED' WHERE changed_column = 'created'; -UPDATE project_lifecycle SET changed_column = 'status' WHERE changed_column = 'created'; \ No newline at end of file +UPDATE project_lifecycle SET changed_column = 'status' WHERE changed_column = 'created'; +DELETE FROM project_lifecycle WHERE project_number = 'EVENT'; \ No newline at end of file diff --git a/src/sql/0-run-first/durations.sql b/src/sql/0-run-first/durations.sql new file mode 100644 index 0000000..824abea --- /dev/null +++ b/src/sql/0-run-first/durations.sql @@ -0,0 +1,70 @@ +CREATE OR REPLACE TABLE lifecycle_times +( + id int primary key auto_increment, + project_number varchar(25), + ready_for_review datetime, + ready_for_review_two datetime, + ready_for_deliver datetime, + sealed datetime, + delivered datetime, + has_been_invoiced datetime, + ready_to_invoice datetime +); +CREATE OR REPLACE INDEX lifetimes_refnum on project_lifecycle (project_number); + + +INSERT INTO lifecycle_times (project_number) +SELECT DISTINCT project_number +FROM project_lifecycle; + + +UPDATE lifecycle_times +set ready_for_review = (SELECT timestamp + from project_lifecycle + where new_value = '+READY_FOR_REVIEW' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + ready_for_review_two = (SELECT timestamp + from project_lifecycle + where new_value = '+READY_FOR_REVIEW2' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + ready_for_deliver = (SELECT timestamp + from project_lifecycle + where new_value = '+READY_FOR_DELIVER' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + ready_for_deliver = (SELECT timestamp + from project_lifecycle + where new_value = '+READY_FOR_DELIVER' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + sealed = (SELECT timestamp + from project_lifecycle + where new_value = '+SEALED' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + delivered = (SELECT timestamp + from project_lifecycle + where new_value = '+DELIVERED' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + has_been_invoiced = (SELECT timestamp + from project_lifecycle + where new_value = '+HAS_BEEN_INVOICED' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1), + ready_to_invoice = (SELECT timestamp + from project_lifecycle + where new_value = '+READY_TO_INVOICE' + and project_lifecycle.project_number = lifecycle_times.project_number + order by timestamp desc + limit 1) +; \ No newline at end of file