-- 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 userdb
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `userdb`.`user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `userdb`.`user` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `active` VARCHAR(45) NOT NULL DEFAULT '1',
  `email` VARCHAR(45) NOT NULL,
  `title` VARCHAR(45) NOT NULL,
  `firstname` VARCHAR(45) NOT NULL,
  `lastname` VARCHAR(45) NOT NULL,
  `industry` VARCHAR(45) NULL,
  `organisation` VARCHAR(45) NULL,
  `speciality` VARCHAR(100) NULL,
  `createdDate` DATE NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `userdb`.`credential`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `userdb`.`credential` (
  `password` VARCHAR(255) NOT NULL,
  `resetPasswordToken` VARCHAR(255) NULL,
  `resetPasswordExpires` BIGINT(11) NULL,
  `user_id` INT NOT NULL,
  PRIMARY KEY (`user_id`),
  CONSTRAINT `fk_credential_user`
    FOREIGN KEY (`user_id`)
    REFERENCES `userdb`.`user` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `userdb`.`role`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `userdb`.`role` (
  `id` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `userdb`.`user_project_role`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `userdb`.`user_project_role` (
  `project_id` INT NOT NULL,
  `user_id` INT NOT NULL,
  `role_id` INT NOT NULL,
  PRIMARY KEY (`user_id`, `role_id`),
  INDEX `fk_user_project_role_role1_idx` (`role_id` ASC) VISIBLE,
  CONSTRAINT `fk_user_project_role_user1`
    FOREIGN KEY (`user_id`)
    REFERENCES `userdb`.`user` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_user_project_role_role1`
    FOREIGN KEY (`role_id`)
    REFERENCES `userdb`.`role` (`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;
