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_access_point` 
ADD INDEX `idx_lock_type` (`access_point_type` ASC) ;

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

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

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_point_log_archive` (
  `access_point_log_id` CHAR(36) NOT NULL ,
  `access_object_id` CHAR(36) NULL DEFAULT NULL ,
  `access_object_serial_no` INT(11) NULL DEFAULT NULL ,
  `key_log_time` INT(10) UNSIGNED NOT NULL ,
  `log_notification_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' ,
  `ap_log_location` POINT NULL DEFAULT NULL ,
  `transaction_id` CHAR(36) NULL DEFAULT NULL ,
  `keyholder_id` CHAR(36) NULL DEFAULT NULL ,
  `access_point_id` CHAR(36) NULL DEFAULT NULL ,
  `lock_rf_id` BIGINT(20) NULL DEFAULT NULL ,
  PRIMARY KEY (`access_point_log_id`) ,
  INDEX `fk_key_notification_idx` (`log_notification_id` ASC) ,
  INDEX `key_log_time` (`key_log_time` ASC) ,
  INDEX `idx_ao_id` (`access_object_id` ASC) ,
  INDEX `idx_ap_id` (`access_point_id` ASC) ,
  INDEX `idx_user_id` (`keyholder_id` ASC) ,
  UNIQUE INDEX `unique_idx` (`key_log_time` ASC, `log_notification_id` ASC, `access_object_id` ASC) ,
  CONSTRAINT `fk_key_notification0`
    FOREIGN KEY (`log_notification_id` )
    REFERENCES `sog`.`glam_notification` (`notification_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;


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