text: -- MySQL Script generated by MySQL Workbench
  -- Sun Nov 24 16:21:54 2019
  -- 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 events
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Schema events
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `events` DEFAULT CHARACTER SET utf8mb4 ;
  USE `events` ;
  
  -- -----------------------------------------------------
  -- Table `event`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `event` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `event_id` VARCHAR(36) NOT NULL,
    `version` INT NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `start_date` DATETIME NOT NULL,
    `price` DECIMAL(13,4) NOT NULL,
    `image_url` VARCHAR(2048) NOT NULL,
    `online_url` VARCHAR(2048) NULL,
    `created_at` DATETIME NOT NULL,
    `created_by` BIGINT NOT NULL,
    `updated_at` DATETIME NULL,
    `updated_by` BIGINT NULL,
    `active` BIT(1) NOT NULL DEFAULT 1,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB;
  
  CREATE UNIQUE INDEX `event_id_UNIQUE` ON `event` (`event_id` ASC) VISIBLE;
  
  CREATE INDEX `name_idx` ON `event` (`name` ASC) VISIBLE;
  
  CREATE INDEX `start_date` ON `event` (`start_date` ASC) VISIBLE;
  
  CREATE INDEX `price` ON `event` (`price` ASC) VISIBLE;
  
  
  -- -----------------------------------------------------
  -- Table `session`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `session` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `session_id` VARCHAR(36) NOT NULL,
    `event_id` BIGINT NOT NULL,
    `version` INT NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `description` TEXT NOT NULL,
    `level` VARCHAR(12) NOT NULL,
    `duration` TIME NOT NULL,
    `presenter` VARCHAR(120) NOT NULL,
    `created_at` DATETIME NOT NULL,
    `created_by` BIGINT NOT NULL,
    `updated_at` DATETIME NULL,
    `updated_by` BIGINT NULL,
    `active` BIT(1) NOT NULL DEFAULT 1,
    PRIMARY KEY (`id`),
    CONSTRAINT `fk_session_event1`
      FOREIGN KEY (`event_id`)
      REFERENCES `event` (`id`)
      ON DELETE RESTRICT
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  
  CREATE UNIQUE INDEX `session_id_UNIQUE` ON `session` (`session_id` ASC) VISIBLE;
  
  CREATE INDEX `name_idx` ON `session` (`name` ASC) VISIBLE;
  
  CREATE INDEX `level_duration_idx` ON `session` (`level` ASC, `duration` ASC) VISIBLE;
  
  CREATE INDEX `presenter_idx` ON `session` (`presenter` ASC) VISIBLE;
  
  CREATE INDEX `fk_session_event1_idx` ON `session` (`event_id` ASC) VISIBLE;
  
  
  -- -----------------------------------------------------
  -- Table `location`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `location` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `location_id` VARCHAR(36) NOT NULL,
    `event_id` BIGINT NOT NULL,
    `version` INT NOT NULL,
    `country` VARCHAR(60) NOT NULL,
    `city` VARCHAR(60) NOT NULL,
    `address` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`id`),
    CONSTRAINT `fk_location_event`
      FOREIGN KEY (`event_id`)
      REFERENCES `event` (`id`)
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  
  CREATE UNIQUE INDEX `location_id_UNIQUE` ON `location` (`location_id` ASC) VISIBLE;
  
  CREATE INDEX `fk_location_event_idx` ON `location` (`event_id` ASC) VISIBLE;
  
  
  -- -----------------------------------------------------
  -- Table `user`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `user` (
    `id` BIGINT NOT NULL AUTO_INCREMENT,
    `user_id` VARCHAR(36) NOT NULL,
    `first_name` VARCHAR(60) NULL,
    `last_name` VARCHAR(60) NULL,
    `email` VARCHAR(64) NOT NULL,
    `password` VARCHAR(80) NOT NULL,
    `enabled` BIT(1) NULL,
    PRIMARY KEY (`id`))
  ENGINE = InnoDB;
  
  CREATE UNIQUE INDEX `user_id_UNIQUE` ON `user` (`user_id` ASC) VISIBLE;
  
  CREATE UNIQUE INDEX `email_UNIQUE` ON `user` (`email` ASC) VISIBLE;
  
  CREATE INDEX `full_name_IDX` ON `user` (`first_name` ASC, `last_name` ASC) VISIBLE;
  
  
  -- -----------------------------------------------------
  -- Table `user_session_votes`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `user_session_votes` (
    `user_id` BIGINT NOT NULL,
    `session_id` BIGINT NOT NULL,
    `created_at` DATETIME NOT NULL,
    PRIMARY KEY (`user_id`, `session_id`),
    CONSTRAINT `fk_user_session_user1`
      FOREIGN KEY (`user_id`)
      REFERENCES `user` (`id`)
      ON DELETE CASCADE
      ON UPDATE CASCADE,
    CONSTRAINT `fk_user_session_session1`
      FOREIGN KEY (`session_id`)
      REFERENCES `session` (`id`)
      ON DELETE CASCADE
      ON UPDATE CASCADE)
  ENGINE = InnoDB;
  
  CREATE INDEX `fk_user_session_session1_idx` ON `user_session_votes` (`session_id` ASC) VISIBLE;
  
  CREATE INDEX `fk_user_session_user1_idx` ON `user_session_votes` (`user_id` ASC) VISIBLE;
  
  
  SET SQL_MODE=@OLD_SQL_MODE;
  SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  