-- MySQL Script generated by MySQL Workbench
-- Wed 07 Feb 2018 07:08:36 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 newspen
-- -----------------------------------------------------

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

-- -----------------------------------------------------
-- Table `newspen`.`pub_permissions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`pub_permissions` (
  `permid` INT NOT NULL AUTO_INCREMENT,
  `permname` VARCHAR(45) NULL,
  PRIMARY KEY (`permid`),
  UNIQUE INDEX `permid_UNIQUE` (`permid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `newspen`.`page_sizes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`page_sizes` (
  `sizeid` INT NOT NULL AUTO_INCREMENT,
  `sizename` VARCHAR(45) NOT NULL,
  `sizewidth` VARCHAR(10) NOT NULL,
  `sizeheight` VARCHAR(10) NOT NULL,
  PRIMARY KEY (`sizeid`),
  UNIQUE INDEX `sizeid_UNIQUE` (`sizeid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `newspen`.`publications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`publications` (
  `pubid` INT NOT NULL AUTO_INCREMENT,
  `pubname` TEXT NOT NULL,
  `uid` INT NOT NULL,
  `pubdate` DATETIME NULL,
  `style` VARCHAR(50) NOT NULL,
  `columns` INT NOT NULL DEFAULT 2,
  `permid` INT NOT NULL,
  `pwd` VARCHAR(60) NULL,
  `page_size` INT NOT NULL,
  `landscape` TINYINT(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`pubid`),
  UNIQUE INDEX `pubid_UNIQUE` (`pubid` ASC),
  INDEX `fk_publications_pub_permissions1_idx` (`permid` ASC),
  INDEX `fk_publications_page_sizes1_idx` (`page_size` ASC),
  CONSTRAINT `fk_publications_pub_permissions1`
    FOREIGN KEY (`permid`)
    REFERENCES `newspen`.`pub_permissions` (`permid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_publications_page_sizes1`
    FOREIGN KEY (`page_size`)
    REFERENCES `newspen`.`page_sizes` (`sizeid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `newspen`.`tile_styles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`tile_styles` (
  `styleid` INT NOT NULL AUTO_INCREMENT,
  `css` MEDIUMTEXT NOT NULL,
  `stylename` VARCHAR(100) NOT NULL,
  `styledesc` TEXT NOT NULL,
  PRIMARY KEY (`styleid`),
  UNIQUE INDEX `styleid_UNIQUE` (`styleid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `newspen`.`tiles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`tiles` (
  `tileid` INT NOT NULL AUTO_INCREMENT,
  `pubid` INT NOT NULL,
  `page` INT NULL,
  `styleid` INT NOT NULL,
  `content` LONGTEXT NOT NULL,
  `width` INT NOT NULL DEFAULT 1,
  `order` INT NOT NULL DEFAULT 0,
  PRIMARY KEY (`tileid`, `pubid`),
  UNIQUE INDEX `tileid_UNIQUE` (`tileid` ASC),
  INDEX `fk_tiles_publications_idx` (`pubid` ASC),
  INDEX `fk_tiles_tile_styles1_idx` (`styleid` ASC),
  CONSTRAINT `fk_tiles_publications`
    FOREIGN KEY (`pubid`)
    REFERENCES `newspen`.`publications` (`pubid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tiles_tile_styles1`
    FOREIGN KEY (`styleid`)
    REFERENCES `newspen`.`tile_styles` (`styleid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `newspen`.`mail_lists`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`mail_lists` (
  `listid` INT NOT NULL AUTO_INCREMENT,
  `listname` VARCHAR(100) NOT NULL,
  `uid` INT NOT NULL,
  PRIMARY KEY (`listid`),
  UNIQUE INDEX `listid_UNIQUE` (`listid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `newspen`.`addresses`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `newspen`.`addresses` (
  `aid` INT NOT NULL AUTO_INCREMENT,
  `listid` INT NOT NULL,
  `email` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`aid`, `listid`),
  UNIQUE INDEX `aid_UNIQUE` (`aid` ASC),
  INDEX `fk_addresses_mail_lists1_idx` (`listid` ASC),
  CONSTRAINT `fk_addresses_mail_lists1`
    FOREIGN KEY (`listid`)
    REFERENCES `newspen`.`mail_lists` (`listid`)
    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;

-- -----------------------------------------------------
-- Data for table `newspen`.`pub_permissions`
-- -----------------------------------------------------
START TRANSACTION;
USE `newspen`;
INSERT INTO `newspen`.`pub_permissions` (`permid`, `permname`) VALUES (1, 'OWNER');
INSERT INTO `newspen`.`pub_permissions` (`permid`, `permname`) VALUES (2, 'LOGGEDIN');
INSERT INTO `newspen`.`pub_permissions` (`permid`, `permname`) VALUES (3, 'LINK');

COMMIT;


-- -----------------------------------------------------
-- Data for table `newspen`.`page_sizes`
-- -----------------------------------------------------
START TRANSACTION;
USE `newspen`;
INSERT INTO `newspen`.`page_sizes` (`sizeid`, `sizename`, `sizewidth`, `sizeheight`) VALUES (1, 'US Letter', '8.5in', '11in');
INSERT INTO `newspen`.`page_sizes` (`sizeid`, `sizename`, `sizewidth`, `sizeheight`) VALUES (2, 'A4', '210mm', '297mm');
INSERT INTO `newspen`.`page_sizes` (`sizeid`, `sizename`, `sizewidth`, `sizeheight`) VALUES (3, 'US Half Letter', '5.5in', '8.5in');
INSERT INTO `newspen`.`page_sizes` (`sizeid`, `sizename`, `sizewidth`, `sizeheight`) VALUES (4, 'US Legal', '8.5in', '14in');
INSERT INTO `newspen`.`page_sizes` (`sizeid`, `sizename`, `sizewidth`, `sizeheight`) VALUES (5, 'A3', '297mm', '420mm');
INSERT INTO `newspen`.`page_sizes` (`sizeid`, `sizename`, `sizewidth`, `sizeheight`) VALUES (6, 'A5', '148mm', '210mm');

COMMIT;


-- -----------------------------------------------------
-- Data for table `newspen`.`tile_styles`
-- -----------------------------------------------------
START TRANSACTION;
USE `newspen`;
INSERT INTO `newspen`.`tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (1, '', 'None', 'No style');
INSERT INTO `newspen`.`tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (2, 'box-shadow: 0px -1px 10px 5px rgba(0,0,0,0.75);\npadding: 3px;\nbackground-color: rgba(255,255,255,.75);', 'Shadow', 'Elevate your content with a shadow.');
INSERT INTO `newspen`.`tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (3, 'border: 1px solid var(--primary);\npadding: 1px 8px;', 'Line', 'A plain border.');
INSERT INTO `newspen`.`tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (4, 'border: 6px dotted var(--primary);\npadding: 0px 8px;', 'Dots', 'Large round dots.');
INSERT INTO `newspen`.`tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (5, 'border: 6px double var(--medium);\npadding: 0px 8px;', 'Double', 'A double line.');

COMMIT;

