-- MySQL Script generated by MySQL Workbench
-- Wed 28 Nov 2018 10:54:14 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 notepost
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Table `notes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `notes` (
  `noteid` INT NOT NULL AUTO_INCREMENT,
  `ownerid` INT NOT NULL,
  `color` VARCHAR(6) NOT NULL DEFAULT 'FFFFFF',
  `content` LONGTEXT NULL,
  `title` TINYTEXT NULL,
  `modified` DATETIME NULL,
  `favorite` TINYINT(1) NOT NULL DEFAULT 0,
  `archived` TINYINT(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`noteid`, `ownerid`),
  UNIQUE INDEX `noteid_UNIQUE` (`noteid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `sharing`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `sharing` (
  `noteid` INT NOT NULL,
  `uid` INT NOT NULL,
  `writable` TINYINT(1) NOT NULL DEFAULT 0,
  `publicid` VARCHAR(45) NULL,
  PRIMARY KEY (`noteid`),
  CONSTRAINT `fk_sharing_notes`
    FOREIGN KEY (`noteid`)
    REFERENCES `notes` (`noteid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `reminders`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `reminders` (
  `reminderid` INT NOT NULL AUTO_INCREMENT,
  `noteid` INT NOT NULL,
  `when` DATETIME NOT NULL,
  PRIMARY KEY (`reminderid`, `noteid`),
  UNIQUE INDEX `reminderid_UNIQUE` (`reminderid` ASC),
  INDEX `fk_reminders_notes1_idx` (`noteid` ASC),
  CONSTRAINT `fk_reminders_notes1`
    FOREIGN KEY (`noteid`)
    REFERENCES `notes` (`noteid`)
    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;
