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,ALLOW_INVALID_DATES';

ALTER TABLE `sog`.`glam_access_object_key` ADD COLUMN `key_operation_mode` ENUM('AUTOMATIC','MANUAL') NULL DEFAULT 'AUTOMATIC'  AFTER `version` , ADD COLUMN `key_transactions_limited` BIT(1) NULL DEFAULT b'0'  AFTER `key_operation_mode` , ADD COLUMN `key_transaction_limit` INT(11) NULL DEFAULT 0  AFTER `key_transactions_limited` ;

ALTER TABLE `sog`.`glam_his_access_point` CHANGE COLUMN `his_action` `his_action` ENUM('ADDED','UPDATED','DELETED','LOCK_REPLACED','LATCH_REPLACED','VALIDATED','RESTORED') NULL DEFAULT NULL  ;

ALTER TABLE `sog`.`glam_his_access_object_key` ADD COLUMN `key_operation_mode` ENUM('AUTOMATIC','MANUAL') NULL DEFAULT 'AUTOMATIC'  AFTER `access_obj_serial_no` , ADD COLUMN `key_transactions_limited` BIT(1) NULL DEFAULT b'0'  AFTER `key_operation_mode` , ADD COLUMN `key_transaction_limit` INT(11) NULL DEFAULT 0  AFTER `key_transactions_limited` ;

ALTER TABLE `sog`.`glam_supervisor_schedule` CHANGE COLUMN `transaction_location` `transaction_location` POINT NULL  ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_actionable` (
  `his_id` CHAR(36) NOT NULL ,
  `action_id` CHAR(36) NOT NULL ,
  `action_type` ENUM('DISCOVERED_KEY','DISCOVERED_LOCK','LOCK_UNSAFE','LATCH_REPLACEMENT','LOCK_REPLACEMENT','PENDING_SCHEDULE','PENDING_SRM','UNSAFE_LOCK','SHARED_LOCK','SRM_FAULT','LOCK_OUT_ZONE','SRM_OFFLINE','SRM_INACTIVE') NULL DEFAULT NULL ,
  `access_object_id` CHAR(36) NULL DEFAULT NULL ,
  `access_point_id` CHAR(36) NULL DEFAULT NULL ,
  `usr_id` CHAR(36) NULL DEFAULT NULL ,
  `action_state` ENUM('ACKNOWLEDGED','UNACKNOWLEDGED') NULL DEFAULT NULL ,
  `changed_by` CHAR(36) NULL DEFAULT NULL ,
  `changed_on` DATETIME NULL DEFAULT NULL ,
  `stakeholder_id` CHAR(36) NULL DEFAULT NULL ,
  `transaction_id` CHAR(36) NULL DEFAULT NULL ,
  `clearable` BIT(1) NULL DEFAULT b'0' ,
  `time_action_logged` INT(11) NULL DEFAULT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `his_action` ENUM('ADDED','UPDATED','DELETED','ACKOWLEDGED','CLEARED','ACK_CLEAR') NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  PRIMARY KEY (`his_id`) ,
  INDEX `TYPE` (`action_type` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

INSERT INTO glam_notification (notification_id,notification_desc) VALUES (44,'Original latch restored.'),
(43,'Original lock restored.');

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