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

CREATE  TABLE IF NOT EXISTS `sog`.`glam_transaction_group` (
  `trans_group_id` CHAR(36) NOT NULL ,
  `trans_group_name` VARCHAR(45) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  PRIMARY KEY (`trans_group_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

ALTER TABLE `sog`.`glam_transaction` ADD COLUMN `transaction_group_id` CHAR(36) NULL DEFAULT NULL  AFTER `last_changed_on` , 
  ADD CONSTRAINT `fk_glam_transaction_glam_transaction_group1`
  FOREIGN KEY (`transaction_group_id` )
  REFERENCES `sog`.`glam_transaction_group` (`trans_group_id` )
  ON DELETE SET NULL
  ON UPDATE CASCADE
, ADD INDEX `fk_glam_transaction_glam_transaction_group1_idx` (`transaction_group_id` ASC) ;

ALTER TABLE `sog`.`glam_his_transaction` ADD COLUMN `transaction_group_id` CHAR(36) NULL DEFAULT NULL  AFTER `last_changed_on` ;

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

CREATE  TABLE IF NOT EXISTS `sog`.`glam_point` (
  `point_id` CHAR(36) NOT NULL ,
  `point_location` POINT NULL ,
  `point_desc` VARCHAR(255) NULL DEFAULT NULL ,
  `point_radius` FLOAT(11) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  PRIMARY KEY (`point_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_route` (
  `route_id` CHAR(36) NOT NULL ,
  `route_name` VARCHAR(45) NULL DEFAULT NULL ,
  `route_desc` VARCHAR(255) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  PRIMARY KEY (`route_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_route_has_glam_point` (
  `glam_route_route_id` CHAR(36) NOT NULL ,
  `glam_point_point_id` CHAR(36) NOT NULL ,
  `route_point_seq_num` INT(11) NULL DEFAULT 0 ,
  PRIMARY KEY (`glam_route_route_id`, `glam_point_point_id`) ,
  INDEX `fk_glam_route_has_glam_point_glam_point1_idx` (`glam_point_point_id` ASC) ,
  INDEX `fk_glam_route_has_glam_point_glam_route1_idx` (`glam_route_route_id` ASC) ,
  CONSTRAINT `fk_glam_route_has_glam_point_glam_route1`
    FOREIGN KEY (`glam_route_route_id` )
    REFERENCES `sog`.`glam_route` (`route_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_route_has_glam_point_glam_point1`
    FOREIGN KEY (`glam_point_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_his_transaction_group` (
  `his_id` BIGINT(20) NOT NULL AUTO_INCREMENT ,
  `trans_group_id` CHAR(36) NOT NULL ,
  `trans_group_name` VARCHAR(45) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL DEFAULT NULL ,
  PRIMARY KEY (`his_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COLLATE = latin1_swedish_ci;


START TRANSACTION;
USE `sog`;
UPDATE `sog`.`glam_notification` SET `notification_desc`= 'Failed authorized opening – Not in scheduled area' WHERE `notification_id`=33;
UPDATE `sog`.`glam_notification` SET `notification_desc`= 'Failed authorized closing – Not in scheduled area' WHERE `notification_id`=34;
COMMIT;

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