-- MySQL Script generated by MySQL Workbench
-- Tue Feb 13 15:17:23 2024
-- 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 NodeData
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `NodeData`.`enqueteAnswer`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`enqueteAnswer` (
  `AnswerID` INT NOT NULL,
  `NodeID` INT NOT NULL,
  `Result` VARCHAR(45) NULL,
  `enqueteDatacol` VARCHAR(45) NULL,
  `enqueteAnswerscol` VARCHAR(45) NULL,
  `Question_QuestionID` INT NOT NULL,
  PRIMARY KEY (`AnswerID`, `Question_QuestionID`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- 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,
  PRIMARY KEY (`NodeID`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `NodeData`.`Measurement`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `NodeData`.`Measurement` (
  `NodeID` INT NOT NULL,
  `Type` VARCHAR(45) NULL,
  `Value` FLOAT NULL,
  `TimeStamp` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
  `Node_NodeID` INT NOT NULL,
  PRIMARY KEY (`NodeID`, `Node_NodeID`),
  INDEX `fk_Measurement_Node1_idx` (`Node_NodeID` ASC) VISIBLE,
  CONSTRAINT `fk_Measurement_Node1`
    FOREIGN KEY (`Node_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 NULL AUTO_INCREMENT,
  PRIMARY KEY (`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;
