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 `shipcode` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
USE `shipcode`;
-- -----------------------------------------------------
-- Table `shipcode`.`ubicaciones_virtuales`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`ubicaciones_virtuales` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `nombre` VARCHAR(50) NOT NULL,
    `observaciones` TEXT NULL,
    PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`base_sistemas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`base_sistemas` (
    `id` INT(5) UNSIGNED NOT NULL,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `padre_id` INT(5) UNSIGNED NULL,
    `nombre` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_base_sistemas_usuarios` (`creador` ASC) ,
    INDEX `fk_base_sistemas_sistemas` (`padre_id` ASC) ,
    CONSTRAINT `fk_base_sistemas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_base_sistemas_sistemas`
        FOREIGN KEY (`padre_id` )
        REFERENCES `shipcode`.`base_sistemas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`base_servicios`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`base_servicios` (
    `id` INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
    `nombre` VARCHAR(50) NOT NULL,
    `mostrar` INT(1) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`base_planemant`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`base_planesmant` (
    `id` INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `tipo_id` INT(3) UNSIGNED NULL,
    `nombre` VARCHAR(50) NOT NULL,
    `observaciones` TEXT NULL,
    `estado` ENUM('HABILITADO', 'DESHABILITADO') NOT NULL DEFAULT 'HABILITADO',
    PRIMARY KEY (`id`),
    INDEX `fk_base_planesmant_usuarios` (`creador` ASC) ,
    INDEX `fk_base_planesmant_tipos_equipos` (`tipo_id` ASC) ,
    CONSTRAINT `fk_base_planesmant_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_base_planesmant_tipos_equipos`
        FOREIGN KEY (`tipo_id` )
        REFERENCES `shipcode`.`equipos_tipos` (`id`)
        ON DELETE SET NULL  
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`base_planesmant_items`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`base_planesmant_items` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `plan_id` INT(4) UNSIGNED NOT NULL,
    `servicio_id` INT(3) UNSIGNED NOT NULL,
    `descripcion` VARCHAR(50) NULL,
    `cantidad_horas` INT UNSIGNED NULL DEFAULT NULL,
    `cantidad_dias` INT UNSIGNED NULL DEFAULT NULL,
    `dias_aviso` INT UNSIGNED NULL,
    `asignado_a` ENUM('NAVE','EXTERNO') NOT NULL DEFAULT 'NAVE',
    `asociar_proyecto` ENUM('SI','NO') NOT NULL DEFAULT 'NO',
    PRIMARY KEY (`id`),
    INDEX `fk_base_planesmant_items_usuarios` (`creador` ASC) ,
    INDEX `fk_base_planesmant_items_servicios` (`servicio_id` ASC) ,
    INDEX `fk_base_planesmant_items_planes` (`plan_id` ASC) ,
    CONSTRAINT `fk_base_planesmant_items_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_base_planesmant_items_servicios`
        FOREIGN KEY (`servicio_id` )
        REFERENCES `shipcode`.`base_servicios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_base_planesmant_items_planes`
        FOREIGN KEY (`plan_id` )
        REFERENCES `shipcode`.`base_planesmant` (`id`)
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`codigos_observaciones`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`codigos_observaciones` (
    `codigo` INT(2) UNSIGNED NOT NULL,
    `plazo` INT(3) UNSIGNED NOT NULL,
    `comentarios` VARCHAR(100) NULL,
    PRIMARY KEY (`codigo`)    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`cuentas_carenas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`cuentas_carenas` (
    `id` INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_cuentas_carenas_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_cuentas_carenas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`empresas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`empresas` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(200) NOT NULL ,
    PRIMARY KEY (`id`),
    INDEX `fk_empresas_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_empresas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`cargos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`cargos` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `nombre` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`equipos_tipos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`equipos_tipos` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    PRIMARY KEY (`id`),
    INDEX `fk_equipos_tipos_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_equipos_tipos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`equipos_parametros`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`equipos_parametros` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    `indicaciones` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_equipos_parametros_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_equipos_parametros_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`mantenimientos_tipos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`mantenimientos_tipos` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    `grupo` INT(1) UNSIGNED NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    INDEX `fk_mantenimientos_tipos_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_mantenimientos_tipos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`equipos_marcas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`equipos_marcas` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    PRIMARY KEY (`id`),
    INDEX `fk_equipos_marcas_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_equipos_marcas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`certificados_tipos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`certificados_tipos` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    `indefinido` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `critico` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `lugar` INT(3) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_certificados_tipos_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_certificados_tipos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`naves`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves` (
    `id` INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
    `matricula` VARCHAR(20) NULL,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `empresa_id` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    `cb` VARCHAR(10) NOT NULL,
    `puerto_matricula` VARCHAR(20) NOT NULL,
    `ismm` VARCHAR(20) NOT NULL,
    `tipo_nave` VARCHAR(20) NOT NULL,
    `clasificacion` VARCHAR(10) NOT NULL,
    `construccion` YEAR NOT NULL,
    `observaciones` TEXT NULL,
    `sig_carena_mes` INT(2) UNSIGNED NULL,
    `sig_carena_year` YEAR  NULL,
    `fotografia` VARCHAR(200) NULL,
    `otras_modificaciones` TEXT NULL,
    `info_tecnica` TEXT NULL,
    `dimensiones` TEXT NULL,
    `capacidades` TEXT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_empresas` (`empresa_id` ASC) ,
    CONSTRAINT `fk_naves_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_empresas`
        FOREIGN KEY (`empresa_id` )
        REFERENCES `shipcode`.`empresas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`mantenimientos_informados`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`mantenimientos_informados` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `fecha_envio` DATE NOT NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `servicio_id` INT(5) UNSIGNED NOT NULL,
    `fecha` DATE NOT NULL,
    `horas` INT UNSIGNED NULL,
    `observaciones` TEXT NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    INDEX `fk_mantenimientos_informados_usuarios` (`creador` ASC) ,
    INDEX `fk_mantenimientos_informados_equipos` (`equipo_id` ASC) ,
    INDEX `fk_mantenimientos_informados_servicios` (`servicio_id` ASC) ,
    CONSTRAINT `fk_mantenimientos_informados_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_mantenimientos_informados_equipos`
        FOREIGN KEY (`equipos_id` )
        REFERENCES `shipcode`.`naves_equipos` (`id` )
        ON DELETE CASCADE  
        ON UPDATE CASCADE
    CONSTRAINT `fk_mantenimientos_informados_servicios`
        FOREIGN KEY (`servicio_id` )
        REFERENCES `shipcode`.`base_servicios` (`id` )
        ON DELETE RESTRICT   
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`solicitudes_tipos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`solicitudes_tipos` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    `notificar_a` VARCHAR(200) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_solicitudes_tipos_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_solicitudes_tipos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`solicitudes`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`solicitudes` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `tipo_id` INT(2) UNSIGNED NOT NULL,
    `fecha_envio` DATE NOT NULL,
    `fecha_recepcion` DATE NULL,
    `fecha_termino` DATE NULL,
    `fecha_cierre` DATE NULL,
    `fecha_rechazo` DATE NULL,
    `usuario_rechazo_id` INT(2) UNSIGNED NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `detalles` TEXT NOT NULL,
    `num_solicitud` INT UNSIGNED NOT NULL,
    `num_orden` INT UNSIGNED NOT NULL,
    `total_neto` INT UNSIGNED NOT NULL,
    `prioridad` ENUM('NORMAL', 'URGENTE') NOT NULL DEFAULT 'NORMAL',
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    INDEX `fk_solicitudes_usuarios` (`creador` ASC) ,
    INDEX `fk_solicitudes_tipos` (`tipo_id` ASC) ,
    INDEX `fk_solicitudes_rechazos` (`usuario_rechazo_id` ASC) ,
    INDEX `fk_solicitudes_naves` (`nave_id` ASC) ,
    CONSTRAINT `fk_solicitudes_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_solicitudes_tipos`
        FOREIGN KEY (`tipo_id` )
        REFERENCES `shipcode`.`solicitudes_tipos` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_solicitudes_rechazos`
        FOREIGN KEY (`usuario_rechazo_id` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_solicitudes_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE  
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`solicitudes_comentarios`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`solicitudes_comentarios` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `solicitud_id` INT(6) UNSIGNED NOT NULL,
    `comentarios` TEXT NOT NULL,
    `tipo` VARCHAR(12) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_solicitudes_comentarios_usuarios` (`creador` ASC) ,
    INDEX `fk_solicitudes_comentarios_solicitudes` (`solicitud_id` ASC) ,
    CONSTRAINT `fk_solicitudes_comentarios_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_solicitudes_comentarios_solicitudes`
        FOREIGN KEY (`solicitud_id` )
        REFERENCES `shipcode`.`solicitudes` (`id` )
        ON DELETE CASCADE  
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_usuarios`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_usuarios` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `usuario_id` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(2) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_usuarios_creador` (`creador` ASC) ,
    INDEX `fk_naves_usuarios_usuarios` (`usuario_id` ASC) ,
    INDEX `fk_naves_usuarios_naves` (`nave_id` ASC) ,
    CONSTRAINT `fk_naves_usuarios_creador`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_usuarios_usuarios`
        FOREIGN KEY (`usuario_id` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,    
    CONSTRAINT `fk_naves_usuarios_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`etiquetas_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`etiquetas_archivos` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    `equipos` ENUM('SI', 'NO') NOT NULL DEFAULT 'SI',
    `naves` ENUM('SI', 'NO') NOT NULL DEFAULT 'SI',
    PRIMARY KEY (`id`),
    INDEX `fk_etiquetas_archivos_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_etiquetas_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `etiqueta_id` INT(2) UNSIGNED NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(200) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_archivos_naves` (`nave_id` ASC) ,
    INDEX `fk_naves_archivos_etiquetas` (`etiqueta_id` ASC) ,
    CONSTRAINT `fk_naves_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_archivos_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_archivos_etiquetas`
        FOREIGN KEY (`etiqueta_id` )
        REFERENCES `shipcode`.`etiquetas_archivos` (`id` )
        ON DELETE SET NULL  
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_sistemas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_sistemas` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `padre_id` INT(5) UNSIGNED NULL,
    `nombre` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_sistemas_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_sistemas_naves` (`nave_id` ASC) ,
    INDEX `fk_naves_sistemas_sistemas` (`padre_id` ASC) ,
    CONSTRAINT `fk_naves_sistemas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_sistemas_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_sistemas_sistemas`
        FOREIGN KEY (`padre_id` )
        REFERENCES `shipcode`.`naves_sistemas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_equipos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_equipos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `ubicacion_id` INT UNSIGNED NOT NULL,
    `tipo_id` INT(2) UNSIGNED NULL,
    `marca_id` INT(2) UNSIGNED NULL,
    `modelo` VARCHAR(100) NULL,
    `nombre` VARCHAR(200) NOT NULL,
    `serie` VARCHAR(100) NULL,
    `datos_tecnicos` TEXT NULL,
    `horometro` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `horometro_anclaje` INT(5) UNSIGNED NULL,
    `parametros` TEXT NULL,
    `planmant_id` INT(4) UNSIGNED NULL,
    `inicio_operaciones` DATE NOT NULL,
    `promedio_calculado` INT UNSIGNED NULL DEFAULT NULL,
    `promedio_asignado` INT UNSIGNED NULL DEFAULT NULL,
    `promedio_usado` ENUM('C','A') DEFAULT 'C',
    `fotografia` VARCHAR(200) NULL DEFAULT NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `condicion` ENUM('NUEVO', 'OPERATIVO', 'NO OPERATIVO', 'DE BAJA'),
    `orden` INT(3) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_equipos_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_equipos_ubicaciones` (`ubicacion_id` ASC) ,
    INDEX `fk_naves_equipos_tipos` (`tipo_id` ASC) ,
    INDEX `fk_naves_equipos_marcas` (`marca_id` ASC),
    INDEX `fk_naves_equipos_planesmant` (`planmant_id` ASC),
    INDEX `fk_naves_equipos_horometro_anclaje` (`horometro_anclaje` ASC),
    INDEX `index_horometros` (`horometro` ASC), 
    CONSTRAINT `fk_naves_equipos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_ubicaciones`
        FOREIGN KEY (`ubicacion_id` )
        REFERENCES `shipcode`.`naves_equipos_ubicaciones` (`id` )
        ON DELETE SET NULL    
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_tipos`
        FOREIGN KEY (`tipo_id` )
        REFERENCES `shipcode`.`equipos_tipos` (`id` )
        ON DELETE SET NULL  
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_marcas`
        FOREIGN KEY (`marca_id` )
        REFERENCES `shipcode`.`equipos_marcas` (`id` )
        ON DELETE SET NULL  
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_planesmant`
        FOREIGN KEY (`planmant_id` )
        REFERENCES `shipcode`.`base_planesmant` (`id` )
        ON DELETE SET NULL  
        ON UPDATE CASCADE ,
    CONSTRAINT `fk_naves_equipos_horometro_anclaje`
        FOREIGN KEY (`horometro_anclaje` )
        REFERENCES `shipcode`.`naves_equipos` (`id` )
        ON DELETE SET NULL  
        ON UPDATE CASCADE     
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_equipos_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_equipos_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `etiqueta_id` INT(2) UNSIGNED NULL,
    `nombre` VARCHAR(50) NOT NULL,
    `archivo` VARCHAR(200) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_equipos_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_equipos_archivos_equipos` (`equipo_id` ASC) ,
    INDEX `fk_equipos_archivos_etiquetas` (`etiqueta_id` ASC) ,
    CONSTRAINT `fk_equipos_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_equipos_archivos_equipos`
        FOREIGN KEY (`equipo_id` )
        REFERENCES `shipcode`.`naves_equipos` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_equipos_archivos_etiquetas`
        FOREIGN KEY (`etiqueta_id` )
        REFERENCES `shipcode`.`etiquetas_archivos` (`id` )
        ON DELETE SET NULL  
        ON UPDATE CASCADE  
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_equipos_ubicaciones`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_equipos_ubicaciones` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `ubicacionv_id` INT(2) UNSIGNED NULL,
    `sistema_id` INT(5) UNSIGNED NULL,
    `fecha_entrada` DATE NOT NULL,
    `fecha_salida` DATE NULL,
    `observaciones` TEXT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_equipos_ubicaciones_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_equipos_ubicaciones_equipos` (`equipo_id` ASC) ,
    CONSTRAINT `fk_naves_equipos_ubicaciones_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_ubicaciones_equipos`
        FOREIGN KEY (`equipo_id` )
        REFERENCES `shipcode`.`naves_equipos` (`id` )
        ON DELETE CASCADE    
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_equipos_partes`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_equipos_partes` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `parte_id` INT(6) UNSIGNED NULL,
    `num_parte` VARCHAR(50) NULL,
    `descripcion` VARCHAR(200) NULL,
    `cantidad` INT(3) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_equipos_partes_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_equipos_partes_partes` (`parte_id` ASC) ,
    CONSTRAINT `fk_naves_equipos_partes_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_partes_partes`
        FOREIGN KEY (`parte_id` )
        REFERENCES `shipcode`.`naves_equipos_partes` (`id` )
        ON DELETE SET NULL 
        ON UPDATE CASCADE 
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_equipos_mantenimientos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_equipos_mantenimientos` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `mantenimiento_informado_id` INT(6) UNSIGNED NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `tipo_id` INT(2) UNSIGNED NOT NULL DEFAULT '1',
    `servicio_id` INT(5) UNSIGNED NOT NULL,
    `servicio_desc` VARCHAR(50) NULL,
    `fecha` DATE NOT NULL,
    `detalles` TEXT NOT NULL,
    `observaciones` TEXT NULL,
    `horometro` INT UNSIGNED NULL,
    `proyecto_requerido` ENUM('SI', 'NO') NOT NULL DEFAULT 'NO', 
    `proyecto_id` INT(4) UNSIGNED NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `informado_por` ENUM('NAVE', 'ADMIN') NOT NULL DEFAULT 'ADMIN',
    PRIMARY KEY (`id`),
    INDEX `fk_naves_equipos_mantenimientos_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_equipos_mantenimientos_mantenimientos_informados` (`mantenimiento_informado_id` ASC) ,
    INDEX `fk_naves_equipos_mantenimientos_equipos` (`equipo_id` ASC) ,
    INDEX `fk_naves_equipos_mantenimientos_tipos` (`tipo_id` ASC) ,
    INDEX `fk_naves_equipos_mantenimientos_servicios` (`servicio_id` ASC) ,
    INDEX `fk_naves_equipos_mantenimientos_proyectos` (`proyecto_id` ASC) ,
    CONSTRAINT `fk_naves_equipos_mantenimientos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_mantenimientos_mantenimientos_informados`
        FOREIGN KEY (`mantenimiento_informado_id` )
        REFERENCES `shipcode`.`mantenimientos_informados` (`id` )
        ON DELETE RESTRICT    
        ON UPDATE CASCADE,    
    CONSTRAINT `fk_naves_equipos_mantenimientos_equipos`
        FOREIGN KEY (`equipo_id` )
        REFERENCES `shipcode`.`naves_equipos` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_mantenimientos_tipos`
        FOREIGN KEY (`tipo_id` )
        REFERENCES `shipcode`.`mantenimientos_tipos` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE, 
    CONSTRAINT `fk_naves_equipos_mantenimientos_servicios`
        FOREIGN KEY (`servicio_id` )
        REFERENCES `shipcode`.`base_servicios` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_equipos_mantenimientos_proyectos`
        FOREIGN KEY (`proyecto_id` )
        REFERENCES `shipcode`.`proyectos` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_equipos_mantenimnientos_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_equipos_mantenimientos_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `mantenimiento_id` INT(6) UNSIGNED NOT NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_equipos_mantenimientos_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_equipos_mantenimientos_archivos_mantenimientos` (`mantenimiento_id` ASC) ,
    CONSTRAINT `fk_equipos_mantenimientos_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_equipos_mantenimientos_archivos_mantenimientos`
        FOREIGN KEY (`mantenimiento_id` )
        REFERENCES `shipcode`.`naves_equipos_mantenimientos` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `cpt`.`naves_horometros_lecturas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `cpt`.`naves_horometros_lecturas` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `fecha` DATE NOT NULL,
    `lectura` INT UNSIGNED NOT NULL,
    `informe_id` INT(5) UNSIGNED NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `ref_id` INT(6) UNSIGNED NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_horometros2_lecturas_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_horometros2_lecturas_informes` (`informe_id` ASC) ,
    INDEX `fk_naves_horometros2_lecturas_equipos` (`equipo_id` ASC) ,
    INDEX `fk_naves_horometros2_lecturas_anclaje` (`ref_anclaje` ASC) ,
    CONSTRAINT `fk_naves_horometros2_lecturas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `cpt`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_horometros2_lecturas_informes`
        FOREIGN KEY (`informe_id` )
        REFERENCES `cpt`.`naves_informes` (`id` )
        ON DELETE CASCADE  
        ON UPDATE CASCADE,   
    CONSTRAINT `fk_naves_horometros2_lecturas_equipos`
        FOREIGN KEY (`equipo_id` )
        REFERENCES `cpt`.`naves_equipos` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE ,
    CONSTRAINT `fk_naves_horometros2_lecturas_anclaje`
        FOREIGN KEY (`ref_id` )
        REFERENCES `cpt`.`naves_horometros_lecturas` (`id` )
        ON DELETE SET NULL      
        ON UPDATE CASCADE     
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `cpt`.`naves_parametros_lecturas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `cpt`.`naves_parametros_lecturas` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `fecha` DATE NOT NULL,
    `lectura` INT UNSIGNED NOT NULL,
    `informe_id` INT(5) UNSIGNED NOT NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `parametro_id` INT(2) UNSIGNED NOT NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    INDEX `fk_naves_parametros_lecturas_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_parametros_lecturas_equipos` (`equipo_id` ASC) ,
    INDEX `fk_naves_parametros_lecturas_informes` (`informe_id` ASC) ,
    INDEX `fk_naves_parametros_lecturas_parametros` (`parametro_id` ASC) ,
    CONSTRAINT `fk_naves_parametros_lecturas_usuarios` 
        FOREIGN KEY (`creador` ) 
        REFERENCES `cpt`.`sistema_usuarios` (`id` ) 
        ON DELETE RESTRICT 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_parametros_lecturas_informes` 
        FOREIGN KEY (`informe_id` ) 
        REFERENCES `cpt`.`naves_informes` (`id` ) 
        ON DELETE CASCADE   
        ON UPDATE CASCADE,    
    CONSTRAINT `fk_naves_parametros_lecturas_equipos` 
        FOREIGN KEY (`equipo_id` ) 
        REFERENCES `cpt`.`naves_equipos` (`id` ) 
        ON DELETE RESTRICT   
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_parametros_lecturas_parametros` 
        FOREIGN KEY (`parametro_id` ) 
        REFERENCES `cpt`.`equipos_parametros` (`id` ) 
        ON DELETE RESTRICT   
        ON UPDATE CASCADE 
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_actividades`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_actividades` (
    `id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `equipo_id` INT(5) UNSIGNED NOT NULL,
    `servicio_id` INT(5) UNSIGNED NOT NULL,
    `fecha_original` DATE NULL,
    `fecha_editada` DATE NULL,
    `fecha_final` DATE NULL,
    `horas` INT UNSIGNED NULL,
    `codigo` INT(4) UNSIGNED NOT NULL, 
    `dependencia_tipo` ENUM('C','S') NULL DEFAULT NULL,
    `dependencia_id` INT UNSIGNED NULL,
    `mantenimiento_id` INT UNSIGNED NULL,
    `programacion` ENUM('MANUAL', 'AUTOMATICA') NOT NULL DEFAULT 'AUTOMATICA',
    `aviso` DATE NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT '0',
    `data_backup` TEXT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_actividades_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_actividades_equipos` (`equipo_id` ASC) ,
    INDEX `fk_naves_actividades_servicios` (`servicio_id` ASC) ,
    INDEX `index_estado_actividad` (`estado` ASC),
    CONSTRAINT `fk_naves_actividades_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_actividades_equipos`
        FOREIGN KEY (`equipo_id` )
        REFERENCES `shipcode`.`naves_equipos` (`id` )
        ON DELETE CASCADE    
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_actividades_servicios`
        FOREIGN KEY (`servicio_id` )
        REFERENCES `shipcode`.`base_servicios` (`id` )
        ON DELETE CASCADE    
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_certificados`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_certificados` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `numero` VARCHAR(50) NULL,
    `tipo_id` INT(2) UNSIGNED NOT NULL,
    `descripcion` VARCHAR(50) NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_certificados_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_certificados_naves` (`nave_id` ASC) ,
    INDEX `fk_naves_certificados_tipos` (`tipo_id` ASC) ,
    CONSTRAINT `fk_naves_certificados_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_certificados_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_certificados_tipos`
        FOREIGN KEY (`tipo_id` )
        REFERENCES `shipcode`.`certificados_tipos` (`id` )
        ON DELETE RESTRICT 
        ON UPDATE CASCADE    
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_certificados_emisiones`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_certificados_emisiones` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `certificado_id` INT(5) UNSIGNED NOT NULL,
    `fecha_emision` DATE NOT NULL,
    `fecha_vencimiento` DATE NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_certificados_emisiones_usuarios` (`creador` ASC) ,
    INDEX `fk_certificados_emisiones_certificados` (`certificado_id` ASC) ,
    CONSTRAINT `fk_certificados_emisiones_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_certificados_emisiones_certificados`
        FOREIGN KEY (`certificado_id` )
        REFERENCES `shipcode`.`naves_certificados` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_certificados_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_certificados_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `certificado_id` INT(5) UNSIGNED NOT NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(100) NOT NULL,
    `orden` INT(3) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_certificados_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_certificados_archivos_carenas` (`certificado_id` ASC) ,
    CONSTRAINT `fk_certificados_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_certificados_archivos_carenas`
        FOREIGN KEY (`certificado_id` )
        REFERENCES `shipcode`.`naves_certificados` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_observaciones`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_observaciones` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `boleta` VARCHAR(50) NOT NULL,
    `fecha_emision` DATE NOT NULL,
    `inspector_tc` VARCHAR(100) NULL,
    `inspector_nv_man` VARCHAR(100) NULL,
    `inspector_mq_cn` VARCHAR(100) NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_observaciones_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_observaciones_naves` (`nave_id` ASC) ,
    UNIQUE `unique_boleta` (`boleta`) ,
    CONSTRAINT `fk_naves_observaciones_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_observaciones_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE  
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`auditorias_internas_prioridades`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`auditorias_internas_prioridades` (
    `id` INT(2) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nombre` VARCHAR(50) NOT NULL ,
    `dias_aviso` INT(2) UNSIGNED NOT NULL,
    `dias_vencimiento` INT(2) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_auditorias_internas_prioridades_usuarios` (`creador` ASC) ,
    CONSTRAINT `fk_auditorias_internas_prioridades_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id`)
        ON DELETE RESTRICT 
        ON UPDATE CASCADE 
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
PACK_KEYS = 0
ROW_FORMAT = DEFAULT;
-- -----------------------------------------------------
-- Table `shipcode`.`auditorias_internas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`auditorias_internas` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `ingreso_por` INT(2) UNSIGNED NOT NULL,
    `ingreso_fecha` DATE NOT NULL,
    `prioridad_id` INT(3) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `area_id` INT(5) UNSIGNED NOT NULL,
    `responsable_id` INT(3) UNSIGNED NOT NULL,
    `fecha_vencimiento` DATE NOT NULL,
    `titulo` VARCHAR(100) NOT NULL,
    `descripcion` TEXT NOT NULL,
    `solucionado` ENUM('SI', 'NO', 'SI CON REPAROS') NOT NULL DEFAULT 'SI',
    `cierre_por` INT(2) UNSIGNED NULL,
    `cierre_fecha` DATE NULL,
    `cierre_informe` TEXT NULL,
    `notificaciones_aviso` VARCHAR(200) NULL,
    `notificaciones_vencimiento` VARCHAR(200) NULL,
    `solucionado` ENUM('SI', 'NO', 'SI CON REPAROS')  NOT NULL DEFAULT 'NO',
    `estado` ENUM('PENDIENTE', 'TERMINADA') NOT NULL DEFAULT 'PENDIENTE',
    PRIMARY KEY (`id`),
    INDEX `fk_auditorias_internas_creaciones` (`ingreso_por` ASC) ,
    INDEX `fk_auditorias_internas_prioridades` (`prioridad_id` ASC) ,
    INDEX `fk_auditorias_internas_naves` (`nave_id` ASC) ,
    INDEX `fk_auditorias_internas_areas` (`area_id` ASC) ,
    INDEX `fk_auditorias_internas_responsables` (`responsable_id` ASC) ,
    INDEX `fk_auditorias_internas_cierres` (`cierre_por` ASC) ,
    CONSTRAINT `fk_auditorias_internas_creaciones`
        FOREIGN KEY (`ingreso_por` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_auditorias_internas_prioridades`
        FOREIGN KEY (`prioridad_id` )
        REFERENCES `shipcode`.`auditorias_internas_prioridades` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,    
    CONSTRAINT `fk_auditorias_internas_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_auditorias_internas_areas`
        FOREIGN KEY (`area_id` )
        REFERENCES `shipcode`.`naves_sistemas` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE,    
    CONSTRAINT `fk_auditorias_internas_responsables`
        FOREIGN KEY (`responsable_id` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT  
        ON UPDATE CASCADE,    
    CONSTRAINT `fk_obser_internas_cierres`
        FOREIGN KEY (`cierre_por` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE   
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`auditorias_internas_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`auditorias_internas_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `auditoria_id` INT(5) UNSIGNED NOT NULL,
    `carpeta` INT(5) UNSIGNED NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(100) NOT NULL,
    `orden` INT(3) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_auditorias_internas_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_auditorias_internas_archivos_auditorias_internas` (`auditoria_id` ASC) ,
    CONSTRAINT `fk_auditorias_internas_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_auditorias_internas_archivos_auditorias_internas`
        FOREIGN KEY (`auditoria_id` )
        REFERENCES `shipcode`.`auditorias_internas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_observaciones_items`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_observaciones_items` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `observacion_id` INT(5) UNSIGNED NOT NULL,
    `item` INT(2) UNSIGNED NOT NULL,
    `codigo` INT(3) UNSIGNED NOT NULL,
    `area` VARCHAR(10) NOT NULL,
    `detalle` TEXT NOT NULL,
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT 0,
    `boleta_aprob` VARCHAR(50) NULL,
    `argumentacion` TEXT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_observaciones_items_observaciones` (`observacion_id` ASC) ,
    UNIQUE `unique_item_observacion` (`observacion_id`, `item`),
    CONSTRAINT `fk_naves_observaciones_items_observaciones`
        FOREIGN KEY (`observacion_id` )
        REFERENCES `shipcode`.`naves_observaciones` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE  
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_observaciones_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_observaciones_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `observacion_id` INT(5) UNSIGNED NOT NULL,
    `carpeta` INT(5) UNSIGNED NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(100) NOT NULL,
    `orden` INT(3) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_observaciones_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_observaciones_archivos_observaciones` (`observacion_id` ASC) ,
    CONSTRAINT `fk_observaciones_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_observaciones_archivos_observaciones`
        FOREIGN KEY (`observacion_id` )
        REFERENCES `shipcode`.`naves_observaciones` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_carenas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_carenas` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `fecha` DATE NOT NULL,
    `periodo` INT(2) UNSIGNED NULL, 
    `observaciones` TEXT NULL, 
    `estado` INT(1) UNSIGNED NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_carenas_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_carenas_naves` (`nave_id` ASC) ,
    CONSTRAINT `fk_naves_carenas_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_carenas_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE  
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_carenas_gastos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_carenas_gastos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `carena_id` INT(5) UNSIGNED NOT NULL,
    `cuenta_id` INT(5) UNSIGNED NOT NULL,
    `monto` INT(5) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_carenas_gastos_usuarios` (`creador` ASC) ,
    INDEX `fk_carenas_gastos_carenas` (`carena_id` ASC) ,
    INDEX `fk_carenas_gastos_cuentas` (`cuenta_id` ASC) ,
    CONSTRAINT `fk_carenas_gastos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_carenas_gastos_carenas`
        FOREIGN KEY (`carena_id` )
        REFERENCES `shipcode`.`naves_carenas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE,
    CONSTRAINT `fk_carenas_gastos_cuentas`
        FOREIGN KEY (`cuenta_id` )
        REFERENCES `shipcode`.`cuentas_carenas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_carenas_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_carenas_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `carena_id` INT(5) UNSIGNED NOT NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_carenas_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_carenas_archivos_carenas` (`carena_id` ASC) ,
    CONSTRAINT `fk_carenas_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_carenas_archivos_carenas`
        FOREIGN KEY (`carena_id` )
        REFERENCES `shipcode`.`naves_carenas` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_siniestros`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_siniestros` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `nave_id` INT(3) UNSIGNED NOT NULL,
    `numero` VARCHAR(50) NOT NULL,
    `fecha` DATE NOT NULL,
    `detalle` TEXT NOT NULL,
    `valor` INT UNSIGNED NOT NULL,
    `estado` INT(1) UNSIGNED NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_naves_siniestros_usuarios` (`creador` ASC) ,
    INDEX `fk_naves_siniestros_naves` (`nave_id` ASC) ,
    CONSTRAINT `fk_naves_siniestros_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_naves_siniestros_naves`
        FOREIGN KEY (`nave_id` )
        REFERENCES `shipcode`.`naves` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE  
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `shipcode`.`naves_siniestros_archivos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `shipcode`.`naves_siniestros_archivos` (
    `id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
    `creacion` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `creador` INT(2) UNSIGNED NOT NULL,
    `siniestro_id` INT(5) UNSIGNED NOT NULL,
    `nombre` VARCHAR(100) NOT NULL,
    `archivo` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_siniestros_archivos_usuarios` (`creador` ASC) ,
    INDEX `fk_siniestros_archivos_siniestros` (`siniestro_id` ASC) ,
    CONSTRAINT `fk_siniestros_archivos_usuarios`
        FOREIGN KEY (`creador` )
        REFERENCES `shipcode`.`sistema_usuarios` (`id` )
        ON DELETE RESTRICT
        ON UPDATE CASCADE,
    CONSTRAINT `fk_siniestros_archivos_siniestros`
        FOREIGN KEY (`siniestro_id` )
        REFERENCES `shipcode`.`naves_siniestros` (`id` )
        ON DELETE CASCADE 
        ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------