-- -----------------------------------------------------
-- Table commentT
-- -----------------------------------------------------
DROP TABLE IF EXISTS commentT ;

CREATE TABLE IF NOT EXISTS commentT (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  parentCommentId BIGINT UNSIGNED NULL,
  objectNodeId INT UNSIGNED NOT NULL COMMENT 'object being commented',
  authorUserId INT UNSIGNED NULL COMMENT 'author id',
  userName VARCHAR(255) NOT NULL,
  privateUserId INT UNSIGNED NULL,
  value TEXT NOT NULL,
  added TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
  changed TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  INDEX fk_commentT_commentT1_idx (parentCommentId ASC) ,
  INDEX fk_commentT_userT1_idx (authorUserId ASC) ,
  INDEX fk_commentT_nodeT1_idx (objectNodeId ASC) ,
  INDEX fk_commentT_userT2_idx (privateUserId ASC) ,
  CONSTRAINT fk_commentT_commentT1
    FOREIGN KEY (parentCommentId)
    REFERENCES commentT (id)
    ON DELETE CASCADE
    ON UPDATE NO ACTION,
  CONSTRAINT fk_commentT_userT1
    FOREIGN KEY (authorUserId)
    REFERENCES userT (id)
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT fk_commentT_nodeT1
    FOREIGN KEY (objectNodeId)
    REFERENCES nodeT (id)
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT fk_commentT_userT2
    FOREIGN KEY (privateUserId)
    REFERENCES userT (id)
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;
