-- MySQL Script generated by MySQL Workbench
-- 04/09/18 13:36:30
-- Model: SoG    Version: 1.3.17
-- MySQL Workbench Forward Engineering

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

-- -----------------------------------------------------
-- Schema sog
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `sog` ;

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

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

CREATE TABLE IF NOT EXISTS `sog`.`glam_point` (
  `point_id` CHAR(36) NOT NULL,
  `point_location` POINT NULL,
  `point_desc` VARCHAR(255) NULL,
  `point_radius` FLOAT NULL,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `location_required` BIT NULL DEFAULT b'1',
  `grace_period_start` INT NULL DEFAULT 0 COMMENT 'Stores grace period in minutes. This will be subtracted from the starting date.',
  `grace_period_end` INT NULL DEFAULT 0 COMMENT 'Stores grace period in minutes. This will be added to the end date.',
  `gsm_coverage` ENUM('UNKNOWN','POOR','GOOD') NULL DEFAULT 'GOOD',
  `his_id` BIGINT NULL DEFAULT NULL,
  `is_deleted` BIT NULL DEFAULT b'0',
  PRIMARY KEY (`point_id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- 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',
  `point_id` CHAR(36) NULL DEFAULT NULL,
  PRIMARY KEY (`domain_id`),
  INDEX `fk_glam_domain_glam_domain1_idx` (`parent_domain_id` ASC),
  INDEX `fk_glam_domain_glam_point1_idx` (`point_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,
  CONSTRAINT `fk_glam_domain_glam_point1`
    FOREIGN KEY (`point_id`)
    REFERENCES `sog`.`glam_point` (`point_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE)
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' NULL DEFAULT NULL,
  `group_description` VARCHAR(200) CHARACTER SET 'utf8' 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',
  `gsm_coverage` ENUM('UNKNOWN','POOR','GOOD') NULL DEFAULT 'GOOD',
  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,
  `notification_colour` INT 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,
  `asset_id` INT NULL DEFAULT NULL,
  PRIMARY KEY (`access_point_log_id`),
  INDEX `fk_key_notification_idx` (`log_notification_id` ASC),
  INDEX `key_log_time` (`key_log_time` ASC),
  INDEX `idx_ao_id` (`access_object_id` ASC),
  INDEX `idx_ap_id` (`access_point_id` ASC),
  INDEX `idx_user_id` (`keyholder_id` ASC),
  UNIQUE INDEX `unique_idx` (`key_log_time` ASC, `log_notification_id` ASC, `access_object_id` ASC),
  CONSTRAINT `fk_key_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_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_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',
  `tag_id` INT UNSIGNED NULL DEFAULT NULL,
  PRIMARY KEY (`sh_id`),
  INDEX `is_deleted` (`is_deleted` ASC),
  INDEX `fk_glam_srm_stakeholder_glam_tag1_idx` (`tag_id` ASC),
  CONSTRAINT `fk_glam_srm_stakeholder_glam_tag1`
    FOREIGN KEY (`tag_id`)
    REFERENCES `sog`.`glam_tag` (`tag_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE)
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_group`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `sog`.`glam_transaction_group` ;

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


-- -----------------------------------------------------
-- 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',
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `transaction_group_id` CHAR(36) NULL DEFAULT NULL,
  `point_id` CHAR(36) NULL DEFAULT NULL,
  PRIMARY KEY (`transaction_id`),
  INDEX `transaction_date_start` (`transaction_date_start` ASC),
  INDEX `transaction_date_end` (`transaction_date_end` ASC),
  INDEX `fk_glam_transaction_glam_transaction_group1_idx` (`transaction_group_id` ASC),
  INDEX `fk_glam_transaction_glam_point1_idx` (`point_id` ASC),
  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,
  CONSTRAINT `fk_glam_transaction_glam_point1`
    FOREIGN KEY (`point_id`)
    REFERENCES `sog`.`glam_point` (`point_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE)
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,
  `system_allow_no_start_date` BIT NULL DEFAULT b'0',
  `system_allow_no_end_date` BIT NULL DEFAULT b'0',
  `system_allow_no_coordinates` BIT NULL DEFAULT b'0',
  `system_srm_enabled` BIT NULL DEFAULT b'0',
  `system_limit_keys` BIT NULL DEFAULT b'0',
  `system_lid_tracking_enabled` BIT NULL DEFAULT b'0',
  `system_acl_enabled` BIT NULL DEFAULT b'0',
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL,
  `system_main_colour` INT NULL DEFAULT 0x2E85F1,
  `system_sub_colour` INT NULL DEFAULT 0x79CDCD,
  `system_key_sec_ip_address` VARCHAR(64) NULL,
  `system_key_sec_port` INT NULL,
  `system_audible_alarm_enabled` BIT NULL DEFAULT b'0',
  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,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_dynamic` BIT NULL DEFAULT b'0',
  `trans_confirmed` BIT NULL DEFAULT b'0',
  `trans_confirmed_on` DATETIME NULL,
  `trans_confirmed_by` CHAR(36) 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),
  INDEX `fk_objholder_idx` (`user_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,
  CONSTRAINT `fk_objholder`
    FOREIGN KEY (`user_id`)
    REFERENCES `sog`.`glam_objholder` (`user_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' 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',
  `key_operation_mode` ENUM('AUTOMATIC','MANUAL') NULL DEFAULT 'AUTOMATIC',
  `key_transactions_limited` BIT NULL DEFAULT b'0',
  `key_transaction_limit` INT NULL DEFAULT 0,
  `key_allow_dynamic_transactions` BIT NULL DEFAULT b'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_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', 'SRM_OFFLINE', 'SRM_INACTIVE', 'ASSET_DISCOVERED') 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,
  `asset_id` INT 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','RESTORED') 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',
  `gsm_coverage` ENUM('UNKNOWN','POOR','GOOD') NULL DEFAULT 'GOOD',
  INDEX `is_deleted` (`is_deleted` ASC),
  PRIMARY KEY (`his_id`),
  INDEX `idx_lock_rf` (`access_point_rf_id` ASC),
  INDEX `idx_his_type_lock` (`his_action` ASC),
  INDEX `idx_access_point_id` (`access_point_id` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC))
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,
  `key_operation_mode` ENUM('AUTOMATIC','MANUAL') NULL DEFAULT 'AUTOMATIC',
  `key_transactions_limited` BIT NULL DEFAULT b'0',
  `key_transaction_limit` INT NULL DEFAULT 0,
  `key_allow_dynamic_transactions` BIT NULL DEFAULT b'0',
  PRIMARY KEY (`his_id`),
  INDEX `idx_key_serial` (`access_obj_serial_no` ASC),
  INDEX `idx_his_type_key` (`his_action` ASC))
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,
  `transaction_group_id` CHAR(36) NULL DEFAULT NULL,
  `point_id` CHAR(36) NULL DEFAULT NULL,
  INDEX `transaction_date_start` (`transaction_date_start` ASC),
  INDEX `transaction_date_end` (`transaction_date_end` ASC),
  PRIMARY KEY (`his_id`),
  INDEX `idx_his_type_trans` (`his_action` ASC))
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,
  `is_dynamic` BIT NULL DEFAULT b'0',
  `trans_confirmed` BIT NULL DEFAULT b'0',
  `trans_confirmed_on` DATETIME NULL DEFAULT NULL,
  `trans_confirmed_by` CHAR(36) NULL DEFAULT NULL,
  PRIMARY KEY (`his_id`),
  INDEX `idx_his_type_schedule` (`his_action` ASC))
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),
  INDEX `idx_his_type_objholder` (`his_action` 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,
  `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`),
  INDEX `idx_his_type_systemuser` (`his_action` ASC))
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;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_actionable` (
  `his_id` CHAR(36) NOT NULL,
  `action_id` CHAR(36) NOT NULL,
  `action_type` ENUM('DISCOVERED_KEY','DISCOVERED_LOCK','LOCK_UNSAFE','LATCH_REPLACEMENT','LOCK_REPLACEMENT','PENDING_SCHEDULE','PENDING_SRM','UNSAFE_LOCK','SHARED_LOCK','SRM_FAULT','LOCK_OUT_ZONE','SRM_OFFLINE','SRM_INACTIVE') NULL,
  `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,
  `his_action` ENUM('ADDED','UPDATED','DELETED','ACKOWLEDGED','CLEARED','ACK_CLEAR') NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`his_id`),
  INDEX `TYPE` (`action_type` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


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

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


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

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


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_transaction_group` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `trans_group_id` CHAR(36) NOT NULL,
  `trans_group_name` VARCHAR(45) NULL,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL,
  PRIMARY KEY (`his_id`))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_dynamic_schedule` (
  `dyn_schedule_id` CHAR(36) NOT NULL,
  `dyn_point_id` CHAR(36) NULL DEFAULT NULL,
  `dyn_domain_id` INT UNSIGNED NULL DEFAULT NULL,
  `dyn_oh_tag_id` INT UNSIGNED NULL DEFAULT NULL,
  `dyn_ap_tag_id` INT UNSIGNED NULL DEFAULT NULL,
  `dyn_schedule_operation` ENUM('ACCESS','ACCESS_COMMISSION') NULL DEFAULT 'ACCESS',
  `dyn_transaction_start` INT NULL DEFAULT NULL,
  `dyn_transaction_end` INT NULL DEFAULT NULL,
  `dyn_transaction_radius` FLOAT NULL DEFAULT NULL,
  `dyn_date_recursion` VARCHAR(128) NULL DEFAULT NULL,
  `dyn_transaction_location` POINT NULL DEFAULT NULL,
  `dyn_domain_perspective` ENUM('AP','OH','BOTH') NULL DEFAULT 'AP',
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `dyn_schedule_description` VARCHAR(64) NULL DEFAULT NULL,
  `dyn_is_suspended` BIT NULL DEFAULT b'0',
  PRIMARY KEY (`dyn_schedule_id`),
  INDEX `fk_glam_dynamic_schedule_glam_point1_idx` (`dyn_point_id` ASC),
  INDEX `fk_glam_dynamic_schedule_glam_domain1_idx` (`dyn_domain_id` ASC),
  INDEX `fk_glam_dynamic_schedule_glam_tag1_idx` (`dyn_oh_tag_id` ASC),
  INDEX `fk_glam_dynamic_schedule_glam_tag2_idx` (`dyn_ap_tag_id` ASC),
  INDEX `fk_glam_dynamic_schedule_glam_start_date_idx` (`dyn_transaction_start` ASC),
  INDEX `fk_glam_dynamic_schedule_glam_end_date_idx` (`dyn_transaction_end` ASC),
  CONSTRAINT `fk_glam_dynamic_schedule_glam_point1`
    FOREIGN KEY (`dyn_point_id`)
    REFERENCES `sog`.`glam_point` (`point_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_dynamic_schedule_glam_domain1`
    FOREIGN KEY (`dyn_domain_id`)
    REFERENCES `sog`.`glam_domain` (`domain_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_dynamic_schedule_glam_tag1`
    FOREIGN KEY (`dyn_oh_tag_id`)
    REFERENCES `sog`.`glam_tag` (`tag_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_dynamic_schedule_glam_tag2`
    FOREIGN KEY (`dyn_ap_tag_id`)
    REFERENCES `sog`.`glam_tag` (`tag_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_report` (
  `report_id` INT NOT NULL AUTO_INCREMENT,
  `report_name` VARCHAR(64) NOT NULL,
  `report_description` VARCHAR(256) NULL,
  `report_url` VARCHAR(256) NULL DEFAULT 'report/glam/lock_status.rptdesign',
  `report_params` VARCHAR(1024) NULL,
  PRIMARY KEY (`report_id`),
  UNIQUE INDEX `report_name_UNIQUE` (`report_name` ASC))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_viewable_report` (
  `glam_report_report_id` INT NOT NULL,
  `app_role_id` CHAR(36) NULL,
  PRIMARY KEY (`glam_report_report_id`),
  INDEX `fk_krf_application_role_idx` (`app_role_id` ASC),
  CONSTRAINT `fk_glam_viewable_report_glam_report1`
    FOREIGN KEY (`glam_report_report_id`)
    REFERENCES `sog`.`glam_report` (`report_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_krf_application_role`
    FOREIGN KEY (`app_role_id`)
    REFERENCES `sog`.`krf_application_role` (`app_role_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_report_mailer` (
  `mailer_id` INT NOT NULL AUTO_INCREMENT,
  `report_id` INT NULL,
  `user_id` CHAR(36) NULL,
  `rm_start_datetime` INT NULL,
  `rm_end_datetime` INT NULL,
  `rm_params` VARCHAR(1024) NULL DEFAULT NULL,
  `rm_mail_at` VARCHAR(128) NULL,
  PRIMARY KEY (`mailer_id`),
  INDEX `fk_report_mailer_report_idx` (`report_id` ASC),
  INDEX `fk_report_mailer_user_idx` (`user_id` ASC),
  CONSTRAINT `fk_report_mailer_report`
    FOREIGN KEY (`report_id`)
    REFERENCES `sog`.`glam_report` (`report_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_report_mailer_user`
    FOREIGN KEY (`user_id`)
    REFERENCES `sog`.`glam_systemuser` (`user_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_dynamic_schedule` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `dyn_schedule_id` CHAR(36) NULL,
  `dyn_point_id` CHAR(36) NULL DEFAULT NULL,
  `dyn_domain_id` INT NULL DEFAULT NULL,
  `dyn_oh_tag_id` INT NULL DEFAULT NULL,
  `dyn_ap_tag_id` INT NULL DEFAULT NULL,
  `dyn_schedule_operation` ENUM('ACCESS','ACCESS_COMMISSION') NULL DEFAULT 'ACCESS',
  `dyn_transaction_start` INT NULL DEFAULT NULL,
  `dyn_transaction_end` INT NULL DEFAULT NULL,
  `dyn_transaction_radius` FLOAT NULL DEFAULT NULL,
  `dyn_date_recursion` VARCHAR(128) NULL DEFAULT NULL,
  `dyn_transaction_location` POINT NULL DEFAULT NULL,
  `dyn_domain_perspective` ENUM('AP','OH','BOTH') NULL DEFAULT 'AP',
  `his_action` ENUM('ADDED','UPDATED','DELETED','SUSPEND','UNSUSPEND') NULL DEFAULT 'ADDED',
  `last_changed_by` CHAR(36) NULL DEFAULT NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `dyn_schedule_description` VARCHAR(64) NULL DEFAULT NULL,
  `dyn_is_suspended` BIT NULL DEFAULT b'0',
  PRIMARY KEY (`his_id`),
  INDEX `original_pk` (`dyn_schedule_id` ASC),
  INDEX `his_action` (`his_action` ASC))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_dyn_sched_oh` (
  `dyn_schedule_id` CHAR(36) NOT NULL,
  `user_id` CHAR(36) NOT NULL,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  PRIMARY KEY (`dyn_schedule_id`, `user_id`),
  INDEX `fk_glam_dyn_sched_oh_glam_objholder1_idx` (`user_id` ASC),
  CONSTRAINT `fk_glam_dyn_sched_oh_glam_dynamic_schedule1`
    FOREIGN KEY (`dyn_schedule_id`)
    REFERENCES `sog`.`glam_dynamic_schedule` (`dyn_schedule_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_dyn_sched_oh_glam_objholder1`
    FOREIGN KEY (`user_id`)
    REFERENCES `sog`.`glam_objholder` (`user_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_dyn_sched_ap` (
  `dyn_schedule_id` CHAR(36) NOT NULL,
  `access_point_id` CHAR(36) NOT NULL,
  `last_changed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  PRIMARY KEY (`dyn_schedule_id`, `access_point_id`),
  INDEX `fk_glam_dyn_sched_ap_glam_access_point1_idx` (`access_point_id` ASC),
  CONSTRAINT `fk_glam_dyn_sched_ap_glam_dynamic_schedule1`
    FOREIGN KEY (`dyn_schedule_id`)
    REFERENCES `sog`.`glam_dynamic_schedule` (`dyn_schedule_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_dyn_sched_ap_glam_access_point1`
    FOREIGN KEY (`access_point_id`)
    REFERENCES `sog`.`glam_access_point` (`access_point_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_dyn_sched_oh` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `dyn_schedule_id` CHAR(36) NULL,
  `user_id` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL DEFAULT 'ADDED',
  PRIMARY KEY (`his_id`))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_dyn_sched_ap` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `dyn_schedule_id` CHAR(36) NULL,
  `access_point_id` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL DEFAULT 'ADDED',
  PRIMARY KEY (`his_id`))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_ext_exam_center` (
  `point_id` CHAR(36) NOT NULL,
  `center_address` VARCHAR(256) NULL,
  `center_tel` VARCHAR(16) NULL,
  `center_abbreviation` VARCHAR(16) NULL,
  `center_timezone` VARCHAR(128) NULL DEFAULT NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` BIT NULL DEFAULT b'0',
  `his_id` BIGINT NULL,
  `center_email` VARCHAR(64) NULL,
  PRIMARY KEY (`point_id`),
  INDEX `fk_glam_ext_exam_center_glam_point1_idx` (`point_id` ASC),
  CONSTRAINT `fk_glam_ext_exam_center_glam_point1`
    FOREIGN KEY (`point_id`)
    REFERENCES `sog`.`glam_point` (`point_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_ext_exam_timetable` (
  `table_id` CHAR(36) NOT NULL,
  `table_start_time` INT NULL,
  `table_end_time` INT NULL,
  `table_subject` VARCHAR(128) NULL,
  `table_abbreviation` VARCHAR(16) NULL,
  `table_group_id` CHAR(36) NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `is_deleted` BIT NULL DEFAULT b'0',
  `his_id` BIGINT NULL,
  PRIMARY KEY (`table_id`))
ENGINE = InnoDB;


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

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


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_ext_exam_schedule_ap` (
  `access_point_id` CHAR(36) NOT NULL,
  `exam_sched_id` INT NOT NULL,
  `access_point_rf_id` BIGINT NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `bag_collected` BIT NULL DEFAULT b'0',
  `bag_collected_on` DATETIME NULL DEFAULT NULL,
  `bag_collected_by` CHAR(36) NULL DEFAULT NULL,
  `bag_delivered` BIT NULL DEFAULT b'0',
  `bag_delivered_on` DATETIME NULL DEFAULT NULL,
  `bag_delivered_by` CHAR(36) NULL DEFAULT NULL,
  INDEX `fk_glam_ext_exam_schedule_lock_glam_access_point1_idx` (`access_point_id` ASC),
  INDEX `fk_glam_ext_exam_schedule_lock_glam_ext_exam_schedule1_idx` (`exam_sched_id` ASC),
  PRIMARY KEY (`access_point_id`, `exam_sched_id`),
  CONSTRAINT `fk_glam_ext_exam_schedule_lock_glam_access_point1`
    FOREIGN KEY (`access_point_id`)
    REFERENCES `sog`.`glam_access_point` (`access_point_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ext_exam_schedule_lock_glam_ext_exam_schedule1`
    FOREIGN KEY (`exam_sched_id`)
    REFERENCES `sog`.`glam_ext_exam_schedule` (`exam_sched_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_ext_exam_schedule_oh` (
  `exam_sched_id` INT NOT NULL,
  `objholder_id` CHAR(36) NOT NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX `fk_glam_ext_exam_schedule_objholder_glam_ext_exam_schedule1_idx` (`exam_sched_id` ASC),
  INDEX `fk_glam_ext_exam_schedule_objholder_glam_objholder1_idx` (`objholder_id` ASC),
  PRIMARY KEY (`exam_sched_id`, `objholder_id`),
  CONSTRAINT `fk_glam_ext_exam_schedule_objholder_glam_ext_exam_schedule1`
    FOREIGN KEY (`exam_sched_id`)
    REFERENCES `sog`.`glam_ext_exam_schedule` (`exam_sched_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ext_exam_schedule_objholder_glam_objholder1`
    FOREIGN KEY (`objholder_id`)
    REFERENCES `sog`.`glam_objholder` (`user_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_point` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `point_id` CHAR(36) NOT NULL,
  `point_desc` VARCHAR(255) NULL,
  `point_radius` FLOAT NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `location_required` BIT NULL,
  `grace_period_start` INT NULL,
  `grace_period_end` INT NULL,
  `gsm_coverage` ENUM('UNKNOWN','POOR','GOOD') NULL,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL,
  `is_deleted` BIT NULL DEFAULT b'0',
  `point_location` POINT NULL,
  PRIMARY KEY (`his_id`),
  INDEX `idx_point_id` (`point_id` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC),
  INDEX `idx_his_action` (`his_action` ASC))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_ext_exam_center` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `point_id` CHAR(36) NOT NULL,
  `center_address` VARCHAR(256) NULL,
  `center_tel` VARCHAR(16) NULL,
  `center_abbreviation` VARCHAR(8) NULL,
  `center_timezone` VARCHAR(128) NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL,
  `point_his_id` BIGINT NOT NULL,
  PRIMARY KEY (`his_id`),
  INDEX `fk_glam_his_ext_exam_center_glam_his_point1_idx` (`point_his_id` ASC),
  INDEX `idx_point_id` (`point_id` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC),
  CONSTRAINT `fk_glam_his_ext_exam_center_glam_his_point1`
    FOREIGN KEY (`point_his_id`)
    REFERENCES `sog`.`glam_his_point` (`his_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_ext_exam_timetable` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `table_id` CHAR(36) NOT NULL,
  `table_start_time` INT NULL,
  `table_end_time` INT NULL,
  `table_subject` VARCHAR(128) NULL,
  `table_abbreviation` VARCHAR(8) NULL,
  `table_group_id` CHAR(36) NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `his_action` ENUM('ADDED','UPDATED','DELETED','GENERATED','CLEARED') NULL,
  PRIMARY KEY (`his_id`),
  INDEX `idx_start_end_time` (`table_start_time` ASC, `table_end_time` ASC),
  INDEX `idx_table_id` (`table_id` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC),
  INDEX `idx_his_action` (`his_action` ASC))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_ext_exam_schedule` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `exam_sched_id` INT NOT NULL,
  `exam_center_his_id` BIGINT NOT NULL,
  `timetable_his_id` BIGINT NOT NULL,
  `sched_comment` VARCHAR(256) NULL,
  `objholder_id` CHAR(36) NULL,
  `sched_status` ENUM('UNKNOWN','PENDING','READY','CREATED','INVALID_OH','INVALID_AP','DELETED') NULL,
  `last_changed_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL,
  PRIMARY KEY (`his_id`),
  INDEX `fk_glam_his_ext_exam_schedule_glam_his_ext_exam_center1_idx` (`exam_center_his_id` ASC),
  INDEX `fk_glam_his_ext_exam_schedule_glam_his_ext_exam_timetable1_idx` (`timetable_his_id` ASC),
  INDEX `idx_his_action` (`his_action` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC),
  CONSTRAINT `fk_glam_his_ext_exam_schedule_glam_his_ext_exam_center1`
    FOREIGN KEY (`exam_center_his_id`)
    REFERENCES `sog`.`glam_his_ext_exam_center` (`his_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_his_ext_exam_schedule_glam_his_ext_exam_timetable1`
    FOREIGN KEY (`timetable_his_id`)
    REFERENCES `sog`.`glam_his_ext_exam_timetable` (`his_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_ext_exam_schedule_ap` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `exam_schedule_his_id` BIGINT NOT NULL,
  `access_point_id` CHAR(36) NOT NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL,
  `bag_collected` BIT NULL,
  `bag_collected_on` DATETIME NULL DEFAULT NULL,
  `bag_collected_by` CHAR(36) NULL DEFAULT NULL,
  `bag_delivered` BIT NULL DEFAULT b'0',
  `bag_delivered_on` DATETIME NULL DEFAULT NULL,
  `bag_delivered_by` CHAR(36) NULL DEFAULT NULL,
  INDEX `fk_glam_his_ext_exam_schedule_ap_glam_his_ext_exam_schedule_idx` (`exam_schedule_his_id` ASC),
  INDEX `idx_access_point` (`access_point_id` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC),
  PRIMARY KEY (`his_id`),
  CONSTRAINT `fk_glam_his_ext_exam_schedule_ap_glam_his_ext_exam_schedule1`
    FOREIGN KEY (`exam_schedule_his_id`)
    REFERENCES `sog`.`glam_his_ext_exam_schedule` (`his_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_his_ext_exam_schedule_oh` (
  `his_id` BIGINT NOT NULL AUTO_INCREMENT,
  `exam_schedule_his_id` BIGINT NOT NULL,
  `objholder_id` CHAR(36) NOT NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `his_action` ENUM('ADDED','UPDATED','DELETED') NULL,
  INDEX `fk_glam_his_ext_exam_schedule_oh_glam_his_ext_exam_schedule_idx` (`exam_schedule_his_id` ASC),
  INDEX `idx_objholder_id` (`objholder_id` ASC),
  INDEX `idx_last_changed_on` (`last_changed_on` ASC),
  PRIMARY KEY (`his_id`),
  CONSTRAINT `fk_glam_his_ext_exam_schedule_oh_glam_his_ext_exam_schedule1`
    FOREIGN KEY (`exam_schedule_his_id`)
    REFERENCES `sog`.`glam_his_ext_exam_schedule` (`his_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_ao_schedule` (
  `id` CHAR(36) NOT NULL,
  `access_object_id` CHAR(36) NOT NULL,
  `access_point_id` CHAR(36) NULL,
  `user_id` CHAR(36) NULL,
  `transaction_id` CHAR(36) NULL,
  `download_status` ENUM('UNKOWN', 'NEW', 'UPDATED', 'PENDING', 'OLD', 'CONFIRMED') NULL DEFAULT 'NEW',
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `transaction_diff` VARCHAR(128) NULL,
  `unsafe_schedule` BIT NULL DEFAULT b'0',
  `transaction_diff_new` VARCHAR(128) NULL,
  `trans_start` INT NULL,
  `trans_end` INT NULL,
  `trans_longitude` FLOAT NULL,
  `trans_latitude` FLOAT NULL,
  `trans_radius` FLOAT NULL,
  `trans_operation` ENUM('ACCESS', 'COMMISSION', 'ACCESS_COMMISSION', 'LOCK_REPLACEMENT', 'LATCH_REPLACEMENT') NULL,
  `trans_ap_serial` INT NULL DEFAULT NULL,
  `trans_ap_rf_id` MEDIUMTEXT NULL DEFAULT NULL,
  `transaction_diff_blob` BLOB NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_glam_ao_schedules_glam_access_object_key1_idx` (`access_object_id` ASC),
  INDEX `fk_glam_ao_schedule_glam_access_point1_idx` (`access_point_id` ASC),
  INDEX `fk_glam_ao_schedule_glam_objholder1_idx` (`user_id` ASC),
  INDEX `fk_glam_ao_schedule_glam_transaction1_idx` (`transaction_id` ASC),
  CONSTRAINT `fk_glam_ao_schedules_glam_access_object_key1`
    FOREIGN KEY (`access_object_id`)
    REFERENCES `sog`.`glam_access_object_key` (`access_object_id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ao_schedule_glam_access_point1`
    FOREIGN KEY (`access_point_id`)
    REFERENCES `sog`.`glam_access_point` (`access_point_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ao_schedule_glam_objholder1`
    FOREIGN KEY (`user_id`)
    REFERENCES `sog`.`glam_objholder` (`user_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_glam_ao_schedule_glam_transaction1`
    FOREIGN KEY (`transaction_id`)
    REFERENCES `sog`.`glam_transaction` (`transaction_id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_asset_type` (
  `type_id` INT NOT NULL AUTO_INCREMENT,
  `type_name` VARCHAR(64) NULL,
  `is_deleted` BIT NULL DEFAULT b'0',
  `created_on` DATETIME NULL,
  `created_by` CHAR(36) NULL,
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL DEFAULT NULL,
  `deleted_by` CHAR(36) NULL DEFAULT NULL,
  `deleted_on` DATETIME NULL,
  PRIMARY KEY (`type_id`),
  INDEX `idx_type_name` (`type_name` ASC))
ENGINE = InnoDB;


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

CREATE TABLE IF NOT EXISTS `sog`.`glam_asset` (
  `asset_id` INT NOT NULL AUTO_INCREMENT,
  `asset_rf_id` BIGINT NULL DEFAULT NULL,
  `asset_name` VARCHAR(64) NULL,
  `asset_description` VARCHAR(256) NULL,
  `asset_coordinates` POINT NULL,
  `asset_state` ENUM('DISCOVERED', 'APPROVED') NULL DEFAULT 'DISCOVERED',
  `type_id` INT NOT NULL,
  `is_deleted` BIT NULL DEFAULT b'0',
  `created_on` DATETIME NULL,
  `created_by` CHAR(36) NULL COMMENT 'User that added the asset',
  `last_changed_on` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_changed_by` CHAR(36) NULL,
  `deleted_on` DATETIME NULL,
  `deleted_by` CHAR(36) NULL,
  `approved_on` DATETIME NULL,
  `approved_by` CHAR(36) NULL COMMENT 'Admin/NOC that approved the asset',
  `asset_rf_id_deleted` MEDIUMTEXT NULL DEFAULT NULL,
  PRIMARY KEY (`asset_id`),
  UNIQUE INDEX `asset_rf_id_UNIQUE` (`asset_rf_id` ASC),
  INDEX `fk_glam_asset_glam_asset_type_idx` (`type_id` ASC),
  INDEX `idx_is_deleted` (`is_deleted` ASC),
  INDEX `idx_asset_name` (`asset_name` ASC),
  CONSTRAINT `fk_glam_asset_glam_asset_type`
    FOREIGN KEY (`type_id`)
    REFERENCES `sog`.`glam_asset_type` (`type_id`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE)
ENGINE = InnoDB;


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`, `notification_colour`) VALUES (0, 'Key powered up', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (1, 'Uncomissioned lock discovered', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (2, 'Successful authorized unlocking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (3, 'Successful authorized locking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (4, 'Successful authorized late locking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (5, 'Failed authorized opening – lock in locked state', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (6, 'Failed authorized closing – lock in unlocked state', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (7, 'Failed authorized opening – lock in unknown state', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (8, 'Failed authorized closing – lock in unknown state', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (9, 'Unauthorized attempted unlocking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (10, 'Unauthorized attempted locking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (11, 'Successful commissioning of lock', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (12, 'Failed commissioning of lock', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (13, 'No RF tag found during unlocking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (14, 'No RF tag found during locking', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (15, 'Recheck of RF tag before closing failed', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (16, 'Duress alarm – keyholder panic', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (17, 'Tamper alarm – key enclosure opened', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (18, 'Possible latch replacement', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (19, 'Possible lock replacement', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (20, 'Latch replaced successfully', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (21, 'Lock replaced successfully', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (22, 'Lock comms error', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (23, 'New key discovered', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (24, 'Key login', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (25, 'Lock comms initialisation error', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (26, 'Lid discovered', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (27, 'Key - Transactions downloaded successfully', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (28, 'Key - Transactions download timeout', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (29, 'Key - Events uploaded successfully', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (30, 'Key - Events upload timeout', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (50, 'Database stopped', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (51, 'Database started', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (52, 'Webserver stopped', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (53, 'Webserver started', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (54, 'Glam stopped', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (55, 'Glam started', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (56, 'Geoserver stopped', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (57, 'Geoserver started', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (58, 'Unsafe Lock in expired schedule', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (59, 'Unsafe Lock now scheduled', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (31, 'Failed authorized opening – No GPS signal', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (32, 'Failed authorized closing – No GPS signal', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (33, 'Failed authorized opening – Not in scheduled area', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (34, 'Failed authorized closing – Not in scheduled area', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (35, 'Failed authorized opening – Key time invalid', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (36, 'Failed authorized opening – Key time invalid', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (49, 'Lock with replacement serial already exists.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (48, 'Lock with replacement latch already exists.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (47, 'Lock moved out of commissioned area.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (46, 'Lock back in commissioned area.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (45, 'Lock safe area updated.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (44, 'Original latch retored.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (43, 'Original lock restored.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (37, 'Possible spoofing detected.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (200, 'User requested information for the specified asset.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (201, 'User registered a new asset to the system.', NULL, NULL);
INSERT INTO `sog`.`glam_notification` (`notification_id`, `notification_desc`, `severity_id`, `notification_colour`) VALUES (202, 'NOC operator confirmed and registered an asset.', NULL, 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);
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 ('1bd19303-8da9-4813-9b73-fe9723472ef7', 'glam_and', '362cf9a9f03079d7adf2ae24f9a29318', 'Glam_And', 'Glam_And', 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);
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', '1bd19303-8da9-4813-9b73-fe9723472ef7', 'd4fbc164-bac0-4315-aee6-617340fea023', 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;

