-- MySQL Script generated by MySQL Workbench
-- 07/21/15 14:45:55
-- 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='STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Table `zzzNodeWorksetT`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `zzzNodeWorksetT` ;

CREATE TABLE IF NOT EXISTS `zzzNodeWorksetT` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `connId` BIGINT UNSIGNED NOT NULL,
  `nodeId` INT UNSIGNED NOT NULL,
  `isMain` INT UNSIGNED NOT NULL DEFAULT 1,
  `isExact` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '0 - not exact node\n1 - exactly dest or indifferent\n2 - exactly src',
  `isLinked` INT UNSIGNED NOT NULL DEFAULT 0,
  `added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  INDEX `added_idx` (`added` ASC),
  INDEX `connid_nodeid_ismain_idx` (`connId` ASC, `nodeId` ASC, `isMain` ASC),
  UNIQUE INDEX `nodeid_connid_uq` (`nodeId` ASC, `connId` ASC),
  INDEX `connid_isexact_idx` (`connId` ASC, `isExact` ASC),
  INDEX `connid_islinked_idx` (`connId` ASC, `isLinked` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `zzzNodeQueueT`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `zzzNodeQueueT` ;

CREATE TABLE IF NOT EXISTS `zzzNodeQueueT` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `nodeId` INT UNSIGNED NOT NULL,
  `isLinked` INT UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  INDEX `islinked_idx` (`isLinked` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Placeholder table for view `zzzNodeWorksetV`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `zzzNodeWorksetV` (`connId` INT, `nodeId` INT, `isMain` INT, `isExact` INT, `isLinked` INT, `added` INT);

-- -----------------------------------------------------
-- View `zzzNodeWorksetV`
-- -----------------------------------------------------
DROP VIEW IF EXISTS `zzzNodeWorksetV` ;
DROP TABLE IF EXISTS `zzzNodeWorksetV`;
CREATE  OR REPLACE VIEW zzzNodeWorksetV AS
select 
    connId,
    nodeId,
    isMain,
    isExact,
    isLinked,
    added
from zzzNodeWorksetT
where connId = connection_id();


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