CREATE TABLE COMMENT_TYPE (
  ORGANIZATION_ID NUMBER(10) NOT NULL, 
  ID NUMBER(10) NOT NULL, 
  CREATED_BY NUMBER(10) DEFAULT NULL NULL, 
  CREATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  UPDATED_BY NUMBER(10) DEFAULT NULL NULL, 
  UPDATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  STATUS VARCHAR2(1) DEFAULT 'A' NOT NULL, 
  NAME VARCHAR2(50) NOT NULL, 
  CONTROL VARCHAR2(1) NOT NULL, 
  ATTACHMENT_REQUIRED VARCHAR2(1) DEFAULT 'N' NOT NULL,
  CONSTRAINT COMMENT_TYPE_PK PRIMARY KEY(ID)
)
/
ALTER TABLE COMMENT_TYPE ADD CONSTRAINT CKC_C_TYPE_ATTACHMENT_REQUIRED CHECK (ATTACHMENT_REQUIRED IN ('Y', 'N'))
/
ALTER TABLE COMMENT_TYPE ADD CONSTRAINT CKC_COMMENT_TYPE_STATUS CHECK (STATUS IN ('A', 'I', 'D'))
/
CREATE SEQUENCE COMMENT_TYPE_ID_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1
/
CREATE TABLE TASK_TYPE_COMMENT_TYPE (
  ORGANIZATION_ID NUMBER(10) NOT NULL, 
  ID NUMBER(10) NOT NULL, 
  CREATED_BY NUMBER(10) DEFAULT NULL NULL, 
  CREATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  UPDATED_BY NUMBER(10) DEFAULT NULL NULL, 
  UPDATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  TASK_TYPE_ID NUMBER(10) NOT NULL, 
  COMMENT_TYPE_ID NUMBER(10) NOT NULL, 
  IN_OUT_COMMENT VARCHAR2(1) DEFAULT 'O' NOT NULL, 
  ACTION_LABEL VARCHAR2(50) DEFAULT NULL NULL, 
  STATUS VARCHAR2(1) DEFAULT 'A' NOT NULL, 
  TASK_TYPE_TARGET NUMBER(10) DEFAULT NULL NULL,
  CONSTRAINT TASK_TYPE_COMMENT_TYPE_PK PRIMARY KEY(ID)
)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE ADD CONSTRAINT T_TYPE_C_TYPE_TASK_TYPE_FK FOREIGN KEY (TASK_TYPE_ID) REFERENCES TASK_TYPE (ID)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE ADD CONSTRAINT T_TYPE_C_TYPE_COMMENT_TYPE_FK FOREIGN KEY (COMMENT_TYPE_ID) REFERENCES COMMENT_TYPE (ID)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE ADD CONSTRAINT T_TYPE_C_TYPE_T_TYPE_TARGET_FK FOREIGN KEY (TASK_TYPE_TARGET) REFERENCES TASK_TYPE (ID)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE ADD CONSTRAINT CKC_T_TYPE_C_TYPE_STATUS CHECK (STATUS in ('A', 'I', 'D'))
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE ADD CONSTRAINT CKC_T_TYPE_C_TYPE_INOUTCOMMENT CHECK (IN_OUT_COMMENT in ('I', 'O'))
/
CREATE SEQUENCE TASK_TYPE_COMMENT_TYPE_ID_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1
/
CREATE TABLE TASK_TYPE_COMMENT_TYPE_CLASSIF (
  ORGANIZATION_ID NUMBER(10) NOT NULL, 
  ID NUMBER(10) NOT NULL, 
  CREATED_BY NUMBER(10) DEFAULT NULL NULL, 
  CREATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  UPDATED_BY NUMBER(10) DEFAULT NULL NULL, 
  UPDATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  STATUS VARCHAR2(1) DEFAULT 'A' NOT NULL, 
  TASK_TYPE_COMMENT_TYPE_ID NUMBER(10) NOT NULL, 
  CLASSIFICATION_ID NUMBER(10) NOT NULL,
  CONSTRAINT T_TYPE_C_TYPE_CLASSIF_PK PRIMARY KEY(ID)
)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE_CLASSIF ADD CONSTRAINT TTYPE_CTYPE_C_TTYPE_CTYPE_FK FOREIGN KEY (TASK_TYPE_COMMENT_TYPE_ID) REFERENCES TASK_TYPE_COMMENT_TYPE (ID)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE_CLASSIF ADD CONSTRAINT TTYPE_CTYPE_C_CLASSIF_FK FOREIGN KEY (CLASSIFICATION_ID) REFERENCES CLASSIFICATION (ID)
/
ALTER TABLE TASK_TYPE_COMMENT_TYPE_CLASSIF ADD CONSTRAINT CKC_T_TYPE_C_TYPE_CLASS_STATUS CHECK (STATUS in ('A', 'I', 'D'))
/
CREATE SEQUENCE T_TYPE_C_TYPE_CLASSIF_ID_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1
/
CREATE TABLE TASK_TYPE_CLASSIFICATION (
  ORGANIZATION_ID NUMBER(10) NOT NULL, 
  ID NUMBER(10) NOT NULL, 
  CREATED_BY NUMBER(10) DEFAULT NULL NULL, 
  CREATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  UPDATED_BY NUMBER(10) DEFAULT NULL NULL, 
  UPDATED_AT DATE DEFAULT SYSDATE NOT NULL, 
  STATUS VARCHAR2(1) DEFAULT 'A' NOT NULL, 
  TASK_TYPE_ID NUMBER(10) NOT NULL, 
  CLASSIFICATION_ID NUMBER(10) NOT NULL, 
  TASK_ISSUE_CLASSIF VARCHAR2(1) DEFAULT 'T' NOT NULL,
  CONSTRAINT TASK_TYPE_CLASSIFICATION_PK PRIMARY KEY(ID)
)
/
ALTER TABLE TASK_TYPE_CLASSIFICATION ADD CONSTRAINT TTYPE_CLASSIF_TASK_TYPE_FK FOREIGN KEY (TASK_TYPE_ID) REFERENCES TASK_TYPE (ID)
/
ALTER TABLE TASK_TYPE_CLASSIFICATION ADD CONSTRAINT TTYPE_CLASSIF_CLASSIF_FK FOREIGN KEY (CLASSIFICATION_ID) REFERENCES CLASSIFICATION (ID)
/
ALTER TABLE TASK_TYPE_CLASSIFICATION ADD CONSTRAINT CKC_TASK_TYPE_CLASSIF_STATUS CHECK (STATUS in ('A', 'I', 'D'))
/
ALTER TABLE TASK_TYPE_CLASSIFICATION ADD CONSTRAINT CKC_TTYPE_C_TASK_ISSUE_CLASSIF CHECK (TASK_ISSUE_CLASSIF in ('T', 'I', 'E'))
/
CREATE SEQUENCE TASK_TYPE_CLASSIF_ID_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1
/
ALTER TABLE ATTACHMENT ADD (
  COMMENTS NUMBER(10) DEFAULT NULL NULL
)
/
ALTER TABLE ATTACHMENT ADD CONSTRAINT ATTACHMENT_COMMENTS_FK FOREIGN KEY (COMMENTS) REFERENCES COMMENTS (ID)
/
ALTER TABLE TASK_TYPE ADD (
  TIME_AUTO_CHANGE_STATUS NUMBER(10) DEFAULT NULL NULL, 
  TASK_STATUS_AUTO_CHANGE_STATUS NUMBER(10) DEFAULT NULL NULL,
)
/
ALTER TABLE TASK_TYPE ADD CONSTRAINT TASK_TYPE_TASK_STATUS_AUTO_FK FOREIGN KEY (TASK_STATUS_AUTO_CHANGE_STATUS) REFERENCES TASK_STATUS (ID)
/
ALTER TABLE TASK ADD (
  CURRENT_TASK_STATUS_IN DATE DEFAULT NULL NULL
)
/