You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.7 KiB
SQL

-- MySQL Script generated by MySQL Workbench
-- Wed 09 Feb 2022 11:18:41 PM CET
-- 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 vujovicig
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema vujovicig
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `vujovicig` ;
USE `vujovicig` ;
-- -----------------------------------------------------
-- Table `vujovicig`.`user`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`user` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`user` (
`id` INT NOT NULL AUTO_INCREMENT,
`nick` VARCHAR(25) NOT NULL,
`mail` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `nick_UNIQUE` (`nick` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`brewery`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`brewery` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`brewery` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
`region` VARCHAR(45) NULL,
`description` MEDIUMTEXT NULL,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`beer`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`beer` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`beer` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
`alc` FLOAT NOT NULL,
`ibu` INT NULL,
`description` MEDIUMTEXT NULL,
`brewery_id` INT NOT NULL,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`degree` INT NULL,
PRIMARY KEY (`id`, `brewery_id`),
INDEX `fk_beer_brewery1_idx` (`brewery_id` ASC),
CONSTRAINT `fk_beer_brewery1`
FOREIGN KEY (`brewery_id`)
REFERENCES `vujovicig`.`brewery` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`tag`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`tag` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`tag` (
`id` INT NOT NULL AUTO_INCREMENT,
`tag_title` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `tag_title_UNIQUE` (`tag_title` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`follow`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`follow` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`follow` (
`user_id` INT NOT NULL,
`brewery_id` INT NOT NULL,
PRIMARY KEY (`user_id`, `brewery_id`),
INDEX `fk_user_has_brewery_brewery1_idx` (`brewery_id` ASC),
INDEX `fk_user_has_brewery_user_idx` (`user_id` ASC),
CONSTRAINT `fk_user_has_brewery_user`
FOREIGN KEY (`user_id`)
REFERENCES `vujovicig`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_user_has_brewery_brewery1`
FOREIGN KEY (`brewery_id`)
REFERENCES `vujovicig`.`brewery` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`list`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`list` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`list` (
`user_id` INT NOT NULL,
`beer_id` INT NOT NULL,
`rating` INT(5) NULL,
PRIMARY KEY (`user_id`, `beer_id`),
INDEX `fk_user_has_beer_beer1_idx` (`beer_id` ASC),
INDEX `fk_user_has_beer_user1_idx` (`user_id` ASC),
CONSTRAINT `fk_user_has_beer_user1`
FOREIGN KEY (`user_id`)
REFERENCES `vujovicig`.`user` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_user_has_beer_beer1`
FOREIGN KEY (`beer_id`)
REFERENCES `vujovicig`.`beer` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`beer_has_tag`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`beer_has_tag` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`beer_has_tag` (
`beer_id` INT NOT NULL,
`tag_id` INT NOT NULL,
PRIMARY KEY (`beer_id`, `tag_id`),
INDEX `fk_beer_has_tag_tag1_idx` (`tag_id` ASC),
INDEX `fk_beer_has_tag_beer1_idx` (`beer_id` ASC),
CONSTRAINT `fk_beer_has_tag_beer1`
FOREIGN KEY (`beer_id`)
REFERENCES `vujovicig`.`beer` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_beer_has_tag_tag1`
FOREIGN KEY (`tag_id`)
REFERENCES `vujovicig`.`tag` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `vujovicig`.`article`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `vujovicig`.`article` ;
CREATE TABLE IF NOT EXISTS `vujovicig`.`article` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NULL,
`body` MEDIUMTEXT NULL,
`time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;