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_system_details` ADD COLUMN `system_key_sec_ip_address` VARCHAR(64) NULL DEFAULT NULL  AFTER `system_sub_colour` , ADD COLUMN `system_key_sec_port` INT(11) NULL DEFAULT NULL  AFTER `system_key_sec_ip_address` , ADD COLUMN `system_audible_alarm_enabled` BIT(1) NULL DEFAULT b'0'  AFTER `system_key_sec_port` ;

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

ALTER TABLE `sog`.`glam_point` CHANGE COLUMN `point_location` `point_location` POINT NULL  ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_ext_exam_center` (
  `point_id` CHAR(36) NOT NULL ,
  `center_address` VARCHAR(256) NULL DEFAULT NULL ,
  `center_tel` VARCHAR(16) NULL DEFAULT NULL ,
  `center_abbreviation` VARCHAR(8) NULL DEFAULT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  PRIMARY KEY (`point_id`) ,
  INDEX `fk_glam_ext_exam_center_glam_point1_idx` (`point_id` ASC) ,
  CONSTRAINT `fk_glam_ext_exam_center_glam_point1`
    FOREIGN KEY (`point_id` )
    REFERENCES `sog`.`glam_point` (`point_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_ext_exam_schedule` (
  `exam_sched_id` INT(11) NOT NULL AUTO_INCREMENT ,
  `center_point_id` CHAR(36) NOT NULL ,
  `timetable_table_id` CHAR(36) NOT NULL ,
  `sched_comment` VARCHAR(256) NULL DEFAULT NULL ,
  `objholder_id` CHAR(36) NULL DEFAULT NULL ,
  `sched_status` ENUM('UNKNOWN','PENDING','READY','CREATED','INVALID_OH','INVALID_AP','DELETED') NULL DEFAULT 'PENDING' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  INDEX `fk_glam_ext_exam_schedule_glam_ext_exam_timetable1_idx` (`timetable_table_id` ASC) ,
  INDEX `fk_glam_ext_exam_schedule_glam_ext_exam_center1_idx` (`center_point_id` ASC) ,
  PRIMARY KEY (`exam_sched_id`) ,
  CONSTRAINT `fk_glam_ext_exam_schedule_glam_ext_exam_timetable1`
    FOREIGN KEY (`timetable_table_id` )
    REFERENCES `sog`.`glam_ext_exam_timetable` (`table_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ext_exam_schedule_glam_ext_exam_center1`
    FOREIGN KEY (`center_point_id` )
    REFERENCES `sog`.`glam_ext_exam_center` (`point_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_ext_exam_timetable` (
  `table_id` CHAR(36) NOT NULL ,
  `table_start_time` INT(11) NULL DEFAULT NULL ,
  `table_end_time` INT(11) NULL DEFAULT NULL ,
  `table_subject` VARCHAR(128) NULL DEFAULT NULL ,
  `table_abbreviation` VARCHAR(8) NULL DEFAULT NULL ,
  `table_group_id` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  PRIMARY KEY (`table_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_ext_exam_schedule_ap` (
  `access_point_id` CHAR(36) NOT NULL ,
  `exam_sched_id` INT(11) NOT NULL ,
  `access_point_rf_id` BIGINT(20) NULL DEFAULT NULL ,
  INDEX `fk_glam_ext_exam_schedule_lock_glam_access_point1_idx` (`access_point_id` ASC) ,
  INDEX `fk_glam_ext_exam_schedule_lock_glam_ext_exam_schedule1_idx` (`exam_sched_id` ASC) ,
  PRIMARY KEY (`access_point_id`, `exam_sched_id`) ,
  CONSTRAINT `fk_glam_ext_exam_schedule_lock_glam_access_point1`
    FOREIGN KEY (`access_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ext_exam_schedule_lock_glam_ext_exam_schedule1`
    FOREIGN KEY (`exam_sched_id` )
    REFERENCES `sog`.`glam_ext_exam_schedule` (`exam_sched_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_ext_exam_schedule_oh` (
  `exam_sched_id` INT(11) NOT NULL ,
  `objholder_id` CHAR(36) NOT NULL ,
  INDEX `fk_glam_ext_exam_schedule_objholder_glam_ext_exam_schedule1_idx` (`exam_sched_id` ASC) ,
  INDEX `fk_glam_ext_exam_schedule_objholder_glam_objholder1_idx` (`objholder_id` ASC) ,
  PRIMARY KEY (`exam_sched_id`, `objholder_id`) ,
  CONSTRAINT `fk_glam_ext_exam_schedule_objholder_glam_ext_exam_schedule1`
    FOREIGN KEY (`exam_sched_id` )
    REFERENCES `sog`.`glam_ext_exam_schedule` (`exam_sched_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ext_exam_schedule_objholder_glam_objholder1`
    FOREIGN KEY (`objholder_id` )
    REFERENCES `sog`.`glam_objholder` (`user_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;
