-- MySQL Script generated by MySQL Workbench
-- Tue 22 May 2018 01:42:53 AM MDT
-- 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
-- -----------------------------------------------------

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


-- -----------------------------------------------------
-- Table `page_sizes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `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 `publications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `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,
  `mailedon` DATETIME NULL,
  `mailedto` INT NULL,
  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 `pub_permissions` (`permid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_publications_page_sizes1`
    FOREIGN KEY (`page_size`)
    REFERENCES `page_sizes` (`sizeid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `tile_styles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `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 `tiles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `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 `publications` (`pubid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tiles_tile_styles1`
    FOREIGN KEY (`styleid`)
    REFERENCES `tile_styles` (`styleid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mail_lists`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `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 `addresses`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `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 `mail_lists` (`listid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `rate_limit`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `rate_limit` (
  `ipaddr` VARCHAR(45) NOT NULL,
  `lastaction` DATETIME NULL,
  PRIMARY KEY (`ipaddr`))
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 `pub_permissions`
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO `pub_permissions` (`permid`, `permname`) VALUES (1, 'OWNER');
INSERT INTO `pub_permissions` (`permid`, `permname`) VALUES (2, 'LOGGEDIN');
INSERT INTO `pub_permissions` (`permid`, `permname`) VALUES (3, 'LINK');

COMMIT;


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

COMMIT;


-- -----------------------------------------------------
-- Data for table `tile_styles`
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO `tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (1, '', 'None', 'No style');
INSERT INTO `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 `tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (3, 'border: 1px solid var(--primary);\npadding: 1px 8px;', 'Line', 'A plain border.');
INSERT INTO `tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (4, 'border: 6px dotted var(--primary);\npadding: 0px 8px;', 'Dots', 'Large round dots.');
INSERT INTO `tile_styles` (`styleid`, `css`, `stylename`, `styledesc`) VALUES (5, 'border: 6px double var(--medium);\npadding: 0px 8px;', 'Double', 'A double line.');

COMMIT;

