-- 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 Dokkie
-- Vervang hieronder de 'jouw_prefix_live' door je prefix in de HBO-ICT.Cloud, bijvoorbeeld pb1d1234_aaaaa_live
-- -----------------------------------------------------

USE `jouw_prefix_live`;

-- -----------------------------------------------------
-- Table `Dokkie`.`Event`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Event` (
  `eventId` INT NOT NULL AUTO_INCREMENT,
  `description` VARCHAR(100) NOT NULL,
  `dateCreated` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`eventId`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `Dokkie`.`User`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `User` (
  `userId` INT NOT NULL AUTO_INCREMENT,
  `email` VARCHAR(255) NOT NULL,
  `password` VARCHAR(45) NOT NULL,
  `username` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`userId`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `Dokkie`.`Participant`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Participant` (
  `eventId` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  `userId` INT NULL,
  PRIMARY KEY (`eventId`, `name`),
  INDEX `event_idx` (`eventId` ASC),
  INDEX `user_idx` (`userId` ASC),
  CONSTRAINT `fk_participant_event`
    FOREIGN KEY (`eventId`)
    REFERENCES `Event` (`eventId`)
    ON DELETE RESTRICT
    ON UPDATE RESTRICT,
  CONSTRAINT `fk_participant_user`
    FOREIGN KEY (`userId`)
    REFERENCES `User` (`userId`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;

-- -----------------------------------------------------
-- Table `Dokkie`.`Payment`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Payment` (
  `paymentId` INT NOT NULL AUTO_INCREMENT,
  `datePaid` DATE NOT NULL,
  `description` VARCHAR(100) NOT NULL,
  `amount` DOUBLE NOT NULL,
  `eventId` INT NOT NULL,
  `name` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`paymentId`),
  INDEX `participant_idx` (`eventId` ASC, `name` ASC),
  CONSTRAINT `fk_payment_participant`
    FOREIGN KEY (`eventId` , `name`)
    REFERENCES `Participant` (`eventId` , `name`)
    ON DELETE RESTRICT
    ON UPDATE RESTRICT)
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
