text: -- MySQL Script generated by MySQL Workbench
  -- Mon Jun 24 19:02:28 2019
  -- Model: New Model    Version: 1.0
  -- 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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
  
  -- -----------------------------------------------------
  -- Schema mydb
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Schema mydb
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
  USE `mydb` ;
  
  -- -----------------------------------------------------
  -- Table `mydb`.`usuario`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`usuario` (
    `id` INT NOT NULL,
    `usuario` VARCHAR(50) NOT NULL,
    `password` VARCHAR(100) NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `mydb`.`libro`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`libro` (
    `id` INT NOT NULL,
    `titulo` VARCHAR(100) NOT NULL,
    `edi` VARCHAR(30) NOT NULL,
    `autor` VARCHAR(100) NOT NULL,
    `cantidad` TINYINT(2) NOT NULL,
    `editorial` VARCHAR(50) NULL,
    `foto` VARCHAR(100) NULL,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `mydb`.`libro_prestamo`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`libro_prestamo` (
    `id` INT NOT NULL,
    `fecha_prestamo` DATE NOT NULL,
    `estado` TINYINT(1) NOT NULL,
    `fecha_devolucion` DATE NULL,
    `prestamo` VARCHAR(100) NOT NULL,
    `usuario_id` INT NOT NULL,
    `libro_id` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_libro_prestamo_usuario_idx` (`usuario_id` ASC) VISIBLE,
    INDEX `fk_libro_prestamo_libro1_idx` (`libro_id` ASC) VISIBLE,
    CONSTRAINT `fk_libro_prestamo_usuario`
      FOREIGN KEY (`usuario_id`)
      REFERENCES `mydb`.`usuario` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_libro_prestamo_libro1`
      FOREIGN KEY (`libro_id`)
      REFERENCES `mydb`.`libro` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `mydb`.`rol`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`rol` (
    `id` INT NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `mydb`.`usuario_rol`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`usuario_rol` (
    `id` INT NOT NULL,
    `estado` TINYINT(1) NOT NULL,
    `rol_id` INT NOT NULL,
    `usuario_id1` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_usuario_rol_rol1_idx` (`rol_id` ASC) VISIBLE,
    INDEX `fk_usuario_rol_usuario1_idx` (`usuario_id1` ASC) VISIBLE,
    CONSTRAINT `fk_usuario_rol_rol1`
      FOREIGN KEY (`rol_id`)
      REFERENCES `mydb`.`rol` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_usuario_rol_usuario1`
      FOREIGN KEY (`usuario_id1`)
      REFERENCES `mydb`.`usuario` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `mydb`.`permiso`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`permiso` (
    `id` INT NOT NULL,
    `nombre` VARCHAR(50) NOT NULL,
    `slug` VARCHAR(50) NOT NULL,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `mydb`.`permiso_rol`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `mydb`.`permiso_rol` (
    `id` INT NOT NULL,
    `rol_id` INT NOT NULL,
    `permiso_id` INT NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fk_permiso_rol_rol1_idx` (`rol_id` ASC) VISIBLE,
    INDEX `fk_permiso_rol_permiso1_idx` (`permiso_id` ASC) VISIBLE,
    CONSTRAINT `fk_permiso_rol_rol1`
      FOREIGN KEY (`rol_id`)
      REFERENCES `mydb`.`rol` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_permiso_rol_permiso1`
      FOREIGN KEY (`permiso_id`)
      REFERENCES `mydb`.`permiso` (`id`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  SET SQL_MODE=@OLD_SQL_MODE;
  SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  