-- 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`.`alunos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`alunos` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `nome` VARCHAR(100) NOT NULL,
  `email_academico` VARCHAR(150) NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `email_academico_UNIQUE` (`email_academico` ASC) VISIBLE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`enderecos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`enderecos` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `CEP` CHAR(9) NOT NULL,
  `rua` VARCHAR(45) NULL,
  `complemento` VARCHAR(45) NULL,
  `alunos_id` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_enderecos_alunos_idx` (`alunos_id` ASC) VISIBLE,
  CONSTRAINT `fk_enderecos_alunos`
    FOREIGN KEY (`alunos_id`)
    REFERENCES `mydb`.`alunos` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`disciplinas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`disciplinas` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `nome` VARCHAR(100) NOT NULL,
  `descricao` VARCHAR(300) NOT NULL,
  `carga_horaria` INT NOT NULL,
  `obrigatoria` INT NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`professores`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`professores` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `nome` VARCHAR(100) NOT NULL,
  `email_academico` VARCHAR(150) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `email_academico_UNIQUE` (`email_academico` ASC) VISIBLE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`disciplinas_professores`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`disciplinas_professores` (
  `disciplinas_id` INT NULL,
  `professores_id` INT NULL,
  `id` INT NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_disciplinas_has_professores_professores1_idx` (`professores_id` ASC) VISIBLE,
  INDEX `fk_disciplinas_has_professores_disciplinas1_idx` (`disciplinas_id` ASC) VISIBLE,
  UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
  CONSTRAINT `fk_disciplinas_has_professores_disciplinas1`
    FOREIGN KEY (`disciplinas_id`)
    REFERENCES `mydb`.`disciplinas` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_disciplinas_has_professores_professores1`
    FOREIGN KEY (`professores_id`)
    REFERENCES `mydb`.`professores` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`alunos_disciplinas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`alunos_disciplinas` (
  `alunos_id` INT NULL,
  `disciplinas_id` INT NULL,
  `id` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`),
  INDEX `fk_alunos_has_disciplinas_disciplinas1_idx` (`disciplinas_id` ASC) VISIBLE,
  INDEX `fk_alunos_has_disciplinas_alunos1_idx` (`alunos_id` ASC) VISIBLE,
  CONSTRAINT `fk_alunos_has_disciplinas_alunos1`
    FOREIGN KEY (`alunos_id`)
    REFERENCES `mydb`.`alunos` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_alunos_has_disciplinas_disciplinas1`
    FOREIGN KEY (`disciplinas_id`)
    REFERENCES `mydb`.`disciplinas` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`faltas`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`faltas` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `alunos_id` INT NOT NULL,
  `professores_id` INT NOT NULL,
  `disciplinas_id` INT NOT NULL,
  `total_faltas` VARCHAR(45) NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_faltas_alunos1_idx` (`alunos_id` ASC) VISIBLE,
  INDEX `fk_faltas_professores1_idx` (`professores_id` ASC) VISIBLE,
  INDEX `fk_faltas_disciplinas1_idx` (`disciplinas_id` ASC) VISIBLE,
  CONSTRAINT `fk_faltas_alunos1`
    FOREIGN KEY (`alunos_id`)
    REFERENCES `mydb`.`alunos` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_faltas_professores1`
    FOREIGN KEY (`professores_id`)
    REFERENCES `mydb`.`professores` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_faltas_disciplinas1`
    FOREIGN KEY (`disciplinas_id`)
    REFERENCES `mydb`.`disciplinas` (`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;
