text: -- MySQL Script generated by MySQL Workbench
  -- sáb 05 jan 2019 11:25:14 -02
  -- Model: New Model    Version: 1.0
  -- MySQL Workbench Forward Engineering
  
  -- DATA_REGDROP SCHEMA catalog;
  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 catalog
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Schema catalog
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `catalog` DEFAULT CHARACTER SET utf8 ;
  USE `catalog` ;
  
  -- -----------------------------------------------------
  -- Table `catalog`.`USUARIO`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`USUARIO` (
    `ID_USER` INT NOT NULL AUTO_INCREMENT COMMENT '		',
    `EMAIL` VARCHAR(45) NOT NULL,
    `NOME` VARCHAR(45) NOT NULL,
    `SENHA` VARCHAR(255) NOT NULL,
    `DATA_REG` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
    `CEP` VARCHAR(9) NULL,
    `NOME_RUA` VARCHAR(120) NULL,
    `BAIRRO` VARCHAR(100) NULL,
    `NUMERO` INT(11) NULL,
    `CIDADE` VARCHAR(45) NULL,
    `ESTADO` VARCHAR(45) NULL,
    `PAIS` VARCHAR(45) NULL,
    `COMPLEMENTO` VARCHAR(100) NULL,
    `ADMIN` TINYINT(1) NOT NULL DEFAULT 0,
    `DATA_NASC` DATETIME NULL,
    UNIQUE INDEX `EMAIL_UNIQUE` (`EMAIL` ASC),
    UNIQUE INDEX `ID_USER_UNIQUE` (`ID_USER` ASC),
    PRIMARY KEY (`ID_USER`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `catalog`.`RECURSO`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`RECURSO` (
    `ID_RECURSO` INT NOT NULL AUTO_INCREMENT,
    `DATA_AD` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
    `CADASTRADOR` VARCHAR(45) NOT NULL,
    `TITULO` VARCHAR(100) NOT NULL UNIQUE,
    `IDIOMA` VARCHAR(45) NOT NULL,
    `DESCRICAO` LONGTEXT NOT NULL,
    `REPOSITORIO` VARCHAR(45) NOT NULL,
    `VERSAO` VARCHAR(45) NOT NULL,
    `STATUS` VARCHAR(45) NOT NULL,
    `ENTIDADE_CONTRIBUINTE` VARCHAR(100) NOT NULL,
    `FORMATO` VARCHAR(45) NOT NULL,
    `TAMANHO` INT(11) NOT NULL,
    `LOCALIZACAO` VARCHAR(200) NOT NULL,
    `REQUISITOS_TECNOLOGICOS` LONGTEXT NOT NULL,
    `INSTRUCOES_INSTALACAO` LONGTEXT NOT NULL,
    `DURACAO` INT(11) NULL,
    `TIPO_INTERATIVIDADE` VARCHAR(45) NOT NULL,
    `TIPO_RECURSO` VARCHAR(45) NOT NULL,
    `DESCRICAO_EDUCACIONAL` LONGTEXT NOT NULL,
    `CUSTO` TINYINT(1) NOT NULL,
    `CREATIVE_COMMONS` VARCHAR(45) NOT NULL,
    `COPYRIGHT` VARCHAR(45) NOT NULL,
    `APROVADO` TINYINT(1) DEFAULT 0,
    PRIMARY KEY (`ID_RECURSO`),
    INDEX `IND_TITULO` (`TITULO` ASC),
    INDEX `IND_IDIOMA` (`IDIOMA` ASC),
    INDEX `TIPO_RECURSO` (`TIPO_RECURSO` ASC),
    CONSTRAINT `FK_RECURSO_AUTOR`
    FOREIGN KEY (`CADASTRADOR`)
    REFERENCES `catalog`.`USUARIO` (`EMAIL`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `catalog`.`AUTOR_RECURSO`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`AUTOR_RECURSO` (
    `ID_RECURSO` INT NOT NULL,
    `NOME` VARCHAR(45) NOT NULL,
    INDEX `fk_AUTOR_RECURSO_RECURSO_idx` (`ID_RECURSO` ASC),
    PRIMARY KEY (`ID_RECURSO`, `NOME`),
    INDEX `FK_AUTOR_RECURSO_AUTOR_idx` (`NOME` ASC),
    CONSTRAINT `FK_AUTOR_RECURSO_AUTOR`
      FOREIGN KEY (`NOME`)
      REFERENCES `catalog`.`USUARIO` (`EMAIL`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_AUTOR_RECURSO_RECURSO`
      FOREIGN KEY (`ID_RECURSO`)
      REFERENCES `catalog`.`RECURSO` (`ID_RECURSO`)
      ON DELETE CASCADE
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `catalog`.`PALAVRASCHAVE`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`PALAVRASCHAVE` (
    `NOME` VARCHAR(80) NOT NULL,
    `ID_RECURSO` INT(11) NOT NULL,
    PRIMARY KEY (`NOME`, `ID_RECURSO`),
    INDEX `FK_PALAVRASCHAVE_RECURSO_idx` (`ID_RECURSO` ASC),
    CONSTRAINT `FK_PALAVRASCHAVE_RECURSO`
      FOREIGN KEY (`ID_RECURSO`)
      REFERENCES `catalog`.`RECURSO` (`ID_RECURSO`)
      ON DELETE CASCADE
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `catalog`.`NIVEIS`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`NIVEIS` (
    `NOME` VARCHAR(10) NOT NULL,
    `ID_RECURSO` INT(11) NOT NULL,
    PRIMARY KEY (`NOME`, `ID_RECURSO`),
    INDEX `FK_NIVEIS_RECURSO_idx` (`ID_RECURSO` ASC),
    CONSTRAINT `FK_NIVEIS_RECURSO`
      FOREIGN KEY (`ID_RECURSO`)
      REFERENCES `catalog`.`RECURSO` (`ID_RECURSO`)
      ON DELETE CASCADE
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `catalog`.`TECNICA`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`TECNICA` (
    `NOME` VARCHAR(80) NOT NULL,
    `ID_RECURSO` INT(11) NOT NULL,
    PRIMARY KEY (`NOME`, `ID_RECURSO`),
    INDEX `FK_TECNICA_RECURSO_idx` (`ID_RECURSO` ASC),
    CONSTRAINT `FK_TECNICA_RECURSO`
      FOREIGN KEY (`ID_RECURSO`)
      REFERENCES `catalog`.`RECURSO` (`ID_RECURSO`)
      ON DELETE CASCADE
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  -- -----------------------------------------------------
  -- Table `catalog`.`CRITERIOS`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `catalog`.`CRITERIO` (
    `NOME` VARCHAR(80) NOT NULL,
    `ID_RECURSO` INT(11) NOT NULL,
    PRIMARY KEY (`NOME`, `ID_RECURSO`),
    INDEX `FK_CRITERIOS_RECURSO_idx` (`ID_RECURSO` ASC),
    CONSTRAINT `FK_CRITERIOS_RECURSO`
      FOREIGN KEY (`ID_RECURSO`)
      REFERENCES `catalog`.`RECURSO` (`ID_RECURSO`)
      ON DELETE CASCADE
      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;
  