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';
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `logpro`
  DEFAULT CHARACTER SET utf8
  COLLATE utf8_unicode_ci;

USE `logpro`;

-- -----------------------------------------------------
-- Table `logpro`.`sistema_interfaces`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_interfaces`
(
  `id`                     INT(2) UNSIGNED               NOT NULL AUTO_INCREMENT,
  `nombre`                 VARCHAR(45)                   NOT NULL,
  `path`                   VARCHAR(30)                   NOT NULL,
  `header`                 VARCHAR(30)                   NOT NULL,
  `visualizacion_unidades` ENUM ('INDIVIDUAL', 'GRUPAL') NOT NULL DEFAULT 'GRUPAL',
  `descripcion`            TEXT                          NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- ----------------------------------------------------
-- Table `logpro`.`sistema_perfiles_usuarios`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_perfiles_usuarios`
(
  `id`                      INT(2) UNSIGNED                     NOT NULL AUTO_INCREMENT,
  `creacion`                TIMESTAMP                           NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `interfaz_id`             INT(2) UNSIGNED                     NOT NULL,
  `nombre`                  VARCHAR(100)                        NOT NULL,
  `tipo`                    ENUM ('COMPLETO', 'IDENTIFICACION') NOT NULL DEFAULT 'COMPLETO',
  `requiere_identificacion` ENUM ('SI', 'NO')                   NOT NULL DEFAULT 'NO',
  `accesos`                 VARCHAR(200)                        NULL,
  `editable`                INT(1) UNSIGNED                     NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_perfiles_usuarios_interfaces` (`interfaz_id` ASC),
  CONSTRAINT `fk_sistema_perfiles_usuarios_interfaces`
  FOREIGN KEY (`interfaz_id`)
  REFERENCES `logpro`.`sistema_interfaces` (`id`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_general_ci
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- ----------------------------------------------------
-- Table `logpro`.`sistema_instancias`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_instancias`
(
  `id`     VARCHAR(20) NOT NULL,
  `nombre` VARCHAR(20) NOT NULL,
  `rut`    VARCHAR(9)  NOT NULL,
  `estado` ENUM ('ACTIVO', 'SUSPENDIDO', 'NO ACTIVO') DEFAULT 'ACTIVO',
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_general_ci
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- ----------------------------------------------------
-- Table `logpro`.`sistema_perfiles_usuarios_instancias`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_perfiles_usuarios_instancias`
(
  `perfil_id`    INT(2) UNSIGNED NOT NULL,
  `instancia_id` VARCHAR(20)     NOT NULL,
  PRIMARY KEY (`perfil_id`, `instancia_id`),
  INDEX `fk_sistema_perfiles_usuarios_instancias_perfiles` (`perfil_id` ASC),
  INDEX `fk_sistema_perfiles_usuarios_instancias_instancias` (`instancia_id` ASC),
  CONSTRAINT `fk_sistema_perfiles_usuarios_instancias_perfiles`
  FOREIGN KEY (`perfil_id`)
  REFERENCES `logpro`.`sistema_perfiles_usuarios` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_perfiles_usuarios_instancias_instancias`
  FOREIGN KEY (`instancia_id`)
  REFERENCES `logpro`.`sistema_instancias` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_general_ci
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- ----------------------------------------------------
-- Table `logpro`.`sistema_widgets`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_widgets`
(
  `id`            INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
  `perfil_id`     INT(2) UNSIGNED NULL,
  `nombre`        VARCHAR(100)    NOT NULL,
  `descripcion`   TEXT            NOT NULL,
  `columnas`      INT(2) UNSIGNED NOT NULL,
  `plantilla`     VARCHAR(100)    NOT NULL,
  `configuracion` TEXT            NULL     DEFAULT NULL,
  `accesos`       VARCHAR(200)    NULL     DEFAULT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_widgets_perfiles` (`perfil_id` ASC),
  CONSTRAINT `fk_sistema_widgets_perfiles`
  FOREIGN KEY (`perfil_id`)
  REFERENCES `logpro_base`.`sistema_perfiles_usuarios` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_general_ci
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- ----------------------------------------------------
-- Table `logpro`.`sistema_usuarios`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_usuarios`
(
  `id`             INT(3) UNSIGNED              NOT NULL AUTO_INCREMENT,
  `creacion`       TIMESTAMP                    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `creador_id`     INT(2) UNSIGNED              NULL     DEFAULT NULL,
  `empresa_id`     INT(2) UNSIGNED              NOT NULL,
  `unidad_id`      VARCHAR(30)                  NULL,
  `tipo`           ENUM ('USUARIO', 'CONTACTO') NOT NULL DEFAULT 'CONTACTO',
  `nombre`         VARCHAR(199)                 NOT NULL,
  `mail`           VARCHAR(100)                 NOT NULL,
  `cargo`          VARCHAR(30)                  NULL     DEFAULT NULL,
  `telefono`       VARCHAR(15)                  NULL     DEFAULT NULL,
  `perfil_id`      INT(2) UNSIGNED              NOT NULL,
  `usuario`        VARCHAR(100)                 NOT NULL,
  `clave`          VARCHAR(100)                 NOT NULL,
  `valido_hasta`   DATE                         NULL     DEFAULT NULL,
  `autorizaciones` TEXT                         NULL,
  `notificaciones` INT(1) UNSIGNED              NOT NULL DEFAULT 0,
  `estado`         INT(1) UNSIGNED              NOT NULL DEFAULT 1,
  `editable`       INT(1) UNSIGNED              NOT NULL DEFAULT 1,
  `mostrar`        INT(1) UNSIGNED              NOT NULL DEFAULT 0,
  `pref_font_size` DECIMAL(4, 3) UNSIGNED       NOT NULL DEFAULT 0.813,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `unique_usuario` (`usuario` ASC),
  INDEX `fk_sistema_usuarios_usuarios` (`creador_id` ASC),
  INDEX `fk_sistema_usuarios_empresas` (`empresa_id` ASC),
  INDEX `fk_sistema_usuarios_unidades` (`unidad_id` ASC),
  INDEX `fk_sistema_usuarios_perfiles` (`perfil_id` ASC),
  CONSTRAINT `fk_sistema_usuarios_usuarios`
  FOREIGN KEY (`creador_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_usuarios_empresas`
  FOREIGN KEY (`empresa_id`)
  REFERENCES `logpro`.`empresas` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_usuarios_unidades`
  FOREIGN KEY (`unidad_id`)
  REFERENCES `logpro`.`control_unidades` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_usuarios_perfiles`
  FOREIGN KEY (`perfil_id`)
  REFERENCES `logpro_base`.`sistema_perfiles_usuarios` (`id`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  COLLATE = utf8_general_ci
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_usuarios_widgets`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_usuarios_widgets`
(
  `id`           INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
  `creacion`     TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `usuario_id`   INT(3) UNSIGNED NOT NULL,
  `widget_id`    INT(2) UNSIGNED NOT NULL,
  `lugar`        INT(2)          NOT NULL DEFAULT '0',
  `preferencias` TEXT            NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_usuarios_widgets_usuarios` (`usuario_id` ASC),
  INDEX `fk_sistema_usuarios_widgets_widgets` (`widget_id` ASC),
  CONSTRAINT `fk_sistema_usuarios_widgets_usuarios`
  FOREIGN KEY (`usuario_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_usuarios_widgets_widgets`
  FOREIGN KEY (`widget_id`)
  REFERENCES `logpro_base`.`sistema_widgets` (`id`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_usuarios_notificaciones`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_usuarios_notificaciones`
(
  `id`            INT(2) UNSIGNED                NOT NULL AUTO_INCREMENT,
  `creacion`      TIMESTAMP                      NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `usuario_id`    INT(3) UNSIGNED                NOT NULL,
  `origen`        VARCHAR(30)                    NOT NULL,
  `titulo`        VARCHAR(50)                    NOT NULL,
  `detalle`       TEXT                           NOT NULL,
  `visualizacion` TIMESTAMP                      NULL,
  `estado`        ENUM ('PENDIENTE', 'RECIBIDA') NOT NULL DEFAULT 'PENDIENTE',
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_usuarios_notificaciones_usuarios` (`usuario_id` ASC),
  CONSTRAINT `fk_sistema_usuarios_notificaciones_usuarios`
  FOREIGN KEY (`usuario_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_usuarios_recuperaciones`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_usuarios_recuperaciones`
(
  `hash`       VARCHAR(50)       NOT NULL,
  `creacion`   TIMESTAMP         NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `usuario_id` INT(3) UNSIGNED   NOT NULL,
  `ip_address` VARCHAR(20)       NULL,
  `terminado`  ENUM ('NO', 'SI') NOT NULL DEFAULT 'NO',
  PRIMARY KEY (`hash`),
  INDEX `fk_sistema_usuarios_recuperaciones_usuarios` (`usuario_id` ASC),
  CONSTRAINT `fk_sistema_usuarios_recuperaciones_usuarios`
  FOREIGN KEY (`usuario_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_config_importaciones`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_config_importaciones`
(
  `id`                   INT(3) UNSIGNED                                                                     NOT NULL AUTO_INCREMENT,
  `tipo`                 ENUM ('GUIAS_DESPACHO', 'OPERACIONES', 'SUMINISTROS_STOCKS', 'HOROMETROS_LECTURAS') NOT NULL,
  `nombre`               VARCHAR(100)                                                                        NOT NULL,
  `controller`           VARCHAR(50)                                                                         NOT NULL,
  `action`               VARCHAR(50)                                                                         NOT NULL,
  `empresas_autorizadas` TEXT                                                                                NOT NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_preferencias`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_preferencias`
(
  `id`          INT UNSIGNED   NOT NULL AUTO_INCREMENT,
  `nombre`      VARCHAR(45)    NOT NULL,
  `valor`       FLOAT UNSIGNED NOT NULL,
  `valor_txt`   VARCHAR(255)   NULL,
  `validador`   VARCHAR(100)   NOT NULL,
  `label`       VARCHAR(50)    NOT NULL,
  `descripcion` TEXT           NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_notificaciones_emails`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_notificaciones_emails`
(
  `email`   VARCHAR(100) NOT NULL,
  `smtp`    VARCHAR(100) NOT NULL,
  `usuario` VARCHAR(100) NOT NULL,
  `clave`   VARCHAR(100) NOT NULL,
  `auth`    VARCHAR(20)  NOT NULL DEFAULT 'login',
  `puerto`  INT UNSIGNED NOT NULL DEFAULT '587',
  `ssl`     VARCHAR(20)           DEFAULT 'tls',
  PRIMARY KEY (`email`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_informes_preconfig`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_informes_preconfig`
(
  `id`         INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
  `creacion`   TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `creador_id` INT(2) UNSIGNED NULL,
  `nombre`     VARCHAR(100)    NOT NULL,
  `url`        VARCHAR(100)    NOT NULL,
  `parametros` TEXT            NOT NULL,
  `estado`     INT(1) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_informes_preconfig_usuarios` (`creador_id` ASC),
  CONSTRAINT `fk_sistema_informes_preconfig_usuarios`
  FOREIGN KEY (`creador_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_mensajes_auto`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_mensajes_auto`
(
  `id`               INT UNSIGNED    NOT NULL AUTO_INCREMENT,
  `creacion`         TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `creador_id`       INT(2) UNSIGNED NULL,
  `usuario_id`       INT(2) UNSIGNED NOT NULL,
  `informe_id`       INT(2) UNSIGNED NOT NULL,
  `dia`              INT(2) UNSIGNED NOT NULL,
  `con_copia`        TEXT            NULL,
  `con_copia_oculta` TEXT            NULL,
  `mensaje`          TEXT            NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_mensajes_auto_usuarios` (`creador_id` ASC),
  INDEX `fk_sistema_mensajes_auto_destinatarios` (`usuario_id` ASC),
  INDEX `fk_sistema_mensajes_auto_informes` (`informe_id` ASC),
  CONSTRAINT `fk_sistema_mensajes_auto_usuarios`
  FOREIGN KEY (`creador_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_mensajes_auto_destinatarios`
  FOREIGN KEY (`usuario_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_sistema_mensajes_auto_informes`
  FOREIGN KEY (`informe_id`)
  REFERENCES `logpro`.`sistema_informes_preconfig` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_log_ingresos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_log_ingresos`
(
  `id`         INT UNSIGNED    NOT NULL AUTO_INCREMENT,
  `creacion`   TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `usuario_id` INT(2) UNSIGNED NOT NULL,
  `session_id` VARCHAR(50)     NULL,
  `ip_address` VARCHAR(20)     NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_sistema_log_ingresos_usuarios` (`usuario_id` ASC),
  CONSTRAINT `fk_sistema_log_ingresos_usuarios`
  FOREIGN KEY (`usuario_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_log_ingresos_fallidos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_log_ingresos_fallidos`
(
  `id`         INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `creacion`   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `session_id` VARCHAR(50)  NULL,
  `data`       TEXT         NOT NULL,
  `ip_address` VARCHAR(20)  NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_log_errores`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_log_errores`
(
  `id`         INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `creacion`   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP
  ON UPDATE CURRENT_TIMESTAMP,
  `session_id` VARCHAR(50)  NULL,
  `data`       TEXT         NOT NULL,
  `ip_address` VARCHAR(20)  NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_log_actividades`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_log_actividades`
(
  `id`         INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `creacion`   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `session_id` VARCHAR(50)  NOT NULL,
  `params`     TEXT         NOT NULL,
  `ip`         VARCHAR(20)  NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `logpro`.`sistema_notificaciones`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`sistema_notificaciones`
(
  `id`            INT UNSIGNED                            NOT NULL AUTO_INCREMENT,
  `creacion`      TIMESTAMP                               NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `grupo`         VARCHAR(50)                             NOT NULL,
  `mensaje`       TEXT                                    NOT NULL,
  `tipo`          ENUM ('INFO', 'ALERTA', 'CONFIRMACION') NOT NULL,
  `estado`        INT(1) UNSIGNED                         NOT NULL DEFAULT '0',
  `visualizacion` TIMESTAMP                               NULL,
  PRIMARY KEY (`id`)
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8
  PACK_KEYS = 0
  ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- VISTA USUARIOS
-- -----------------------------------------------------
-- Table `logpro`.`vista_usuarios`
-- -----------------------------------------------------
CREATE VIEW `logpro`.`vista_usuarios` AS
  SELECT
    su.id,
    su.perfil_id,
    su.nombre,
    su.tipo,
    su.empresa_id,
    su.unidad_id,
    su.usuario,
    su.mail,
    su.telefono,
    su.cargo,
    su.clave,
    su.autorizaciones,
    su.notificaciones,
    su.valido_hasta,
    su.estado,
    su.mostrar,
    su.pref_font_size,
    e.nombre_fantasia AS empresa,
    pu.editable       AS perfil_editable,
    pu.nombre         AS perfil,
    pu.tipo           AS acceso,
    pu.requiere_identificacion,
    si.nombre         AS interfaz,
    si.path,
    si.header,
    si.visualizacion_unidades
  FROM sistema_usuarios su
    JOIN empresas e ON e.id = su.empresa_id
    JOIN logpro_base.sistema_perfiles_usuarios pu ON pu.id = su.perfil_id
    JOIN logpro_base.sistema_interfaces si ON si.id = pu.interfaz_id;
-- -----------------------------------------------------
-- Table `logpro`.`vista_contactos`
-- -----------------------------------------------------
CREATE VIEW `logpro`.`vista_contactos` AS
  SELECT
    su.id,
    su.nombre,
    su.perfil_id,
    su.empresa_id,
    su.tipo,
    su.mail,
    su.telefono,
    su.cargo,
    e.nombre_fantasia AS empresa
  FROM sistema_usuarios su
    JOIN empresas e ON e.id = su.empresa_id;
-- -----------------------------------------------------
SET SQL_MODE = @OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS = @OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS = @OLD_UNIQUE_CHECKS;