-- MySQL Script generated by MySQL Workbench
-- Wed Jan  8 11:06:08 2020
-- 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 = 'TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema simple-vote
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `simple-vote`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `simple-vote`.`users`
(
    `idusers`  INT          NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(45)  NOT NULL,
    `email`    VARCHAR(45)  NOT NULL,
    `password` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`idusers`),
    UNIQUE INDEX `username_UNIQUE` (`username` ASC),
    UNIQUE INDEX `email_UNIQUE` (`email` ASC)
)
    ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `simple-vote`.`surveys`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `simple-vote`.`surveys`
(
    `idsurveys`   INT          NOT NULL AUTO_INCREMENT,
    `question`       VARCHAR(255) NOT NULL,
    `description` VARCHAR(255) NULL,
    `answers`     VARCHAR(255) NOT NULL,
    `fkuser`      INT          NOT NULL,
    PRIMARY KEY (`idsurveys`),
    INDEX `fkuser_idx` (`fkuser` ASC),
    CONSTRAINT `fkuser`
        FOREIGN KEY (`fkuser`)
            REFERENCES `simple-vote`.`users` (`idusers`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION
)
    ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `simple-vote`.`votes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `simple-vote`.`votes`
(
    `idvotes`      INT NOT NULL AUTO_INCREMENT,
    `fksurveys`    INT NOT NULL,
    `votesAnswer1` INT NOT NULL DEFAULT 0,
    `votesAnswer2` INT NOT NULL DEFAULT 0,
    PRIMARY KEY (`idvotes`),
    INDEX `fksurveys_idx` (`fksurveys` ASC),
    CONSTRAINT `fksurveys`
        FOREIGN KEY (`fksurveys`)
            REFERENCES `simple-vote`.`surveys` (`idsurveys`)
            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;
