-- ------------------------------------------
-- UPDATE FOR sod_workflow_approval 
-- because of legacy risks needs to be re-run
-- ------------------------------------------
ALTER TABLE `sod_preventive_check_wf_approval` 
CHANGE COLUMN `timestamp` `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `action`,
ADD COLUMN `run` INT NOT NULL DEFAULT 1 AFTER `handle`, 
RENAME TO `sod_workflow_approval` ;

-- ------------------------------------------
-- UPDATE FOR sod_workflow
-- because of legacy risks needs to be re-run
-- and first approval needs to be shown
-- ------------------------------------------
ALTER TABLE `sod_workflow` 
CHANGE COLUMN `timestamp` `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN `run` INT NOT NULL DEFAULT 1 AFTER `violation_id`,
ADD COLUMN `first_approval` TIMESTAMP NULL DEFAULT NULL AFTER `run`,
ADD COLUMN `latest_approval` TIMESTAMP NULL DEFAULT NULL AFTER `first_approval`;

-- ------------------------------------------
-- UPDATE sod_workflow_approval.run column
-- default needs to be set at 0 now that all 
-- existing already has been set to 1
-- ------------------------------------------
ALTER TABLE `sod_workflow` 
CHANGE COLUMN `run` `run` INT NOT NULL DEFAULT 0;
ALTER TABLE `sod_workflow_approval` 
CHANGE COLUMN `run` `run` INT NOT NULL DEFAULT 0;
