-- Drop requests_live table
DROP TABLE requests_live;
-- Drop requests_confirm table
DROP TABLE requests_confirm;
-- fill in created_on column with created_at values if created_on is null
UPDATE requests
SET created_on = created_at
WHERE created_on IS NULL;
-- add table_label column
ALTER TABLE requests ADD COLUMN table_label VARCHAR(255);
-- fill in table_label column with table_number values
UPDATE requests
SET table_label = table_number
WHERE table_label IS NULL;
-- drop is_escalated column
ALTER TABLE requests DROP COLUMN is_escalated;
-- add time_to_confirm column
ALTER TABLE requests ADD COLUMN time_to_confirm INT;
-- fill in time_to_confirm column with difference between created_on and confirmed_at
UPDATE requests 
SET time_to_confirm = TIMESTAMPDIFF(SECOND, created_on, confirmed_at)
WHERE confirmed_at IS NOT NULL;
-- rename restaurant_id to venue_id
ALTER TABLE requests CHANGE restaurant_id venue_id VARCHAR(255);
-- rename doc_id to request_id
ALTER TABLE requests CHANGE doc_id request_id VARCHAR(255) NOT NULL; 
-- add time_to_done column
ALTER TABLE requests ADD COLUMN time_to_done INT;
-- fill in time_to_done column with difference between confirmed_at and done_at
UPDATE requests
SET time_to_done = TIMESTAMPDIFF(SECOND, confirmed_at, done_at)
WHERE done_at IS NOT NULL;
-- add time_after_escalation column
ALTER TABLE requests ADD COLUMN time_after_escalation INT;
-- fill in time_after_escalation column with difference between escalated_at and confirmed_at
UPDATE requests
SET time_after_escalation = TIMESTAMPDIFF(SECOND, escalated_at, confirmed_at)
WHERE escalated_at IS NOT NULL;
