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

DROP SCHEMA IF EXISTS `sog` ;
CREATE SCHEMA IF NOT EXISTS `sog` DEFAULT CHARACTER SET latin1 ;
USE `sog` ;

-- -----------------------------------------------------
-- Table `sog`.`glam_domain`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_domain` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_domain` (
  `domain_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `domain_name` VARCHAR(50) NULL DEFAULT NULL ,
  `domain_region` GEOMETRY NULL DEFAULT NULL ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `version` INT NULL DEFAULT 0 ,
  `parent_domain_id` INT UNSIGNED NULL DEFAULT NULL ,
  `in_lockdown` BIT NULL DEFAULT b'0' ,
  PRIMARY KEY (`domain_id`) ,
  INDEX `fk_glam_domain_glam_domain1_idx` (`parent_domain_id` ASC) ,
  CONSTRAINT `fk_glam_domain_glam_domain1`
    FOREIGN KEY (`parent_domain_id` )
    REFERENCES `sog`.`glam_domain` (`domain_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
AUTO_INCREMENT = 2
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_keyholder_group`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_keyholder_group` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_keyholder_group` (
  `group_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `group_name` VARCHAR(64) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL ,
  `group_description` VARCHAR(200) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL ,
  PRIMARY KEY (`group_id`) ,
  UNIQUE INDEX `group_name_UNIQUE` (`group_name` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_objholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_objholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_objholder` (
  `user_id` CHAR(36) NOT NULL ,
  `group_id` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `objholder_active` BIT(1) NULL DEFAULT b'1' ,
  `objholder_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `version` INT(11) NULL DEFAULT '0' ,
  INDEX `fk_glam_keyholder_glam_keyholder_group1_idx` (`group_id` ASC) ,
  PRIMARY KEY (`user_id`) ,
  CONSTRAINT `fk_glam_keyholder_glam_keyholder_group1`
    FOREIGN KEY (`group_id` )
    REFERENCES `sog`.`glam_keyholder_group` (`group_id` )
    ON DELETE SET NULL
    ON UPDATE SET NULL)
ENGINE = InnoDB
AUTO_INCREMENT = 58
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_domain_objholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_domain_objholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_domain_objholder` (
  `domain_id` INT UNSIGNED NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`domain_id`, `user_id`) ,
  INDEX `fk_glam_domain_objholder_glam_objholder1_idx` (`user_id` ASC) ,
  INDEX `fk_glam_batch_keyholder_glam_batch1_idx` (`domain_id` ASC) ,
  CONSTRAINT `fk_glam_batch_keyholder_glam_batch1`
    FOREIGN KEY (`domain_id` )
    REFERENCES `sog`.`glam_domain` (`domain_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_domain_objholder_glam_objholder1`
    FOREIGN KEY (`user_id` )
    REFERENCES `sog`.`glam_objholder` (`user_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_point` (
  `access_point_id` CHAR(36) NOT NULL ,
  `access_point_serial_no` INT NOT NULL ,
  `access_point_status` ENUM('OPEN','CLOSED','UNKNOWN') NULL DEFAULT 'UNKNOWN' ,
  `access_point_com_status` ENUM('COMMISSIONED','UNCOMMISSIONED','DISCOVERED') NULL DEFAULT 'DISCOVERED' ,
  `access_point_description` VARCHAR(256) NULL DEFAULT NULL ,
  `access_point_comment` VARCHAR(1024) NULL DEFAULT NULL ,
  `access_point_safe_status` ENUM('BUSY','UNSAFE','SAFE') NULL DEFAULT 'SAFE' ,
  `access_point_is_owner` BIT(1) NULL DEFAULT b'1' COMMENT 'Indicates if this system \nis the owner of the lock.' ,
  `access_point_last_status_change` INT(10) UNSIGNED NULL DEFAULT '0' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `version` INT(11) NULL DEFAULT '0' ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `ap_replacement_serial_no` INT NULL DEFAULT NULL ,
  `in_lockdown` BIT NULL DEFAULT b'0' ,
  `access_point_rf_id` BIGINT NULL ,
  `access_point_location` POINT NULL DEFAULT NULL ,
  `access_point_rf_replacement` BIGINT NULL DEFAULT NULL ,
  `glam_access_pointcol` VARCHAR(45) NULL DEFAULT NULL ,
  `access_point_type` INT NULL DEFAULT 0 ,
  `ap_share_status` ENUM('NONE','SHARED_BY','SHARED_TO') NULL DEFAULT 'NONE' ,
  `ap_key_replaced_serial_no` INT NULL DEFAULT NULL ,
  `ap_key_replaced_latch` INT NULL DEFAULT NULL ,
  `ap_last_access_by` CHAR(36) NULL DEFAULT NULL ,
  `ap_movement_radius` FLOAT NULL DEFAULT 10.0 ,
  `ap_movement_last_pos` POINT NULL DEFAULT NULL ,
  `ap_movement_alarm_enabled` BIT NULL DEFAULT b'0' ,
  PRIMARY KEY (`access_point_id`) ,
  UNIQUE INDEX `access_point_serial_no_UNIQUE` (`access_point_serial_no` ASC) ,
  INDEX `is_deleted` (`is_deleted` ASC) ,
  INDEX `description` (`access_point_description` ASC) ,
  UNIQUE INDEX `access_point_rf_id_UNIQUE` (`access_point_rf_id` ASC) ,
  INDEX `idx_lock_type` (`access_point_type` ASC) )
ENGINE = InnoDB
AUTO_INCREMENT = 3724
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_domain_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_domain_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_domain_access_point` (
  `domain_id` INT UNSIGNED NOT NULL ,
  `access_point_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`domain_id`, `access_point_id`) ,
  INDEX `fk_glam_domain_access_point_glam_access_point1_idx` (`access_point_id` ASC) ,
  INDEX `fk_bl_batch_idx` (`domain_id` ASC) ,
  CONSTRAINT `fk_bl_batch`
    FOREIGN KEY (`domain_id` )
    REFERENCES `sog`.`glam_domain` (`domain_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_domain_access_point_glam_access_point1`
    FOREIGN KEY (`access_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_systemuser`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_systemuser` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_systemuser` (
  `user_id` CHAR(36) NOT NULL ,
  `user_group_access` SMALLINT NULL DEFAULT 0 ,
  `is_deleted` BIT(1) NULL ,
  `version` INT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL ,
  PRIMARY KEY (`user_id`) )
ENGINE = InnoDB
AUTO_INCREMENT = 71
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_domain_systemuser`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_domain_systemuser` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_domain_systemuser` (
  `domain_id` INT UNSIGNED NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`domain_id`, `user_id`) ,
  INDEX `fk_glam_domain_systemuser_glam_domain1_idx` (`domain_id` ASC) ,
  INDEX `fk_glam_domain_systemuser_glam_systemuser1_idx` (`user_id` ASC) ,
  CONSTRAINT `fk_glam_domain_systemuser_glam_domain1`
    FOREIGN KEY (`domain_id` )
    REFERENCES `sog`.`glam_domain` (`domain_id` )
    ON DELETE NO ACTION
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_domain_systemuser_glam_systemuser1`
    FOREIGN KEY (`user_id` )
    REFERENCES `sog`.`glam_systemuser` (`user_id` )
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_object`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_object` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_object` (
  `access_object_id` CHAR(36) NOT NULL ,
  `access_obj_serial_no` INT NULL ,
  `obj_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `version` INT(11) NULL DEFAULT '0' ,
  `user_id` CHAR(36) NULL ,
  PRIMARY KEY (`access_object_id`) ,
  INDEX `is_deleted` (`is_deleted` ASC) ,
  UNIQUE INDEX `access_obj_serial_no_UNIQUE` (`access_obj_serial_no` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_severity`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_severity` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_severity` (
  `severity_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `severity_name` VARCHAR(50) NULL DEFAULT NULL ,
  `serverity_level` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `severity_colour` VARCHAR(10) NULL DEFAULT NULL ,
  PRIMARY KEY (`severity_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_notification`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_notification` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_notification` (
  `notification_id` INT(10) UNSIGNED NOT NULL ,
  `notification_desc` VARCHAR(100) NULL DEFAULT NULL ,
  `severity_id` INT(10) UNSIGNED NULL DEFAULT NULL ,
  PRIMARY KEY (`notification_id`) ,
  INDEX `fk_notify_sev_idx` (`severity_id` ASC) ,
  CONSTRAINT `fk_notify_sev`
    FOREIGN KEY (`severity_id` )
    REFERENCES `sog`.`glam_severity` (`severity_id` )
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_point_log`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_point_log` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_point_log` (
  `access_point_log_id` CHAR(36) NOT NULL ,
  `access_object_id` CHAR(36) NULL ,
  `access_object_serial_no` INT 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 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_notification`
    FOREIGN KEY (`log_notification_id` )
    REFERENCES `sog`.`glam_notification` (`notification_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_objholder_unsafe_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_objholder_unsafe_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_objholder_unsafe_point` (
  `hup_acces_point_id` CHAR(36) NOT NULL ,
  `hup_user_id` CHAR(36) NOT NULL ,
  `hup_date_flagged` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`hup_acces_point_id`, `hup_user_id`) ,
  INDEX `fk_glam_keyholder_unsafe_lock_glam_lock1_idx` (`hup_acces_point_id` ASC) ,
  INDEX `fk_glam_objholder_unsafe_point_glam_objholder1_idx` (`hup_user_id` ASC) ,
  CONSTRAINT `fk_glam_keyholder_unsafe_lock_glam_lock1`
    FOREIGN KEY (`hup_acces_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_glam_objholder_unsafe_point_glam_objholder1`
    FOREIGN KEY (`hup_user_id` )
    REFERENCES `sog`.`glam_objholder` (`user_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_lid_track`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_lid_track` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_lid_track` (
  `lid_id` INT NOT NULL AUTO_INCREMENT ,
  `lid_location` POINT NOT NULL ,
  `lid_description` VARCHAR(128) NULL ,
  `lid_comment` VARCHAR(512) NULL ,
  SPATIAL INDEX `lid_location` (`lid_location` ASC) ,
  PRIMARY KEY (`lid_id`) )
ENGINE = MyISAM
AUTO_INCREMENT = 5
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_stakeholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_stakeholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_stakeholder` (
  `sh_id` CHAR(36) NOT NULL ,
  `sh_name` VARCHAR(64) NOT NULL ,
  `sh_description` VARCHAR(256) NULL DEFAULT NULL ,
  `sh_service_url` VARCHAR(128) NOT NULL ,
  `sh_is_active` BIT(1) NULL DEFAULT b'1' ,
  `sh_date_created` DATETIME NOT NULL ,
  `sh_user_id` CHAR(36) NULL DEFAULT NULL COMMENT 'ID of the system user that\ncreated the stakeholder.' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `version` INT(10) UNSIGNED NULL DEFAULT '0' ,
  `sh_sys_to_sh_username` VARCHAR(64) NULL DEFAULT NULL ,
  `sh_sys_to_sh_pwd` VARCHAR(64) NULL DEFAULT NULL ,
  `sh_system_name` VARCHAR(64) NULL DEFAULT NULL ,
  `sh_system_unique_id` VARCHAR(36) NULL DEFAULT NULL ,
  `sh_is_shadow` BIT(1) NULL DEFAULT b'0' ,
  `sh_current_sequence` INT(10) UNSIGNED NULL DEFAULT '0' ,
  `sh_last_sync_sequence` INT(10) UNSIGNED NULL DEFAULT '0' ,
  `sh_share_confirm_status` ENUM('UNCONFIRMED','CONFIRMED','VALIDATED','VALIDATION_ERROR','PENDING_DELETION') NULL DEFAULT 'UNCONFIRMED' ,
  `sh_share_confirm_code` INT(11) NULL DEFAULT '0' ,
  `sh_share_policy` ENUM('AUTH_REQ','NO_AUTH_REQ','SHARE_DEFINED') NULL DEFAULT 'AUTH_REQ' ,
  `sh_share_system_status` ENUM('OFFLINE','ONLINE') NULL DEFAULT 'OFFLINE' ,
  PRIMARY KEY (`sh_id`) ,
  INDEX `is_deleted` (`is_deleted` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_sh_notification_log`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_sh_notification_log` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_sh_notification_log` (
  `shnl_id` CHAR(36) NOT NULL ,
  `shnl_date_created` DATETIME NOT NULL ,
  `shnl_action` BLOB NULL DEFAULT NULL ,
  `shnl_sh_id` CHAR(36) NOT NULL ,
  `shnl_retry_count` INT(11) NULL DEFAULT '0' ,
  PRIMARY KEY (`shnl_id`) ,
  INDEX `fk_glam_srm_sh_notification_log_glam_srm_stakeholder1_idx` (`shnl_sh_id` ASC) ,
  CONSTRAINT `fk_glam_srm_sh_notification_log_glam_srm_stakeholder1`
    FOREIGN KEY (`shnl_sh_id` )
    REFERENCES `sog`.`glam_srm_stakeholder` (`sh_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_shared_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_shared_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_shared_access_point` (
  `glam_srm_sh_id` CHAR(36) NOT NULL ,
  `access_point_id` CHAR(36) NOT NULL ,
  `glam_srm_share_created_on` DATETIME NOT NULL ,
  `glam_srm_share_created_by` CHAR(36) NULL DEFAULT NULL ,
  `glam_srm_share_status` ENUM('PENDING_ADDITION','PENDING_REMOVAL','CONFIRMED') NULL DEFAULT 'PENDING_ADDITION' ,
  `glam_srm_sh_transaction_policy` ENUM('AUTH_REQ','NO_AUTH_REQ') NULL DEFAULT 'AUTH_REQ' ,
  `glam_srm_last_changed` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`glam_srm_sh_id`, `access_point_id`) ,
  INDEX `fk_glam_srm_shared_lock_glam_srm_stakeholder1_idx` (`glam_srm_sh_id` ASC) ,
  INDEX `fk_glam_srm_shared_access_point_glam_access_point1_idx` (`access_point_id` ASC) ,
  CONSTRAINT `fk_glam_srm_shared_lock_glam_srm_stakeholder1`
    FOREIGN KEY (`glam_srm_sh_id` )
    REFERENCES `sog`.`glam_srm_stakeholder` (`sh_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_srm_shared_access_point_glam_access_point1`
    FOREIGN KEY (`access_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COMMENT = 'glam_srm_stakeholder_sh_id';


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_stakeholder_access_object`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_stakeholder_access_object` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_stakeholder_access_object` (
  `glam_srm_sh_id` CHAR(36) NOT NULL ,
  `glam_srm_share_created_on` DATETIME NOT NULL ,
  `access_object_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`glam_srm_sh_id`, `access_object_id`) ,
  INDEX `fk_glam_srm_stakeholder_access_object_glam_access_object1_idx` (`access_object_id` ASC) ,
  INDEX `fk_glam_srm_stakeholder_key_glam_srm_stakeholder1_idx` (`glam_srm_sh_id` ASC) ,
  CONSTRAINT `fk_glam_srm_stakeholder_key_glam_srm_stakeholder1`
    FOREIGN KEY (`glam_srm_sh_id` )
    REFERENCES `sog`.`glam_srm_stakeholder` (`sh_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_srm_stakeholder_access_object_glam_access_object1`
    FOREIGN KEY (`access_object_id` )
    REFERENCES `sog`.`glam_access_object` (`access_object_id` )
    ON DELETE RESTRICT
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_stakeholder_objholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_stakeholder_objholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_stakeholder_objholder` (
  `glam_srm_sh_id` CHAR(36) NOT NULL ,
  `glam_srm_share_created_on` DATETIME NOT NULL ,
  `keyholder_id_owner` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `glam_objholder_user_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`glam_srm_sh_id`, `glam_objholder_user_id`) ,
  INDEX `fk_glam_srm_stakeholder_keyholder_glam_srm_stakeholder1_idx` (`glam_srm_sh_id` ASC) ,
  INDEX `fk_glam_srm_stakeholder_objholder_glam_objholder1_idx` (`glam_objholder_user_id` ASC) ,
  CONSTRAINT `fk_glam_srm_stakeholder_keyholder_glam_srm_stakeholder1`
    FOREIGN KEY (`glam_srm_sh_id` )
    REFERENCES `sog`.`glam_srm_stakeholder` (`sh_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_srm_stakeholder_objholder_glam_objholder1`
    FOREIGN KEY (`glam_objholder_user_id` )
    REFERENCES `sog`.`glam_objholder` (`user_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_stakeholder_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_stakeholder_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_stakeholder_access_point` (
  `glam_srm_sh_id` CHAR(36) NOT NULL ,
  `glam_access_point_access_point_id` CHAR(36) NOT NULL ,
  `glam_srm_sh_date_created` DATETIME NOT NULL ,
  `glam_srm_sh_transaction_policy` ENUM('AUTH_REQ','NO_AUTH_REQ') NULL DEFAULT 'AUTH_REQ' ,
  `glam_srm_last_changed` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`glam_srm_sh_id`, `glam_access_point_access_point_id`) ,
  INDEX `fk_glam_srm_stakeholder_lock_glam_access_point1_idx` (`glam_access_point_access_point_id` ASC) ,
  INDEX `fk_glam_srm_stakeholder_lock_glam_srm_stakeholder1_idx` (`glam_srm_sh_id` ASC) ,
  CONSTRAINT `fk_glam_srm_stakeholder_lock_glam_srm_stakeholder1`
    FOREIGN KEY (`glam_srm_sh_id` )
    REFERENCES `sog`.`glam_srm_stakeholder` (`sh_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_srm_stakeholder_lock_glam_access_point1`
    FOREIGN KEY (`glam_access_point_access_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1
COMMENT = 'Locks that have been shared by OTHER system.';


-- -----------------------------------------------------
-- Table `sog`.`glam_transaction`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_transaction` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_transaction` (
  `transaction_id` CHAR(36) NOT NULL ,
  `transaction_date_start` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_date_end` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_auth_no` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_gps_radius` FLOAT NULL DEFAULT NULL ,
  `transaction_description` VARCHAR(200) NULL DEFAULT NULL ,
  `transaction_recursion` VARCHAR(20) NULL DEFAULT NULL ,
  `transaction_id_owner` CHAR(36) NULL DEFAULT NULL ,
  `transaction_authenticated_by` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `transaction_job_card` VARCHAR(64) NULL DEFAULT NULL ,
  `transaction_location` POINT NULL DEFAULT NULL ,
  `transaction_type` ENUM('STATIC','MOBILE') NULL DEFAULT 'STATIC' ,
  PRIMARY KEY (`transaction_id`) ,
  INDEX `transaction_date_start` (`transaction_date_start` ASC) ,
  INDEX `transaction_date_end` (`transaction_date_end` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_srm_stakeholder_transaction`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_srm_stakeholder_transaction` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_srm_stakeholder_transaction` (
  `glam_srm_sh_id` CHAR(36) NOT NULL ,
  `transaction_id` CHAR(36) NOT NULL ,
  `glam_srm_last_changed` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`glam_srm_sh_id`, `transaction_id`) ,
  INDEX `fk_glam_srm_transaction_glam_srm_stakeholder1_idx` (`glam_srm_sh_id` ASC) ,
  INDEX `fk_glam_srm_stakeholder_transaction_glam_transaction1_idx` (`transaction_id` ASC) ,
  CONSTRAINT `fk_glam_srm_transaction_glam_srm_stakeholder1`
    FOREIGN KEY (`glam_srm_sh_id` )
    REFERENCES `sog`.`glam_srm_stakeholder` (`sh_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_srm_stakeholder_transaction_glam_transaction1`
    FOREIGN KEY (`transaction_id` )
    REFERENCES `sog`.`glam_transaction` (`transaction_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_system`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_system` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_system` (
  `id` INT(10) UNSIGNED NOT NULL ,
  `last_key_log` INT(10) UNSIGNED NULL DEFAULT '0' ,
  `last_sys_log` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `prev_key_log` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `prev_sys_log` INT(10) UNSIGNED NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) )
ENGINE = MyISAM
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_apn`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_apn` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_apn` (
  `apn_id` INT NOT NULL AUTO_INCREMENT ,
  `apn_name` VARCHAR(64) NULL ,
  `apn_username` VARCHAR(64) NULL ,
  `apn_password` VARCHAR(64) NULL ,
  `apn` VARCHAR(64) NULL ,
  `chesse` VARCHAR(45) NULL ,
  PRIMARY KEY (`apn_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_system_details`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_system_details` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_system_details` (
  `system_id` INT(11) NOT NULL AUTO_INCREMENT ,
  `system_name` VARCHAR(64) NULL DEFAULT NULL ,
  `system_unique_name` VARCHAR(36) NOT NULL ,
  `system_service_url` VARCHAR(128) NULL DEFAULT NULL ,
  `system_share_policy` ENUM('AUTH_REQ','NO_AUTH_REQ') NULL DEFAULT 'AUTH_REQ' ,
  `system_key_ip_address` VARCHAR(64) NULL ,
  `system_key_port` INT NULL ,
  `system_welcome_bitmap` BLOB NULL ,
  `system_geoserver_url` VARCHAR(128) NULL DEFAULT NULL ,
  `default_apn_id` INT NULL DEFAULT NULL ,
  `system_home_coordinates` POINT NULL DEFAULT NULL ,
  PRIMARY KEY (`system_id`) ,
  INDEX `fk_glam_system_details_glam_apn1_idx` (`default_apn_id` ASC) ,
  CONSTRAINT `fk_glam_system_details_glam_apn1`
    FOREIGN KEY (`default_apn_id` )
    REFERENCES `sog`.`glam_apn` (`apn_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_system_log`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_system_log` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_system_log` (
  `syslog_time` INT(10) UNSIGNED NOT NULL DEFAULT '0' ,
  `notification_id` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `pid` VARCHAR(20) NOT NULL ,
  `details` BLOB NULL DEFAULT NULL ,
  PRIMARY KEY (`pid`, `syslog_time`) ,
  INDEX `fk_system_notification_idx` (`notification_id` ASC) ,
  CONSTRAINT `fk_system_notification`
    FOREIGN KEY (`notification_id` )
    REFERENCES `sog`.`glam_notification` (`notification_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_system_mail`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_system_mail` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_system_mail` (
  `user_id` CHAR(36) NOT NULL ,
  `notification_id` INT(10) UNSIGNED NOT NULL ,
  PRIMARY KEY (`user_id`, `notification_id`) ,
  INDEX `fk_mail_notify_idx` (`notification_id` ASC) ,
  CONSTRAINT `fk_mail_notify`
    FOREIGN KEY (`notification_id` )
    REFERENCES `sog`.`glam_notification` (`notification_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_transaction_schedule`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_transaction_schedule` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_transaction_schedule` (
  `access_point_id` CHAR(36) NOT NULL ,
  `transaction_id` CHAR(36) NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  `transaction_operation` ENUM('ACCESS','COMMISSION','ACCESS_COMMISSION','LOCK_REPLACEMENT','LATCH_REPLACEMENT') NULL DEFAULT 'ACCESS' ,
  `transaction_type` ENUM('STATIC','DYNAMIC') NULL DEFAULT 'STATIC' ,
  `trans_sched_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `srm_schedule_confirmation_status` ENUM('PENDING','APPROVED','DECLINED') NULL DEFAULT 'PENDING' ,
  `srm_last_changed` DATETIME NULL DEFAULT NULL ,
  `srm_sh_id` VARCHAR(36) NULL DEFAULT NULL ,
  `srm_transsched_status_code` VARCHAR(64) NULL DEFAULT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `is_suspended` BIT NULL DEFAULT b'0' ,
  `sched_job_card` VARCHAR(64) NULL DEFAULT NULL ,
  PRIMARY KEY (`access_point_id`, `transaction_id`, `user_id`) ,
  INDEX `fk_transaction_trans_idx` (`transaction_id` ASC) ,
  INDEX `fk_glam_transaction_schedule_glam_access_point1_idx` (`access_point_id` ASC) ,
  CONSTRAINT `fk_transaction_trans`
    FOREIGN KEY (`transaction_id` )
    REFERENCES `sog`.`glam_transaction` (`transaction_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_transaction_schedule_glam_access_point1`
    FOREIGN KEY (`access_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`versioning`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`versioning` ;

CREATE  TABLE IF NOT EXISTS `sog`.`versioning` (
  `version_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
  `version_name` VARCHAR(64) NOT NULL ,
  `version_desc` BLOB NULL DEFAULT NULL ,
  `version_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `version` INT(10) UNSIGNED NOT NULL ,
  `version_string` VARCHAR(10) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL ,
  PRIMARY KEY (`version_id`) )
ENGINE = MyISAM
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_object_key`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_object_key` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_object_key` (
  `access_object_id` CHAR(36) NOT NULL ,
  `key_gsm_imei` VARCHAR(20) NULL DEFAULT NULL ,
  `key_sim_card_no` VARCHAR(20) NULL DEFAULT NULL ,
  `key_mode` ENUM('Static','Dynamic') NULL DEFAULT NULL ,
  `key_track_interval` VARCHAR(20) NULL DEFAULT NULL ,
  `key_box_no` VARCHAR(24) NULL DEFAULT NULL ,
  `key_sim_pin` VARCHAR(10) NULL DEFAULT '0000' ,
  `key_sim_puk` VARCHAR(24) NULL DEFAULT '00000000' ,
  `key_location` POINT NULL DEFAULT NULL ,
  `key_hw_version` VARCHAR(24) NULL DEFAULT NULL ,
  `key_sw_version` VARCHAR(20) NULL DEFAULT NULL ,
  `key_charger_version` VARCHAR(20) NULL DEFAULT NULL ,
  `key_server_address` VARCHAR(65) NULL DEFAULT NULL ,
  `key_server_port` VARCHAR(10) NULL DEFAULT NULL ,
  `key_apn` VARCHAR(24) NULL DEFAULT NULL ,
  `key_apn_username` VARCHAR(24) NULL DEFAULT NULL ,
  `key_apn_password` VARCHAR(24) NULL DEFAULT NULL ,
  `key_transaction_download_status` ENUM('PENDING','UPDATED') NULL DEFAULT NULL ,
  `key_tracker` ENUM('Y','N') NULL DEFAULT 'N' ,
  `key_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
  `version` INT(11) NULL DEFAULT '0' ,
  PRIMARY KEY (`access_object_id`) ,
  INDEX `key_box_no` (`key_box_no` ASC) ,
  CONSTRAINT `fk_glam_access_object_key_glam_access_object1`
    FOREIGN KEY (`access_object_id` )
    REFERENCES `sog`.`glam_access_object` (`access_object_id` )
    ON DELETE NO ACTION
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_object_card`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_object_card` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_object_card` (
  `access_object_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`access_object_id`) ,
  INDEX `fk_glam_access_object_card_glam_access_object1_idx` (`access_object_id` ASC) ,
  CONSTRAINT `fk_glam_access_object_card_glam_access_object1`
    FOREIGN KEY (`access_object_id` )
    REFERENCES `sog`.`glam_access_object` (`access_object_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag` (
  `tag_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `tag_name` VARCHAR(64) NULL ,
  `tag_colour` INT NULL ,
  `tag_description` VARCHAR(256) NULL DEFAULT NULL ,
  `is_deleted` BIT NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL ,
  `last_changed_on` TIMESTAMP NULL ,
  `version` INT NULL ,
  PRIMARY KEY (`tag_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_object_key`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_object_key` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_object_key` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `access_object_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `access_object_id`) ,
  INDEX `fk_glam_tag_object_key_glam_access_object1_idx` (`access_object_id` ASC) ,
  INDEX `fk_glam_tag_object_key_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_object_key_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  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)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_access_point` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `access_point_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `access_point_id`) ,
  INDEX `fk_glam_tag_access_point_glam_access_point1_idx` (`access_point_id` ASC) ,
  INDEX `fk_glam_tag_access_point_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_access_point_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_tag_access_point_glam_access_point1`
    FOREIGN KEY (`access_point_id` )
    REFERENCES `sog`.`glam_access_point` (`access_point_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_transaction`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_transaction` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_transaction` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `transaction_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `transaction_id`) ,
  INDEX `fk_glam_tag_transaction_glam_transaction1_idx` (`transaction_id` ASC) ,
  INDEX `fk_glam_tag_transaction_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_transaction_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_tag_transaction_glam_transaction1`
    FOREIGN KEY (`transaction_id` )
    REFERENCES `sog`.`glam_transaction` (`transaction_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_objholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_objholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_objholder` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `user_id`) ,
  INDEX `fk_glam_tag_objholder_glam_objholder1_idx` (`user_id` ASC) ,
  INDEX `fk_glam_tag_objholder_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_objholder_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_tag_objholder_glam_objholder1`
    FOREIGN KEY (`user_id` )
    REFERENCES `sog`.`glam_objholder` (`user_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_transaction_schedule`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_transaction_schedule` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_transaction_schedule` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `access_point_id` CHAR(36) NOT NULL ,
  `transaction_id` CHAR(36) NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `access_point_id`, `transaction_id`, `user_id`) ,
  INDEX `fk_glam_tag_transaction_schedule_glam_transaction_schedule1_idx` (`access_point_id` ASC, `transaction_id` ASC, `user_id` ASC) ,
  INDEX `fk_glam_tag_transaction_schedule_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_transaction_schedule_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  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)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_domain`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_domain` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_domain` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `domain_id` INT UNSIGNED NOT NULL ,
  PRIMARY KEY (`tag_id`, `domain_id`) ,
  INDEX `fk_glam_tag_domain_glam_domain1_idx` (`domain_id` ASC) ,
  INDEX `fk_glam_tag_domain_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_domain_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_tag_domain_glam_domain1`
    FOREIGN KEY (`domain_id` )
    REFERENCES `sog`.`glam_domain` (`domain_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_domain_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_domain_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_domain_access_point` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `domain_ap_domain_id` INT UNSIGNED NOT NULL ,
  `domain_ap_access_point_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `domain_ap_domain_id`, `domain_ap_access_point_id`) ,
  INDEX `fk_glam_tag_domain_access_point_glam_domain_access_point1_idx` (`domain_ap_domain_id` ASC, `domain_ap_access_point_id` ASC) ,
  INDEX `fk_glam_tag_domain_access_point_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_domain_access_point_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_tag_domain_access_point_glam_domain_access_point1`
    FOREIGN KEY (`domain_ap_domain_id` , `domain_ap_access_point_id` )
    REFERENCES `sog`.`glam_domain_access_point` (`domain_id` , `access_point_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_tag_domain_objholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_tag_domain_objholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_tag_domain_objholder` (
  `tag_id` INT UNSIGNED NOT NULL ,
  `domain_objholder_domain_id` INT UNSIGNED NOT NULL ,
  `domain_objholder_user_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`tag_id`, `domain_objholder_domain_id`, `domain_objholder_user_id`) ,
  INDEX `fk_glam_tag_domain_objholder_glam_domain_objholder1_idx` (`domain_objholder_domain_id` ASC, `domain_objholder_user_id` ASC) ,
  INDEX `fk_glam_tag_domain_objholder_glam_tag1_idx` (`tag_id` ASC) ,
  CONSTRAINT `fk_glam_tag_domain_objholder_glam_tag1`
    FOREIGN KEY (`tag_id` )
    REFERENCES `sog`.`glam_tag` (`tag_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_tag_domain_objholder_glam_domain_objholder1`
    FOREIGN KEY (`domain_objholder_domain_id` , `domain_objholder_user_id` )
    REFERENCES `sog`.`glam_domain_objholder` (`domain_id` , `user_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_application`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_application` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_application` (
  `app_id` CHAR(36) NOT NULL ,
  `app_name` VARCHAR(64) NULL DEFAULT NULL ,
  `app_description` VARCHAR(256) NULL DEFAULT NULL ,
  `app_version` VARCHAR(8) NULL DEFAULT NULL ,
  `app_location` VARCHAR(45) NULL DEFAULT NULL ,
  PRIMARY KEY (`app_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_application_role`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_application_role` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_application_role` (
  `app_role_id` CHAR(36) NOT NULL ,
  `app_id` CHAR(36) NOT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT NULL ,
  `app_role_name` VARCHAR(64) NULL DEFAULT NULL ,
  PRIMARY KEY (`app_role_id`) ,
  INDEX `fk_krf_application_role_krf_application1_idx` (`app_id` ASC) ,
  CONSTRAINT `fk_krf_application_role_krf_application1`
    FOREIGN KEY (`app_id` )
    REFERENCES `sog`.`krf_application` (`app_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_role`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_role` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_role` (
  `role_id` CHAR(36) NOT NULL ,
  `role_name` VARCHAR(64) NULL DEFAULT NULL ,
  PRIMARY KEY (`role_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_user`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_user` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_user` (
  `usr_id` CHAR(36) NOT NULL ,
  `usr_username` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_password` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_firstname` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_lastname` VARCHAR(128) NULL DEFAULT NULL ,
  `usr_contact_cell_no` VARCHAR(16) NULL DEFAULT NULL ,
  `usr_contact_work_no` VARCHAR(16) NULL DEFAULT NULL ,
  `usr_contact_email` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_employee_no` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_is_active` BIT(1) NULL DEFAULT b'1' ,
  `usr_system_role` VARCHAR(64) NULL DEFAULT 'SYS_USER' ,
  `usr_last_login` DATETIME NULL DEFAULT NULL ,
  `usr_api_key` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_timezone_id` VARCHAR(64) NULL DEFAULT NULL ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT NULL ,
  `version` INT(11) NULL DEFAULT NULL ,
  PRIMARY KEY (`usr_id`) ,
  UNIQUE INDEX `usr_username_UNIQUE` (`usr_username` ASC) ,
  INDEX `is_deleted` (`is_deleted` ASC) ,
  INDEX `idx_firstname` (`usr_firstname` ASC) ,
  INDEX `idx_lastname` (`usr_lastname` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_user_application`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_user_application` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_user_application` (
  `app_id` CHAR(36) NOT NULL ,
  `usr_id` CHAR(36) NOT NULL ,
  `app_role_id` CHAR(36) NOT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT NULL ,
  `version` INT(11) NULL DEFAULT NULL ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  PRIMARY KEY (`app_id`, `usr_id`, `app_role_id`) ,
  INDEX `fk_krf_user_application_krf_user1_idx` (`usr_id` ASC) ,
  INDEX `fk_krf_user_application_krf_application_role1_idx` (`app_role_id` ASC) ,
  INDEX `fk_krf_user_application_krf_application1_idx` (`app_id` ASC) ,
  CONSTRAINT `fk_krf_user_application_krf_application1`
    FOREIGN KEY (`app_id` )
    REFERENCES `sog`.`krf_application` (`app_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_krf_user_application_krf_user1`
    FOREIGN KEY (`usr_id` )
    REFERENCES `sog`.`krf_user` (`usr_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_krf_user_application_krf_application_role1`
    FOREIGN KEY (`app_role_id` )
    REFERENCES `sog`.`krf_application_role` (`app_role_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_user_role`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_user_role` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_user_role` (
  `role_id` CHAR(36) NOT NULL ,
  `usr_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`role_id`, `usr_id`) ,
  INDEX `fk_krf_user_role_krf_user1_idx` (`usr_id` ASC) ,
  INDEX `fk_krf_user_role_krf_role1_idx` (`role_id` ASC) ,
  CONSTRAINT `fk_krf_user_role_krf_role1`
    FOREIGN KEY (`role_id` )
    REFERENCES `sog`.`krf_role` (`role_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_krf_user_role_krf_user1`
    FOREIGN KEY (`usr_id` )
    REFERENCES `sog`.`krf_user` (`usr_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`krf_user_settings`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`krf_user_settings` ;

CREATE  TABLE IF NOT EXISTS `sog`.`krf_user_settings` (
  `settings_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `user_timezone` VARCHAR(128) NULL ,
  `usr_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`settings_id`, `usr_id`) ,
  INDEX `fk_krf_user_settings_krf_user1_idx` (`usr_id` ASC) ,
  CONSTRAINT `fk_krf_user_settings_krf_user1`
    FOREIGN KEY (`usr_id` )
    REFERENCES `sog`.`krf_user` (`usr_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_actionable`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_actionable` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_actionable` (
  `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') 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 NULL DEFAULT b'0' ,
  `time_action_logged` INT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  PRIMARY KEY (`action_id`) ,
  INDEX `TYPE` (`action_type` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_keyholder_supervisor`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_keyholder_supervisor` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_keyholder_supervisor` (
  `user_id` CHAR(36) NOT NULL ,
  `group_id` INT(10) UNSIGNED NOT NULL ,
  PRIMARY KEY (`user_id`, `group_id`) ,
  INDEX `fk_glam_keyholder_supervisor_glam_keyholder_group1_idx` (`group_id` ASC) ,
  INDEX `fk_glam_keyholder_supervisor_glam_objholder1_idx` (`user_id` ASC) ,
  CONSTRAINT `fk_glam_keyholder_supervisor_glam_objholder1`
    FOREIGN KEY (`user_id` )
    REFERENCES `sog`.`glam_objholder` (`user_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_keyholder_supervisor_glam_keyholder_group1`
    FOREIGN KEY (`group_id` )
    REFERENCES `sog`.`glam_keyholder_group` (`group_id` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_object_image`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_object_image` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_object_image` (
  `img_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `img_name` VARCHAR(64) NOT NULL ,
  `img_location` VARCHAR(256) NULL ,
  `img_md5` CHAR(32) NULL ,
  `img_version` INT UNSIGNED NULL DEFAULT 0 ,
  `system_id` INT(11) NULL ,
  PRIMARY KEY (`img_id`) ,
  INDEX `fk_glam_access_object_image_glam_system_details1_idx` (`system_id` ASC) ,
  CONSTRAINT `fk_glam_access_object_image_glam_system_details1`
    FOREIGN KEY (`system_id` )
    REFERENCES `sog`.`glam_system_details` (`system_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_object_firmware`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_object_firmware` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_access_object_firmware` (
  `firmware_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `firmware_name` VARCHAR(64) NULL ,
  `firmware_internal_version` INT UNSIGNED NULL DEFAULT 0 ,
  `firmware_type` ENUM('UNKNOWN','KEY_2010','KEY_2012','KEY_BT_2012') NULL DEFAULT 'UNKNOWN' ,
  `firmware_md5` CHAR(32) NULL ,
  `firmware_location` VARCHAR(256) NULL ,
  `firmware_image` BLOB NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` DATETIME NULL DEFAULT NULL ,
  `system_id` INT(11) NULL ,
  `firmware_version` VARCHAR(16) NULL DEFAULT '1.0.0' ,
  `firmware_is_active` BIT NULL DEFAULT b'0' ,
  `firmware_release` DATETIME NULL ,
  `firmware_author` VARCHAR(128) NULL ,
  PRIMARY KEY (`firmware_id`) ,
  INDEX `fk_glam_access_object_firmware_glam_system_details1_idx` (`system_id` ASC) ,
  CONSTRAINT `fk_glam_access_object_firmware_glam_system_details1`
    FOREIGN KEY (`system_id` )
    REFERENCES `sog`.`glam_system_details` (`system_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_access_point`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_access_point` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_access_point` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT ,
  `access_point_id` CHAR(36) NOT NULL ,
  `access_point_serial_no` INT NOT NULL ,
  `access_point_status` ENUM('OPEN','CLOSED','UNKNOWN') NULL DEFAULT 'UNKNOWN' ,
  `access_point_com_status` ENUM('COMMISSIONED','UNCOMMISSIONED','DISCOVERED') NULL DEFAULT 'DISCOVERED' ,
  `access_point_description` VARCHAR(256) NULL DEFAULT NULL ,
  `access_point_comment` VARCHAR(1024) NULL DEFAULT NULL ,
  `access_point_safe_status` ENUM('BUSY','UNSAFE','SAFE') NULL DEFAULT 'SAFE' ,
  `access_point_is_owner` BIT(1) NULL DEFAULT b'1' COMMENT 'Indicates if this system \nis the owner of the lock.' ,
  `access_point_last_status_change` INT(10) UNSIGNED NULL DEFAULT '0' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `version` INT(11) NULL DEFAULT '0' ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `ap_replacement_serial_no` INT NULL DEFAULT NULL ,
  `in_lockdown` BIT NULL DEFAULT b'0' ,
  `access_point_rf_id` BIGINT NULL ,
  `access_point_location` POINT NULL DEFAULT NULL ,
  `access_point_rf_replacement` BIGINT NULL DEFAULT NULL ,
  `glam_access_pointcol` VARCHAR(45) NULL DEFAULT NULL ,
  `access_point_type` INT NULL DEFAULT 0 ,
  `ap_share_status` ENUM('NONE','SHARED_BY','SHARED_TO') NULL DEFAULT 'NONE' ,
  `ap_key_replaced_serial_no` INT NULL DEFAULT NULL ,
  `ap_key_replaced_latch` INT NULL DEFAULT NULL ,
  `his_action` ENUM('ADDED','UPDATED','DELETED','LOCK_REPLACED','LATCH_REPLACED','VALIDATED') NULL ,
  `ap_last_access_by` CHAR(36) NULL DEFAULT NULL ,
  `ap_movement_radius` FLOAT NULL DEFAULT 10 ,
  `ap_movement_last_pos` POINT NULL DEFAULT NULL ,
  `ap_movement_alarm_enabled` BIT NULL DEFAULT b'0' ,
  INDEX `is_deleted` (`is_deleted` ASC) ,
  PRIMARY KEY (`his_id`) )
ENGINE = InnoDB
AUTO_INCREMENT = 3724
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_access_object_key`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_access_object_key` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_access_object_key` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT ,
  `access_object_id` VARCHAR(36) NOT NULL ,
  `key_gsm_imei` VARCHAR(20) NULL DEFAULT NULL ,
  `key_sim_card_no` VARCHAR(20) NULL DEFAULT NULL ,
  `key_mode` ENUM('Static','Dynamic') NULL DEFAULT NULL ,
  `key_track_interval` VARCHAR(20) NULL DEFAULT NULL ,
  `key_box_no` VARCHAR(24) NULL DEFAULT NULL ,
  `key_sim_pin` VARCHAR(10) NULL DEFAULT '0000' ,
  `key_sim_puk` VARCHAR(24) NULL DEFAULT '00000000' ,
  `key_location` POINT NULL DEFAULT NULL ,
  `key_hw_version` VARCHAR(24) NULL DEFAULT NULL ,
  `key_sw_version` VARCHAR(20) NULL DEFAULT NULL ,
  `key_charger_version` VARCHAR(20) NULL DEFAULT NULL ,
  `key_server_address` VARCHAR(65) NULL DEFAULT NULL ,
  `key_server_port` VARCHAR(10) NULL DEFAULT NULL ,
  `key_apn` VARCHAR(24) NULL DEFAULT NULL ,
  `key_apn_username` VARCHAR(24) NULL DEFAULT NULL ,
  `key_apn_password` VARCHAR(24) NULL DEFAULT NULL ,
  `key_transaction_download_status` ENUM('PENDING','UPDATED') NULL DEFAULT NULL ,
  `key_tracker` ENUM('Y','N') NULL DEFAULT 'N' ,
  `key_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `version` INT(11) NULL DEFAULT '0' ,
  `his_action` ENUM('ADDED','UPDATED','DELETED','ASSIGNED','DEASSIGNED') NULL ,
  `user_id` CHAR(36) NULL ,
  `access_obj_serial_no` INT NULL ,
  PRIMARY KEY (`his_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_transaction`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_transaction` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_transaction` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT ,
  `transaction_id` CHAR(36) NOT NULL ,
  `transaction_date_start` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_date_end` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_auth_no` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_gps_radius` FLOAT NULL DEFAULT NULL ,
  `transaction_description` VARCHAR(200) NULL DEFAULT NULL ,
  `transaction_recursion` VARCHAR(20) NULL DEFAULT NULL ,
  `transaction_id_owner` CHAR(36) NULL DEFAULT NULL ,
  `transaction_authenticated_by` INT(10) UNSIGNED NULL DEFAULT NULL ,
  `transaction_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `transaction_job_card` VARCHAR(64) NULL DEFAULT NULL ,
  `transaction_location` POINT NULL DEFAULT NULL ,
  `transaction_type` ENUM('STATIC','MOBILE') NULL DEFAULT 'STATIC' ,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  INDEX `transaction_date_start` (`transaction_date_start` ASC) ,
  INDEX `transaction_date_end` (`transaction_date_end` ASC) ,
  PRIMARY KEY (`his_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_transaction_schedule`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_transaction_schedule` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_transaction_schedule` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT ,
  `access_point_id` CHAR(36) NOT NULL ,
  `transaction_id` CHAR(36) NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  `transaction_operation` ENUM('ACCESS','COMMISSION','ACCESS_COMMISSION','LOCK_REPLACEMENT','LATCH_REPLACEMENT') NULL DEFAULT 'ACCESS' ,
  `transaction_type` ENUM('STATIC','DYNAMIC') NULL DEFAULT 'STATIC' ,
  `trans_sched_is_owner` BIT(1) NULL DEFAULT b'1' ,
  `srm_schedule_confirmation_status` ENUM('PENDING','APPROVED','DECLINED') NULL DEFAULT 'PENDING' ,
  `srm_last_changed` DATETIME NULL DEFAULT NULL ,
  `srm_sh_id` VARCHAR(36) NULL DEFAULT NULL ,
  `srm_transsched_status_code` VARCHAR(64) NULL DEFAULT NULL ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `is_suspended` BIT NULL DEFAULT b'0' ,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL ,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  PRIMARY KEY (`his_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_supervisor_schedule`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_supervisor_schedule` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_supervisor_schedule` (
  `supervisor_schedule_id` INT NOT NULL AUTO_INCREMENT ,
  `supervisor_id` CHAR(36) NOT NULL ,
  `user_id` CHAR(36) NOT NULL ,
  `access_point_id` CHAR(36) NOT NULL ,
  `transasction_operation` ENUM('ACCESS','COMMISSION','ACCESS_COMMISSION','LOCK_REPLACEMENT','LATCH_REPLACEMENT') NULL DEFAULT 'ACCESS' ,
  `transaction_date_start` INT(10) UNSIGNED NULL ,
  `transaction_date_end` INT(10) UNSIGNED NULL ,
  `transaction_location` POINT NULL ,
  `transaction_gps_radius` FLOAT NULL ,
  `transaction_description` VARCHAR(200) NULL ,
  `transaction_type` ENUM('STATIC','MOBILE') NULL DEFAULT 'STATIC' ,
  `transaction_is_declined` BIT NULL DEFAULT b'0' ,
  `transaction_job_card` VARCHAR(64) NULL DEFAULT NULL ,
  PRIMARY KEY (`supervisor_schedule_id`) ,
  INDEX `TIME` (`transaction_date_start` ASC, `transaction_date_end` ASC) ,
  INDEX `SUPERVISOR` (`supervisor_id` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sog`.`glam_access_point_log_archive`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_access_point_log_archive` ;

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 ,
  `access_object_serial_no` INT 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 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;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_objholder`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_objholder` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_objholder` (
  `usr_id` CHAR(36) NOT NULL ,
  `usr_username` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_password` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_firstname` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_lastname` VARCHAR(128) NULL DEFAULT NULL ,
  `usr_contact_cell_no` VARCHAR(16) NULL DEFAULT NULL ,
  `usr_contact_work_no` VARCHAR(16) NULL DEFAULT NULL ,
  `usr_contact_email` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_employee_no` VARCHAR(64) NULL ,
  `usr_is_active` BIT(1) NULL DEFAULT b'1' ,
  `usr_system_role` VARCHAR(64) NULL DEFAULT 'SYS_USER' ,
  `usr_last_login` DATETIME NULL DEFAULT NULL ,
  `usr_api_key` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_timezone_id` VARCHAR(64) NULL DEFAULT NULL ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `version` INT(11) NULL DEFAULT NULL ,
  `objholder_active` BIT NULL DEFAULT b'1' ,
  `objholder_is_owner` BIT NULL DEFAULT b'1' ,
  `his_id` BIGINT NOT NULL AUTO_INCREMENT ,
  `his_action` ENUM('ADDED','UPDATED','DELETED','ASSIGN_SUPERVISOR','DEASSIGN_SUPERVISOR') NULL ,
  `is_supervisor` BIT NULL DEFAULT b'0' ,
  PRIMARY KEY (`his_id`) ,
  INDEX `is_deleted` (`is_deleted` ASC) ,
  INDEX `idx_firstname` (`usr_firstname` ASC) ,
  INDEX `idx_lastname` (`usr_lastname` ASC) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_systemuser`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_systemuser` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_systemuser` (
  `usr_id` CHAR(36) NOT NULL ,
  `usr_username` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_password` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_firstname` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_lastname` VARCHAR(128) NULL DEFAULT NULL ,
  `usr_contact_cell_no` VARCHAR(16) NULL DEFAULT NULL ,
  `usr_contact_work_no` VARCHAR(16) NULL DEFAULT NULL ,
  `usr_contact_email` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_employee_no` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_is_active` BIT(1) NULL DEFAULT b'1' ,
  `usr_system_role` VARCHAR(64) NULL DEFAULT 'SYS_USER' ,
  `usr_last_login` DATETIME NULL DEFAULT NULL ,
  `usr_api_key` VARCHAR(64) NULL DEFAULT NULL ,
  `usr_timezone_id` VARCHAR(64) NULL DEFAULT NULL ,
  `is_deleted` BIT(1) NULL DEFAULT b'0' ,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL ,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
  `version` INT(11) NULL DEFAULT NULL ,
  `his_id` BIGINT NOT NULL AUTO_INCREMENT ,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL ,
  INDEX `is_deleted` (`is_deleted` ASC) ,
  INDEX `idx_firstname` (`usr_firstname` ASC) ,
  INDEX `idx_lastname` (`usr_lastname` ASC) ,
  PRIMARY KEY (`his_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `sog`.`glam_his_systemuser_role`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_his_systemuser_role` ;

CREATE  TABLE IF NOT EXISTS `sog`.`glam_his_systemuser_role` (
  `his_id` BIGINT NOT NULL ,
  `role_id` CHAR(36) NOT NULL ,
  PRIMARY KEY (`his_id`, `role_id`) )
ENGINE = InnoDB;

USE `sog` ;
USE `sog`;

DELIMITER $$

USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`apInsert` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `sog`.`apInsert`
AFTER INSERT ON `sog`.`glam_access_point`
FOR EACH ROW
BEGIN 
    INSERT INTO glam_his_access_point
    SET 	access_point_id = NEW.access_point_id, 
		access_point_serial_no= NEW.access_point_serial_no, 
		access_point_status= NEW.access_point_status, 
		access_point_com_status= NEW.access_point_com_status, 
		access_point_description= NEW.access_point_description, 
		access_point_comment= NEW.access_point_comment, 
		access_point_safe_status= NEW.access_point_safe_status, 
		access_point_is_owner= NEW.access_point_is_owner, 
		access_point_last_status_change= NEW.access_point_last_status_change, 
		is_deleted= NEW.is_deleted, 
		version= NEW.version, 		
		last_changed_by= NEW.last_changed_by, 
		ap_replacement_serial_no= NEW.ap_replacement_serial_no, 
		in_lockdown= NEW.in_lockdown, 
		access_point_rf_id= NEW.access_point_rf_id, 
		access_point_location= NEW.access_point_location, 
		glam_access_pointcol= NEW.glam_access_pointcol, 
		access_point_type= NEW.access_point_type, 
    ap_share_status= NEW.ap_share_status, 
    ap_key_replaced_serial_no=NEW.ap_key_replaced_serial_no,
    ap_key_replaced_latch=NEW.ap_key_replaced_latch,
    ap_last_access_by=NEW.ap_last_access_by,
    ap_movement_radius=NEW.ap_movement_radius,
    ap_movement_last_pos=NEW.ap_movement_last_pos,
    ap_movement_alarm_enabled=NEW.ap_movement_alarm_enabled,
		his_action = 'ADDED';

END$$


USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`apDelete` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `apDelete`
BEFORE DELETE ON `sog`.`glam_access_point`
FOR EACH ROW
BEGIN 
    INSERT INTO glam_his_access_point
    SET 	access_point_id = OLD.access_point_id, 
		access_point_serial_no= OLD.access_point_serial_no, 
		access_point_status= OLD.access_point_status, 
		access_point_com_status= OLD.access_point_com_status, 
		access_point_description= OLD.access_point_description, 
		access_point_comment= OLD.access_point_comment, 
		access_point_safe_status= OLD.access_point_safe_status, 
		access_point_is_owner= OLD.access_point_is_owner, 
		access_point_last_status_change= OLD.access_point_last_status_change, 
		is_deleted= OLD.is_deleted, 
		version= OLD.version, 	
		last_changed_by= OLD.last_changed_by, 
		ap_replacement_serial_no= OLD.ap_replacement_serial_no, 
		in_lockdown= OLD.in_lockdown, 
		access_point_rf_id= OLD.access_point_rf_id, 
		access_point_location= OLD.access_point_location, 
		glam_access_pointcol= OLD.glam_access_pointcol, 
		access_point_type= OLD.access_point_type, 
    ap_share_status= OLD.ap_share_status, 
    ap_key_replaced_serial_no=OLD.ap_key_replaced_serial_no,
    ap_key_replaced_latch=OLD.ap_key_replaced_latch,
    ap_last_access_by=OLD.ap_last_access_by,
    ap_movement_radius=OLD.ap_movement_radius,
    ap_movement_last_pos=OLD.ap_movement_last_pos,
    ap_movement_alarm_enabled=OLD.ap_movement_alarm_enabled,
		his_action = 'DELETED';

END$$


DELIMITER ;

DELIMITER $$

USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`transInsert` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `transInsert`
AFTER INSERT ON `glam_transaction`
FOR EACH ROW
BEGIN 
    INSERT INTO glam_his_transaction
    SET 	 
	    transaction_id  = NEW.transaction_id, 
	    transaction_date_start = NEW.transaction_date_start, 
	    transaction_date_end = NEW.transaction_date_end, 
	    transaction_auth_no = NEW.transaction_auth_no, 
	    transaction_gps_radius = NEW.transaction_gps_radius, 
	    transaction_description = NEW.transaction_description, 
	    transaction_recursion = NEW.transaction_recursion, 
	    transaction_id_owner = NEW.transaction_id_owner, 
	    transaction_authenticated_by = NEW.transaction_authenticated_by, 
	    transaction_is_owner = NEW.transaction_is_owner,
	    last_changed_by = NEW.last_changed_by,
	    transaction_job_card = NEW.transaction_job_card,
	    transaction_location = NEW.transaction_location,
	    transaction_type = NEW.transaction_type,
	    his_action = 'ADDED';

END$$


USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`transUpdate` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `transUpdate`
AFTER UPDATE ON `glam_transaction`
FOR EACH ROW
BEGIN 
		INSERT INTO glam_his_transaction
		SET 	transaction_id  = NEW.transaction_id, 
			    transaction_date_start = NEW.transaction_date_start, 
			    transaction_date_end = NEW.transaction_date_end, 
			    transaction_auth_no = NEW.transaction_auth_no, 
			    transaction_gps_radius = NEW.transaction_gps_radius, 
			    transaction_description = NEW.transaction_description, 
			    transaction_recursion = NEW.transaction_recursion, 
			    transaction_id_owner = NEW.transaction_id_owner, 
			    transaction_authenticated_by = NEW.transaction_authenticated_by, 
			    transaction_is_owner = NEW.transaction_is_owner,
			    last_changed_by = NEW.last_changed_by,
			    transaction_job_card = NEW.transaction_job_card,
			    transaction_location = NEW.transaction_location,
			    transaction_type = NEW.transaction_type,
			his_action= 'UPDATED';
END$$


USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`transDelete` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `transDelete`
BEFORE DELETE ON `glam_transaction`
FOR EACH ROW
BEGIN 
   INSERT INTO glam_his_transaction
		SET 	
				transaction_id  = OLD.transaction_id, 
				transaction_date_start = OLD.transaction_date_start, 
			    transaction_date_end = OLD.transaction_date_end, 
			    transaction_auth_no = OLD.transaction_auth_no, 
			    transaction_gps_radius = OLD.transaction_gps_radius, 
			    transaction_description = OLD.transaction_description, 
			    transaction_recursion = OLD.transaction_recursion, 
			    transaction_id_owner = OLD.transaction_id_owner, 
			    transaction_authenticated_by = OLD.transaction_authenticated_by, 
			    transaction_is_owner = OLD.transaction_is_owner,
			    last_changed_by = OLD.last_changed_by,
			    transaction_job_card = OLD.transaction_job_card,
			    transaction_location = OLD.transaction_location,
			    transaction_type = OLD.transaction_type,
			his_action= 'DELETED';
END$$


DELIMITER ;

DELIMITER $$

USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`scheduleInsert` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `scheduleInsert`
AFTER INSERT ON `glam_transaction_schedule`
FOR EACH ROW
BEGIN 
    INSERT INTO glam_his_transaction_schedule
    SET 	 
	     access_point_id  = NEW.access_point_id,
	    transaction_id  = NEW.transaction_id,
	    user_id  = NEW.user_id,
	    transaction_operation  = NEW.transaction_operation,
	    transaction_type  = NEW.transaction_type,
	    trans_sched_is_owner  = NEW.trans_sched_is_owner,
	    srm_schedule_confirmation_status  = NEW.srm_schedule_confirmation_status,
	    srm_last_changed  = NEW.srm_last_changed,
	    srm_sh_id  = NEW.srm_sh_id,
	    srm_transsched_status_code  = NEW.srm_transsched_status_code,
	    last_changed_by  = NEW.last_changed_by ,
	    is_suspended  = NEW.is_suspended ,
	    his_action = 'ADDED';
	    
	   
	    

END$$


USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`scheduleUpdate` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `scheduleUpdate`
AFTER UPDATE ON `glam_transaction_schedule`
FOR EACH ROW
BEGIN 
		INSERT INTO glam_his_transaction_schedule
		SET 	 access_point_id  = NEW.access_point_id,
	    transaction_id  = NEW.transaction_id,
	    user_id  = NEW.user_id,
	    transaction_operation  = NEW.transaction_operation,
	    transaction_type  = NEW.transaction_type,
	    trans_sched_is_owner  = NEW.trans_sched_is_owner,
	    srm_schedule_confirmation_status  = NEW.srm_schedule_confirmation_status,
	    srm_last_changed  = NEW.srm_last_changed,
	    srm_sh_id  = NEW.srm_sh_id,
	    srm_transsched_status_code  = NEW.srm_transsched_status_code,
	    last_changed_by  = NEW.last_changed_by ,
	    is_suspended  = NEW.is_suspended ,
			his_action= 'UPDATED';
END$$


USE `sog`$$
DROP TRIGGER IF EXISTS `sog`.`scheduleDelete` $$
USE `sog`$$




CREATE
DEFINER=`root`@`localhost`
TRIGGER `scheduleDelete`
BEFORE DELETE ON `glam_transaction_schedule`
FOR EACH ROW
BEGIN 
   INSERT INTO glam_his_transaction_schedule
		SET 	
			    access_point_id  = OLD.access_point_id,
			    transaction_id  = OLD.transaction_id,
			    user_id  = OLD.user_id,
			    transaction_operation  = OLD.transaction_operation,
			    transaction_type  = OLD.transaction_type,
			    trans_sched_is_owner  = OLD.trans_sched_is_owner,
			    srm_schedule_confirmation_status  = OLD.srm_schedule_confirmation_status,
			    srm_last_changed  = OLD.srm_last_changed,
			    srm_sh_id  = OLD.srm_sh_id,
			    srm_transsched_status_code  = OLD.srm_transsched_status_code,
			    last_changed_by  = OLD.last_changed_by ,
			    is_suspended  = OLD.is_suspended ,
			his_action= 'DELETED';
END$$


DELIMITER ;


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

-- -----------------------------------------------------
-- Data for table `sog`.`glam_systemuser`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`glam_systemuser` (`user_id`, `user_group_access`, `is_deleted`, `version`, `last_changed_on`, `last_changed_by`) VALUES ('d0ae3b9f-28e3-4a33-81b9-83849bc17623', NULL, NULL, NULL, NULL, NULL);
INSERT INTO `sog`.`glam_systemuser` (`user_id`, `user_group_access`, `is_deleted`, `version`, `last_changed_on`, `last_changed_by`) VALUES ('3f6a7c17-4bbe-4305-9b5e-35275ba1ec49', NULL, NULL, NULL, NULL, NULL);

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`glam_notification`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (0, 'Key powered up', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (1, 'Uncomissioned lock discovered', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (2, 'Successful authorized unlocking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (3, 'Successful authorized locking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (4, 'Successful authorized late locking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (5, 'Failed authorized opening – lock in locked state', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (6, 'Failed authorized closing – lock in unlocked state', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (7, 'Failed authorized opening – lock in unknown state', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (8, 'Failed authorized closing – lock in unknown state', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (9, 'Unauthorized attempted unlocking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (10, 'Unauthorized attempted locking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (11, 'Successful commissioning of lock', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (12, 'Failed commissioning of lock', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (13, 'No RF tag found during unlocking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (14, 'No RF tag found during locking', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (15, 'Recheck of RF tag before closing failed', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (16, 'Duress alarm – keyholder panic', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (17, 'Tamper alarm – key enclosure opened', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (18, 'Possible latch replacement', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (19, 'Possible lock replacement', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (20, 'Latch replaced successfully', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (21, 'Lock replaced successfully', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (22, 'Lock comms error', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (23, 'New key discovered', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (24, 'Key login', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (25, 'Lock comms initialisation error', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (26, 'Lid discovered', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (27, 'Key - Transactions downloaded successfully', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (28, 'Key - Transactions download timeout', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (29, 'Key - Events uploaded successfully', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (30, 'Key - Events upload timeout', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (50, 'Database stopped', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (51, 'Database started', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (52, 'Webserver stopped', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (53, 'Webserver started', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (54, 'Glam stopped', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (55, 'Glam started', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (56, 'Geoserver stopped', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (57, 'Geoserver started', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (58, 'Unsafe Lock in expired schedule', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (59, 'Unsafe Lock now scheduled', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (31, 'Failed authorized opening – No GPS signal', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (32, 'Failed authorized closing – No GPS signal', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (33, 'Failed authorized opening – Radius to large', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (34, 'Failed authorized closing – Radius to large', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (35, 'Failed authorized opening – Key time invalid', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (36, 'Failed authorized opening – Key time invalid', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (49, 'Lock with replacement serial already exists.', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (48, 'Lock with replacement latch already exists.', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (47, 'Lock moved out of commissioned area.', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (46, 'Lock back in commissioned area.', NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`) VALUES (45, 'Lock safe area updated.', NULL);

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`krf_application`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`krf_application` (`app_id`, `app_name`, `app_description`, `app_version`, `app_location`) VALUES ('dfcc552b-62ef-11e2-a2e9-e8039a3b0793', 'Glam', 'Gridlock Access Management', '0.0.1', NULL);

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`krf_application_role`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('21251efa-62f0-11e2-a2e9-e8039a3b0793', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_NOC');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('99ec4e65-62f0-11e2-a2e9-e8039a3b0793', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_KEYHOLDER');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('9da344ad-62f0-11e2-a2e9-e8039a3b0793', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_SUPERVISOR');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('a17e1ea8-62f0-11e2-a2e9-e8039a3b0793', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_OPERATOR');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('e5ab8bf6-f784-4ebd-8f03-00d469d995ce', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_SRM');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('ff64ca77-85c0-4d1b-ba64-4f69eaa311e3', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_ADMIN');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('cba7cb18-dc35-4425-8045-4eba7913d7bc', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_DAEMON');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('5627e66e-de67-4338-8e3a-dcda2b312977', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_SRM_CLIENT');
INSERT INTO `sog`.`krf_application_role` (`app_role_id`, `app_id`, `last_changed_on`, `app_role_name`) VALUES ('d4fbc164-bac0-4315-aee6-617340fea023', 'dfcc552b-62ef-11e2-a2e9-e8039a3b0793', NULL, 'GLAM_AND');

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`krf_role`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`krf_role` (`role_id`, `role_name`) VALUES ('11251c1e-ad91-4bb5-8850-e2384f67dc8e', 'ROLE_ADMIN');
INSERT INTO `sog`.`krf_role` (`role_id`, `role_name`) VALUES ('a3538833-db11-4341-aa41-c6c7127beabf', 'ROLE_USER');
INSERT INTO `sog`.`krf_role` (`role_id`, `role_name`) VALUES ('ad73c62a-f0e1-4035-8a91-ff3feab131c9', 'ROLE_SERVICE');

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`krf_user`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`krf_user` (`usr_id`, `usr_username`, `usr_password`, `usr_firstname`, `usr_lastname`, `usr_contact_cell_no`, `usr_contact_work_no`, `usr_contact_email`, `usr_employee_no`, `usr_is_active`, `usr_system_role`, `usr_last_login`, `usr_api_key`, `usr_timezone_id`, `is_deleted`, `last_changed_by`, `last_changed_on`, `version`) VALUES ('d0ae3b9f-28e3-4a33-81b9-83849bc17623', 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Admin', 'Admin', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL);
INSERT INTO `sog`.`krf_user` (`usr_id`, `usr_username`, `usr_password`, `usr_firstname`, `usr_lastname`, `usr_contact_cell_no`, `usr_contact_work_no`, `usr_contact_email`, `usr_employee_no`, `usr_is_active`, `usr_system_role`, `usr_last_login`, `usr_api_key`, `usr_timezone_id`, `is_deleted`, `last_changed_by`, `last_changed_on`, `version`) VALUES ('3f6a7c17-4bbe-4305-9b5e-35275ba1ec49', 'user', 'ee11cbb19052e40b07aac0ca060c23ee', 'User', 'User', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL);
INSERT INTO `sog`.`krf_user` (`usr_id`, `usr_username`, `usr_password`, `usr_firstname`, `usr_lastname`, `usr_contact_cell_no`, `usr_contact_work_no`, `usr_contact_email`, `usr_employee_no`, `usr_is_active`, `usr_system_role`, `usr_last_login`, `usr_api_key`, `usr_timezone_id`, `is_deleted`, `last_changed_by`, `last_changed_on`, `version`) VALUES ('f7cd20ad-97fe-48ff-a175-3d16cba90894', 'glamd', '0b11faed1796a54d62696fa07f756820', 'Glamd', 'Glamd', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL);
INSERT INTO `sog`.`krf_user` (`usr_id`, `usr_username`, `usr_password`, `usr_firstname`, `usr_lastname`, `usr_contact_cell_no`, `usr_contact_work_no`, `usr_contact_email`, `usr_employee_no`, `usr_is_active`, `usr_system_role`, `usr_last_login`, `usr_api_key`, `usr_timezone_id`, `is_deleted`, `last_changed_by`, `last_changed_on`, `version`) VALUES ('424bc188-d2f0-4b0c-be07-654fe1b19af6', 'srmd', '75ee1e68c8a9fa0ae79cdfd077f00059', 'Srmd', 'Srmd', NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL);

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`krf_user_application`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`krf_user_application` (`app_id`, `usr_id`, `app_role_id`, `last_changed_by`, `last_changed_on`, `version`, `is_deleted`) VALUES ('dfcc552b-62ef-11e2-a2e9-e8039a3b0793', '3f6a7c17-4bbe-4305-9b5e-35275ba1ec49', '21251efa-62f0-11e2-a2e9-e8039a3b0793', NULL, NULL, NULL, NULL);
INSERT INTO `sog`.`krf_user_application` (`app_id`, `usr_id`, `app_role_id`, `last_changed_by`, `last_changed_on`, `version`, `is_deleted`) VALUES ('dfcc552b-62ef-11e2-a2e9-e8039a3b0793', 'd0ae3b9f-28e3-4a33-81b9-83849bc17623', 'ff64ca77-85c0-4d1b-ba64-4f69eaa311e3', NULL, NULL, NULL, NULL);
INSERT INTO `sog`.`krf_user_application` (`app_id`, `usr_id`, `app_role_id`, `last_changed_by`, `last_changed_on`, `version`, `is_deleted`) VALUES ('dfcc552b-62ef-11e2-a2e9-e8039a3b0793', 'f7cd20ad-97fe-48ff-a175-3d16cba90894', 'cba7cb18-dc35-4425-8045-4eba7913d7bc', NULL, NULL, NULL, NULL);
INSERT INTO `sog`.`krf_user_application` (`app_id`, `usr_id`, `app_role_id`, `last_changed_by`, `last_changed_on`, `version`, `is_deleted`) VALUES ('dfcc552b-62ef-11e2-a2e9-e8039a3b0793', '424bc188-d2f0-4b0c-be07-654fe1b19af6', 'e5ab8bf6-f784-4ebd-8f03-00d469d995ce', NULL, NULL, NULL, NULL);

COMMIT;

-- -----------------------------------------------------
-- Data for table `sog`.`krf_user_role`
-- -----------------------------------------------------
START TRANSACTION;
USE `sog`;
INSERT INTO `sog`.`krf_user_role` (`role_id`, `usr_id`) VALUES ('11251c1e-ad91-4bb5-8850-e2384f67dc8e', 'd0ae3b9f-28e3-4a33-81b9-83849bc17623');
INSERT INTO `sog`.`krf_user_role` (`role_id`, `usr_id`) VALUES ('a3538833-db11-4341-aa41-c6c7127beabf', '3f6a7c17-4bbe-4305-9b5e-35275ba1ec49');
INSERT INTO `sog`.`krf_user_role` (`role_id`, `usr_id`) VALUES ('ad73c62a-f0e1-4035-8a91-ff3feab131c9', 'f7cd20ad-97fe-48ff-a175-3d16cba90894');
INSERT INTO `sog`.`krf_user_role` (`role_id`, `usr_id`) VALUES ('ad73c62a-f0e1-4035-8a91-ff3feab131c9', '424bc188-d2f0-4b0c-be07-654fe1b19af6');

COMMIT;
