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';
-- -----------------------------------------------------
USE `logpro`;
-- -----------------------------------------------------
-- Table `logpro`.`salmofood_ventas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`salmofood_ventas` (
  `id`                      VARCHAR(32)                NOT NULL,
  `creacion`                TIMESTAMP                  NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `creador_id`              INT(2) UNSIGNED            NOT NULL,
  `cliente_id`              INT(3) UNSIGNED            NOT NULL,
  `ref_oc`                  VARCHAR(30),
  `estado`                  ENUM ('ACTIVA', 'CERRADA') NOT NULL DEFAULT 'ACTIVA',
  PRIMARY KEY (`id`),
  INDEX `fk_salmofood_ventas_creadores` (`creador_id` ASC),
  INDEX `fk_salmofood_ventas_clientes` (`cliente_id` ASC),
  CONSTRAINT `fk_salmofood_ventas_creadores`
  FOREIGN KEY (`creador_id`)
  REFERENCES `logpro`.`sistema_usuarios` (`id`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE,
  CONSTRAINT `fk_salmofood_ventas_clientes`
  FOREIGN KEY (`cliente_id`)
  REFERENCES `logpro`.`empresas` (`id`)
    ON DELETE RESTRICT
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `logpro`.`salmofood_ventas_solicitudes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `logpro`.`salmofood_ventas_solicitudes` (
  `venta_id`  VARCHAR(32) NOT NULL,
  `solicitud_id`  BIGINT UNSIGNED NOT NULL,
  PRIMARY KEY (`venta_id`, `solicitud_id`),
  INDEX `fk_salmofood_ventas_ventas` (`venta_id` ASC),
  INDEX `fk_salmofood_ventas_solicitudes` (`solicitud_id` ASC),
  CONSTRAINT `fk_salmofood_ventas_ventas`
  FOREIGN KEY (`venta_id`)
  REFERENCES `logpro`.`salmofood_ventas` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_salmofood_ventas_solicitudes`
  FOREIGN KEY (`solicitud_id`)
  REFERENCES `logpro`.`cargas_solicitadas` (`id`)
    ON DELETE CASCADE
    ON UPDATE CASCADE
)
  ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
SET SQL_MODE = @OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS = @OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS = @OLD_UNIQUE_CHECKS;