SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

ALTER TABLE `sog`.`glam_tag_object_key` DROP FOREIGN KEY `fk_glam_tag_object_key_glam_tag1` , DROP FOREIGN KEY `fk_glam_tag_object_key_glam_access_object1` ;

ALTER TABLE `sog`.`glam_tag_transaction_schedule` DROP FOREIGN KEY `fk_glam_tag_transaction_schedule_glam_transaction_schedule1` ;

ALTER TABLE `sog`.`glam_access_point` ADD COLUMN `ap_last_access_by` CHAR(36) NULL DEFAULT NULL  AFTER `ap_key_replaced_latch` ;

ALTER TABLE `sog`.`glam_srm_stakeholder` CHANGE COLUMN `last_changed_by` `last_changed_by` CHAR(36) NULL DEFAULT NULL  ;

ALTER TABLE `sog`.`glam_transaction_schedule` ADD COLUMN `sched_job_card` VARCHAR(64) NULL DEFAULT NULL  AFTER `is_suspended` ;

ALTER TABLE `sog`.`glam_tag_object_key` 
  ADD CONSTRAINT `fk_glam_tag_object_key_glam_tag1`
  FOREIGN KEY (`tag_id` )
  REFERENCES `sog`.`glam_tag` (`tag_id` )
  ON DELETE CASCADE
  ON UPDATE CASCADE, 
  ADD CONSTRAINT `fk_glam_tag_object_key_glam_access_object1`
  FOREIGN KEY (`access_object_id` )
  REFERENCES `sog`.`glam_access_object` (`access_object_id` )
  ON DELETE CASCADE
  ON UPDATE CASCADE;

ALTER TABLE `sog`.`glam_tag_transaction_schedule` 
  ADD CONSTRAINT `fk_glam_tag_transaction_schedule_glam_transaction_schedule1`
  FOREIGN KEY (`access_point_id` , `transaction_id` , `user_id` )
  REFERENCES `sog`.`glam_transaction_schedule` (`access_point_id` , `transaction_id` , `user_id` )
  ON DELETE CASCADE
  ON UPDATE CASCADE;

ALTER TABLE `sog`.`glam_actionable` ADD COLUMN `last_changed_by` CHAR(36) NULL DEFAULT NULL  AFTER `time_action_logged` , CHANGE COLUMN `action_type` `action_type` ENUM('DISCOVERED_KEY','DISCOVERED_LOCK','LOCK_UNSAFE','LATCH_REPLACEMENT','LOCK_REPLACEMENT','PENDING_SCHEDULE','PENDING_SRM','UNSAFE_LOCK') NULL DEFAULT NULL  ;

ALTER TABLE `sog`.`glam_supervisor_schedule` ADD COLUMN `transaction_job_card` VARCHAR(64) NULL DEFAULT NULL  AFTER `transaction_is_declined` , CHANGE COLUMN `transaction_location` `transaction_location` POINT NULL  ;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
