-- MySQL Script generated by MySQL Workbench
-- Wed Mar 13 16:04:58 2024
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering
-- CHANGE NODEID TO AUTO INCREMENET IN NODE TABLE
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 NodeData
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema NodeData
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `NodeData` DEFAULT CHARACTER SET utf8 ;
USE `NodeData` ;

-- -----------------------------------------------------
-- Table `NodeData`.`Question`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`Question` (
  `QuestionID` INT NOT NULL,
  `Question` VARCHAR(45) NULL,
  PRIMARY KEY (`QuestionID`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `NodeData`.`Node`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`Node` (
  `NodeID` INT NOT NULL,
  `Name` VARCHAR(45) NULL,
  `Location` VARCHAR(45) NULL,
  `MAC` VARCHAR(45) NULL,
  PRIMARY KEY (`NodeID`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `NodeData`.`Measurement`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`Measurement` (
  `NodeID` INT NOT NULL,
  `TimeStamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `Type` VARCHAR(45) NULL,
  `Value` FLOAT NULL,
  CONSTRAINT `fk_Measurement_Node1`
    FOREIGN KEY (`NodeID`)
    REFERENCES `NodeData`.`Node` (`NodeID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `NodeData`.`Enquete`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`Enquete` (
  `EnqueteID` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`EnqueteID`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `NodeData`.`enqueteQuestion`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`enqueteQuestion` (
  `Enquete_EnqueteID` INT NOT NULL,
  `Question_QuestionID` INT NOT NULL,
  PRIMARY KEY (`Enquete_EnqueteID`, `Question_QuestionID`),
  INDEX `fk_Enquete_has_Question_Question1_idx` (`Question_QuestionID` ASC) VISIBLE,
  INDEX `fk_Enquete_has_Question_Enquete1_idx` (`Enquete_EnqueteID` ASC) VISIBLE,
  CONSTRAINT `fk_Enquete_has_Question_Enquete1`
    FOREIGN KEY (`Enquete_EnqueteID`)
    REFERENCES `NodeData`.`Enquete` (`EnqueteID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Enquete_has_Question_Question1`
    FOREIGN KEY (`Question_QuestionID`)
    REFERENCES `NodeData`.`Question` (`QuestionID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `NodeData`.`Reply`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`Reply` (
  `Node_NodeID` INT NOT NULL,
  `enqueteQuestion_Enquete_EnqueteID` INT NOT NULL,
  `enqueteQuestion_Question_QuestionID` INT NOT NULL,
  `Result` INT NULL,
  `Time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  `AnswerID` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`AnswerID`, `Node_NodeID`, `enqueteQuestion_Enquete_EnqueteID`, `enqueteQuestion_Question_QuestionID`),
  INDEX `fk_Node_has_enqueteQuestion_enqueteQuestion1_idx` (`enqueteQuestion_Enquete_EnqueteID` ASC, `enqueteQuestion_Question_QuestionID` ASC) VISIBLE,
  INDEX `fk_Node_has_enqueteQuestion_Node1_idx` (`Node_NodeID` ASC) VISIBLE,
  CONSTRAINT `fk_Node_has_enqueteQuestion_Node1`
    FOREIGN KEY (`Node_NodeID`)
    REFERENCES `NodeData`.`Node` (`NodeID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Node_has_enqueteQuestion_enqueteQuestion1`
    FOREIGN KEY (`enqueteQuestion_Enquete_EnqueteID` , `enqueteQuestion_Question_QuestionID`)
    REFERENCES `NodeData`.`enqueteQuestion` (`Enquete_EnqueteID` , `Question_QuestionID`)
    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;
