-- MySQL Script generated by MySQL Workbench
-- Tue 26 Dec 2017 04:44:44 PM MST
-- 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 inventory
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `inventory`.`categories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory`.`categories` (
  `catid` INT NOT NULL AUTO_INCREMENT,
  `catname` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`catid`),
  UNIQUE INDEX `catid_UNIQUE` (`catid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `inventory`.`locations`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory`.`locations` (
  `locid` INT NOT NULL AUTO_INCREMENT,
  `locname` VARCHAR(100) NOT NULL,
  `loccode` VARCHAR(45) NOT NULL,
  `locinfo` VARCHAR(500) NULL,
  PRIMARY KEY (`locid`),
  UNIQUE INDEX `locid_UNIQUE` (`locid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `inventory`.`items`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory`.`items` (
  `itemid` INT NOT NULL AUTO_INCREMENT,
  `catid` INT NOT NULL,
  `locid` INT NOT NULL,
  `name` VARCHAR(100) NOT NULL,
  `code1` VARCHAR(50) NOT NULL,
  `code2` VARCHAR(50) NOT NULL,
  `text1` TEXT(500) NOT NULL,
  `text2` TEXT(500) NOT NULL,
  `text3` TEXT(500) NOT NULL,
  `qty` INT NOT NULL DEFAULT 1,
  `want` INT NOT NULL DEFAULT 0,
  `userid` INT NULL,
  PRIMARY KEY (`itemid`, `catid`, `locid`),
  INDEX `fk_items_categories_idx` (`catid` ASC),
  INDEX `fk_items_locations1_idx` (`locid` ASC),
  UNIQUE INDEX `itemid_UNIQUE` (`itemid` ASC),
  CONSTRAINT `fk_items_categories`
    FOREIGN KEY (`catid`)
    REFERENCES `inventory`.`categories` (`catid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_items_locations1`
    FOREIGN KEY (`locid`)
    REFERENCES `inventory`.`locations` (`locid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `inventory`.`labels`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory`.`labels` (
  `rowid` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(50) NOT NULL,
  `value` VARCHAR(100) NOT NULL,
  PRIMARY KEY (`rowid`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `inventory`.`permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory`.`permissions` (
  `userid` INT NOT NULL,
  `itemid` INT NOT NULL,
  `canedit` TINYINT(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`userid`, `itemid`),
  INDEX `fk_permissions_items1_idx` (`itemid` ASC),
  CONSTRAINT `fk_permissions_items1`
    FOREIGN KEY (`itemid`)
    REFERENCES `inventory`.`items` (`itemid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `inventory`.`report_access_codes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `inventory`.`report_access_codes` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `code` VARCHAR(45) NULL,
  `expires` DATETIME NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `id_UNIQUE` (`id` ASC))
ENGINE = InnoDB;


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