--
--    Licensed Materials - Property of IBM
--    
--    BI and PM: HTS
--    
--    (c) Copyright IBM Corp. 2003, 2011.
--    
--    US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
--    

--
--  Modifications:
--
--  1) Change NCCOG  to the desired database name.
--  2) Note: CCSID is an estimated value, your
--           requirements may differ.

-------------------------------------------------------------------------------
-- HTS_CREATE_Hsql.sql         *  DO NOT EDIT  *          Data Store Version: 2
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$200-- tables create begin
-------------------------------------------------------------------------------

CREATE TABLE HTS_ATTACHMENT(
    attachmentId VARCHAR(50) NOT NULL,
    accessType VARCHAR(250) NOT NULL,
    attachURI VARCHAR(50),
    attachedAt BIGINT NOT NULL,
    attachedBy VARCHAR(250) NOT NULL,
    contentType VARCHAR(250) NOT NULL,
    lang VARCHAR(10),
    linkId VARCHAR(50),
    name VARCHAR(250) NOT NULL,
    value CLOB(1M)
) IN NCCOG.HTSATTAC CCSID UNICODE;

CREATE AUX TABLE HTS_ATTAAUX
      IN NCCOG.HTSLOBAT
      STORES HTS_ATTACHMENT
      COLUMN value;

CREATE TABLE HTS_CALLBACK(
    callbackId VARCHAR(50) NOT NULL,
    action VARCHAR(250),
    address VARCHAR(250),
    credential VARCHAR(250),
    operation VARCHAR(250)
) IN NCCOG.HTSCLBCK CCSID UNICODE;

CREATE TABLE HTS_CALLBACKPARAM(
    callbackParamId VARCHAR(50) NOT NULL,
    qname VARCHAR(250),
    value CLOB(1M),
    callbackId VARCHAR(50)
) IN NCCOG.HTSCBPAR CCSID UNICODE;

CREATE AUX TABLE HTS_CALLBAUX
      IN NCCOG.HTSLOBCP
      STORES HTS_CALLBACKPARAM
      COLUMN value;

CREATE TABLE HTS_DEADLINE(
    deadlineId VARCHAR(50) NOT NULL,
    deadlineType VARCHAR(50) NOT NULL,
    timeForExpression VARCHAR(250),
    timeUntilExpression VARCHAR(250)
) IN NCCOG.HTSHDLNE CCSID UNICODE;

CREATE TABLE HTS_DEADLINE_INSTANCE(
    deadlineInstanceId VARCHAR(50) NOT NULL,
    deadlineSignature VARCHAR(250),
    timeout BIGINT,
    taskId VARCHAR(50)
) IN NCCOG.HTSDDLNE CCSID UNICODE;

CREATE TABLE HTS_ESCALATION(
    escalationId VARCHAR(50) NOT NULL,
    conditionExpression VARCHAR(250),
    localNotificationId VARCHAR(50)
) IN NCCOG.HTSESCAL CCSID UNICODE;

CREATE TABLE HTS_ESCALATION_HUMANROLES(
    escalationHumanRolesId VARCHAR(50) NOT NULL,
    fromExpression VARCHAR(250),
    roleName VARCHAR(50) NOT NULL,
    userId VARCHAR(50)
) IN NCCOG.HTSESCHR CCSID UNICODE;

CREATE TABLE HTS_ESCALATION_TO_PART(
    toPartId VARCHAR(50) NOT NULL,
    expression VARCHAR(250),
    name VARCHAR(250)
) IN NCCOG.HTSESCTP CCSID UNICODE;

CREATE TABLE HTS_FOLDER(
    folderId VARCHAR(50) NOT NULL,
    folderName VARCHAR(125),
    folderType VARCHAR(250),
    taskId VARCHAR(50),
    userId VARCHAR(50)
) IN NCCOG.HTSFOLDE CCSID UNICODE;

CREATE TABLE HTS_HUMANROLE(
    humanRoleId VARCHAR(50) NOT NULL,
    roleName VARCHAR(50) NOT NULL,
    taskId VARCHAR(50),
    userId VARCHAR(50)
) IN NCCOG.HTSHUMRL CCSID UNICODE;

CREATE TABLE HTS_IMPORT(
    importId VARCHAR(50) NOT NULL,
    importType VARCHAR(250) NOT NULL,
    location VARCHAR(250) NOT NULL,
    namespace VARCHAR(250)
) IN NCCOG.HTSIMPOR CCSID UNICODE;

CREATE TABLE HTS_LOCAL_NOTIFICATION(
    localNotificationId VARCHAR(50) NOT NULL,
    localNotification VARCHAR(250),
    priorityExpression VARCHAR(250)
) IN NCCOG.HTSNOTIF CCSID UNICODE;

CREATE TABLE HTS_L_DEADLINE_ESCALATION(
    deadlineId VARCHAR(50),
    escalationId VARCHAR(50)
) IN NCCOG.HTSDLESC CCSID UNICODE;

CREATE TABLE HTS_L_ESCALATION_ESCHUMANROLES(
    escalationId VARCHAR(50),
    escalationHumanRolesId VARCHAR(50)
) IN NCCOG.HTSESCHS CCSID UNICODE;

CREATE TABLE HTS_L_LOCNOTE_ESCHUMANROLES(
    escalationId VARCHAR(50),
    escalationHumanRolesId VARCHAR(50)
) IN NCCOG.HTSLCKNT CCSID UNICODE;

CREATE TABLE HTS_L_LOCNOTE_ESCTOPARTS(
    localNotificationId VARCHAR(50),
    toPartId VARCHAR(50)
) IN NCCOG.HTSLNESC CCSID UNICODE;

CREATE TABLE HTS_L_POST_TASKS(
    postId VARCHAR(50),
    taskId VARCHAR(50)
) IN NCCOG.HTSPOTSS CCSID UNICODE;

CREATE TABLE HTS_L_PRESEL_PRESDESC(
    presentationElementsId VARCHAR(50),
    presentationDescriptionId VARCHAR(50)
) IN NCCOG.HTSPRSPR CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_DEADLINES(
    taskClassId VARCHAR(50),
    deadlineId VARCHAR(50)
) IN NCCOG.HTSTSKDE CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_ESCALATION(
    taskClassId VARCHAR(50),
    escalationId VARCHAR(50)
) IN NCCOG.HTSTKESC CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_IMPORT(
    taskClassId VARCHAR(50),
    importId VARCHAR(50)
) IN NCCOG.HTSTKIMP CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_PRESELDESC(
    taskClassId VARCHAR(50),
    presentationElementsDescId VARCHAR(50)
) IN NCCOG.HTSTKPRE CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_PRESELNAME(
    taskClassId VARCHAR(50),
    presentationElementsNameId VARCHAR(50)
) IN NCCOG.HTSTCPRE CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_PRESELPARAM(
    taskClassId VARCHAR(50),
    presentationElementsParamsId VARCHAR(50)
) IN NCCOG.HTSTSKPR CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_PRESELSUBJ(
    taskClassId VARCHAR(50),
    presentationElementsSubjId VARCHAR(50)
) IN NCCOG.HTSTSKPJ CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_PROPERTY(
    taskClassId VARCHAR(50),
    propertyId VARCHAR(50)
) IN NCCOG.HTSTSKPY CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_PURGECNSTR(
    taskClassId VARCHAR(50),
    purgeConstraintId VARCHAR(50)
) IN NCCOG.HTSTSKPU CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_RENDERING(
    taskClassId VARCHAR(50),
    renderingId VARCHAR(50)
) IN NCCOG.HTSTKPEN CCSID UNICODE;

CREATE TABLE HTS_L_TASKCLASS_SUBSCRIBE(
    taskClassId VARCHAR(50),
    taskSubscriptionId VARCHAR(50)
) IN NCCOG.HTSTKSUB CCSID UNICODE;

CREATE TABLE HTS_L_TASKUSER_DISPLAYNAME(
    userId VARCHAR(50),
    displayNameId VARCHAR(50)
) IN NCCOG.HTSTUDPL CCSID UNICODE;

CREATE TABLE HTS_L_TASK_PRESEL(
    taskId VARCHAR(50),
    presentationElementsId VARCHAR(50)
) IN NCCOG.HTSTKPRL CCSID UNICODE;

CREATE TABLE HTS_L_TASK_READBY(
    taskId VARCHAR(50),
    taskReadById VARCHAR(50)
) IN NCCOG.HTSTKRDY CCSID UNICODE;

CREATE TABLE HTS_L_TASK_TASK(
    taskId VARCHAR(50),
    childTskId VARCHAR(50)
) IN NCCOG.HTSTSKTK CCSID UNICODE;

CREATE TABLE HTS_L_TASK_THREAD(
    taskId VARCHAR(50),
    threadId VARCHAR(50)
) IN NCCOG.HTSTSKTR CCSID UNICODE;

CREATE TABLE HTS_L_TASK_UNSUBSCRIBE (taskId VARCHAR(50),
    subscriptionId VARCHAR(50)
) IN NCCOG.HTSTSKUB CCSID UNICODE;

CREATE TABLE HTS_MESSAGE(
    messageId VARCHAR(50) NOT NULL,
    message CLOB(1M),
    messageType VARCHAR(20) NOT NULL,
    name VARCHAR(50),
    taskId VARCHAR(50)
) IN NCCOG.HTSMSGTS CCSID UNICODE;

CREATE AUX TABLE HTS_MSGAUX
      IN NCCOG.HTSLOBMS
      STORES HTS_MESSAGE
      COLUMN message;

CREATE TABLE HTS_POST(
    postId VARCHAR(50) NOT NULL,
    createDate BIGINT NOT NULL,
    pagetext CLOB(1M),
    sticky SMALLINT,
    title VARCHAR(250),
    visible SMALLINT NOT NULL,
    threadId VARCHAR(50),
    userId VARCHAR(50),
    parentId VARCHAR(50)
) IN NCCOG.HTSPOSTS CCSID UNICODE;

CREATE AUX TABLE HTS_POSAUX
      IN NCCOG.HTSLOBPT
      STORES HTS_POST
      COLUMN pagetext;

CREATE TABLE HTS_PRESENTATIONDESCRIPTION(
    presentationDescriptionId VARCHAR(50) NOT NULL,
    contentType VARCHAR(250) NOT NULL,
    description CLOB(1M) NOT NULL
) IN NCCOG.HTSPRDES CCSID UNICODE;

CREATE AUX TABLE HTS_PREAUX
      IN NCCOG.HTSLOBPD
      STORES HTS_PRESENTATIONDESCRIPTION
      COLUMN description;

CREATE TABLE HTS_PRESENTATIONELEMENTS(
    presentationElementsId VARCHAR(50) NOT NULL,
    lang VARCHAR(50) NOT NULL,
    name VARCHAR(250),
    subject VARCHAR(250)
) IN NCCOG.HTSPRELS CCSID UNICODE;

CREATE TABLE HTS_PRESENTATIONELEMENTS_DESC(
    presentationElementsDescId VARCHAR(50) NOT NULL,
    contentType VARCHAR(50) NOT NULL,
    description CLOB(1M),
    lang VARCHAR(50) NOT NULL
) IN NCCOG.HTSPRSDC CCSID UNICODE;

CREATE AUX TABLE HTS_PDEAUX
      IN NCCOG.HTSLOBDE
      STORES HTS_PRESENTATIONELEMENTS_DESC
      COLUMN description;

CREATE TABLE HTS_PRESENTATIONELEMENTS_NAME(
    presentationElementsNameId VARCHAR(50) NOT NULL,
    lang VARCHAR(50) NOT NULL,
    name VARCHAR(250) NOT NULL
) IN NCCOG.HTSPELSN CCSID UNICODE;

CREATE TABLE HTS_PRESENTATIONELEMENTS_SUBJ(
    presentationElementsSubjId VARCHAR(50) NOT NULL,
    lang VARCHAR(50) NOT NULL,
    subject VARCHAR(250) NOT NULL
) IN NCCOG.HTSPDSUB CCSID UNICODE;

CREATE TABLE HTS_PRESENTELEMENTS_PARAMS(
    presentationElementsParamsId VARCHAR(50) NOT NULL,
    expression VARCHAR(250) NOT NULL,
    name VARCHAR(50) NOT NULL,
    type VARCHAR(50) NOT NULL
) IN NCCOG.HTSELSPS CCSID UNICODE;

CREATE TABLE HTS_RENDERING(
    renderingId VARCHAR(50) NOT NULL,
    renderUri VARCHAR(250),
    renderValue CLOB(1M),
    type VARCHAR(50) NOT NULL,
    typeNamespace VARCHAR(250),
    typePrefix VARCHAR(50)
) IN NCCOG.HTSRENDR CCSID UNICODE;

CREATE AUX TABLE HTS_RENAUX
      IN NCCOG.HTSLOREN
      STORES HTS_RENDERING
      COLUMN renderValue;

CREATE TABLE HTS_TASK(
    taskId VARCHAR(50) NOT NULL,
    activationTime BIGINT,
    completedOn BIGINT,
    createdOn BIGINT NOT NULL,
    defaultLocale VARCHAR(10) NOT NULL,
    expirationTime BIGINT,
    name VARCHAR(250),
    operation VARCHAR(250) NOT NULL,
    priority INTEGER,
    isSkipable SMALLINT NOT NULL,
    status VARCHAR(250) NOT NULL,
    taskClassVersion VARCHAR(10) NOT NULL,
    taskType VARCHAR(250) NOT NULL,
    timezoneId VARCHAR(50),
    modCount INTEGER,
    callbackId VARCHAR(50),
    actualOwner VARCHAR(50),
    createdBy VARCHAR(50),
    taskInitiator VARCHAR(50)
) IN NCCOG.HTSTASKT CCSID UNICODE;

CREATE TABLE HTS_TASKCLASS(
    taskClassId VARCHAR(50) NOT NULL,
    activationTime VARCHAR(125),
    delegationType VARCHAR(50),
    expirationTime VARCHAR(125),
    folders CLOB(1M),
    name VARCHAR(250),
    operation VARCHAR(250) NOT NULL,
    outcome VARCHAR(250),
    paramsExpressionLanguage VARCHAR(50) NOT NULL,
    peopleAssignments CLOB(1M),
    portType VARCHAR(250) NOT NULL,
    priority VARCHAR(125),
    responseOperation VARCHAR(250),
    responsePortType VARCHAR(250),
    taskIconPath VARCHAR(125),
    taskType VARCHAR(250) NOT NULL,
    versionId VARCHAR(3)
) IN NCCOG.HTSTSKCL CCSID UNICODE;

CREATE AUX TABLE HTS_TKCAUX
      IN NCCOG.HTSLOTKC
      STORES HTS_TASKCLASS
      COLUMN folders;

CREATE AUX TABLE HTS_TC2AUX
      IN NCCOG.HTSL2TKC
      STORES HTS_TASKCLASS
      COLUMN peopleAssignments;

CREATE TABLE HTS_TASKCLASS_PROPERTY(
    propertyId VARCHAR(50) NOT NULL,
    name VARCHAR(250),
    value VARCHAR(250)
) IN NCCOG.HTSTCPRO CCSID UNICODE;

CREATE TABLE HTS_TASKSUBSCRIPTION(
    taskSubscriptionId VARCHAR(50) NOT NULL,
    subscriptionExpression VARCHAR(250),
    subscriptionType VARCHAR(250)
) IN NCCOG.HTSTSKSU CCSID UNICODE;

CREATE TABLE HTS_TASKUSER(
    userId VARCHAR(50) NOT NULL,
    isGroup SMALLINT,
    logicalPeoplegroup VARCHAR(10) NOT NULL,
    logicalPeoplegroupRef VARCHAR(250) NOT NULL,
    userToken VARCHAR(250)
) IN NCCOG.HTSTSKUS CCSID UNICODE;

CREATE TABLE HTS_TASK_PURGE_CONSTRAINT(
    purgeConstraintId VARCHAR(50) NOT NULL,
    purgeConstraintClass VARCHAR(250),
    purgeConstraintValue CLOB(1M)
) IN NCCOG.HTSTPCTR CCSID UNICODE;

CREATE AUX TABLE HTS_TPCAUX
      IN NCCOG.HTSLOTPC
      STORES HTS_TASK_PURGE_CONSTRAINT
      COLUMN purgeConstraintValue;

CREATE TABLE HTS_TASK_READ_BY(
    taskReadById VARCHAR(50) NOT NULL,
    taskReadLevel INTEGER NOT NULL,
    userId VARCHAR(50)
) IN NCCOG.HTSTSKRB CCSID UNICODE;

CREATE TABLE HTS_THREAD(
    threadId VARCHAR(50) NOT NULL,
    createDate BIGINT NOT NULL,
    isOpen SMALLINT NOT NULL,
    replycount INTEGER NOT NULL,
    title VARCHAR(250),
    type VARCHAR(50),
    visible SMALLINT NOT NULL
) IN NCCOG.HTSTHRED CCSID UNICODE;

CREATE TABLE HTS_UNSUBSCRIPTION(
    subscriptionId VARCHAR(50) NOT NULL,
    event VARCHAR(250) NOT NULL,
    subscriptionState VARCHAR(250) NOT NULL,
    userId VARCHAR(50)
) IN NCCOG.HTSUNSUB CCSID UNICODE;

CREATE TABLE HTS_USER_DISPLAY_NAME(
    displayNameId VARCHAR(50) NOT NULL,
    dateAdded BIGINT,
    locale VARCHAR(50),
    name VARCHAR(250)
) IN NCCOG.HTSUDISN CCSID UNICODE;

CREATE TABLE HTS_VERSION(
    versionId VARCHAR(50) NOT NULL,
    dbVersionId INTEGER NOT NULL
) IN NCCOG.HTSVERSI CCSID UNICODE;

-------------------------------------------------------------------------------
--$201-- indices create begin
-------------------------------------------------------------------------------

CREATE UNIQUE INDEX PN_HTSATT ON HTS_ATTACHMENT(attachmentId);

CREATE UNIQUE INDEX PN_HTSCAL ON HTS_CALLBACK(callbackId);

CREATE UNIQUE INDEX PN_HTSCBP ON HTS_CALLBACKPARAM(callbackParamId);

CREATE UNIQUE INDEX PN_HTSDDL ON HTS_DEADLINE(deadlineId);

CREATE UNIQUE INDEX PN_HTSDLI ON HTS_DEADLINE_INSTANCE(deadlineInstanceId);

CREATE UNIQUE INDEX PN_HTSESC ON HTS_ESCALATION(escalationId);

CREATE UNIQUE INDEX PN_HTSESH ON HTS_ESCALATION_HUMANROLES(escalationHumanRolesId);

CREATE UNIQUE INDEX PN_HTSETP ON HTS_ESCALATION_TO_PART(toPartId);

CREATE UNIQUE INDEX PN_HTSFOL ON HTS_FOLDER(folderId);

CREATE UNIQUE INDEX PN_HTSHUR ON HTS_HUMANROLE(humanRoleId);

CREATE UNIQUE INDEX PN_HTSIMP ON HTS_IMPORT(importId);

CREATE UNIQUE INDEX PN_HTSLOT ON HTS_LOCAL_NOTIFICATION(localNotificationId);

CREATE UNIQUE INDEX PN_HTSMES ON HTS_MESSAGE(messageId);

CREATE UNIQUE INDEX PN_HTSPOT ON HTS_POST(postId);

CREATE UNIQUE INDEX PN_HTSPNI ON HTS_PRESENTATIONDESCRIPTION(presentationDescriptionId);

CREATE UNIQUE INDEX PN_HTSPES ON HTS_PRESENTATIONELEMENTS(presentationElementsId);

CREATE UNIQUE INDEX PN_HTSPED ON HTS_PRESENTATIONELEMENTS_DESC(presentationElementsDescId);

CREATE UNIQUE INDEX PN_HTSPEN ON HTS_PRESENTATIONELEMENTS_NAME(presentationElementsNameId );

CREATE UNIQUE INDEX PN_HTSPEU ON HTS_PRESENTATIONELEMENTS_SUBJ(presentationElementsSubjId);

CREATE UNIQUE INDEX PN_HTSPEP ON HTS_PRESENTELEMENTS_PARAMS(presentationElementsParamsId);

CREATE UNIQUE INDEX PN_HTSREN ON HTS_RENDERING(renderingId);

CREATE UNIQUE INDEX PN_HTSTSK ON HTS_TASK(taskId);

CREATE UNIQUE INDEX PN_HTSTSC ON HTS_TASKCLASS(taskClassId);

CREATE UNIQUE INDEX PN_HTSTCP ON HTS_TASKCLASS_PROPERTY(propertyId);

CREATE UNIQUE INDEX PN_HTSTSN ON HTS_TASKSUBSCRIPTION(taskSubscriptionId);

CREATE UNIQUE INDEX PN_HTSTUS ON HTS_TASKUSER(userId);

CREATE UNIQUE INDEX PN_HTSTPC ON HTS_TASK_PURGE_CONSTRAINT(purgeConstraintId);

CREATE UNIQUE INDEX PN_HTSTRB ON HTS_TASK_READ_BY(taskReadById);

CREATE UNIQUE INDEX PN_HTSHTH ON HTS_THREAD(threadId);

CREATE UNIQUE INDEX PN_HTUNS ON HTS_UNSUBSCRIPTION(subscriptionId);

CREATE UNIQUE INDEX PN_HTSUDN ON HTS_USER_DISPLAY_NAME(displayNameId);

CREATE UNIQUE INDEX PN_HTSVER ON HTS_VERSION(versionId);

CREATE INDEX I_HTS_PRM_HTSCALLB ON HTS_CALLBACKPARAM (callbackId);

CREATE INDEX I_HTS_TNC_HTSTASK ON HTS_DEADLINE_INSTANCE (taskId);

CREATE INDEX I_HTS_LTN_HTSLOCAL ON HTS_ESCALATION (localNotificationId);

CREATE INDEX I_HTS_RLS_HTSTASKU ON HTS_ESCALATION_HUMANROLES (userId);

CREATE INDEX I_HTS_LDR_FOLDERNA ON HTS_FOLDER (folderName);

CREATE INDEX I_HTS_LDR_HTSTASK ON HTS_FOLDER (taskId);

CREATE INDEX I_HTS_LDR_HTSTASKU ON HTS_FOLDER (userId);

CREATE INDEX I_HTS_NRL_HTSTASK ON HTS_HUMANROLE (taskId);

CREATE INDEX I_HTS_NRL_HTSTASKU ON HTS_HUMANROLE (userId);

CREATE INDEX I_HTS_LTN_DEADLINE ON HTS_L_DEADLINE_ESCALATION (deadlineId);

CREATE INDEX I_HTS_LTN_ELEMENT ON HTS_L_DEADLINE_ESCALATION (escalationId);

CREATE INDEX I_HTS_RLS_ELEMENT ON HTS_L_ESCALATION_ESCHUMANROLES (escalationHumanRolesId);

CREATE INDEX I_HTS_RLS_ESCALATI ON HTS_L_ESCALATION_ESCHUMANROLES (escalationId);

CREATE INDEX I_HTS_RLS_ELEMENT1 ON HTS_L_LOCNOTE_ESCHUMANROLES (escalationHumanRolesId);

CREATE INDEX I_HTS_RLS_ESCALAT1 ON HTS_L_LOCNOTE_ESCHUMANROLES (escalationId);

CREATE INDEX I_HTS_RTS_ELEMENT ON HTS_L_LOCNOTE_ESCTOPARTS (toPartId);

CREATE INDEX I_HTS_RTS_LOCALNOT ON HTS_L_LOCNOTE_ESCTOPARTS (localNotificationId);

CREATE INDEX I_HTS_SKS_ELEMENT ON HTS_L_POST_TASKS (taskId);

CREATE INDEX I_HTS_SKS_POSTID ON HTS_L_POST_TASKS (postId);

CREATE INDEX I_HTS_DSC_ELEMENT ON HTS_L_PRESEL_PRESDESC (presentationDescriptionId);

CREATE INDEX I_HTS_DSC_PRESENTA ON HTS_L_PRESEL_PRESDESC (presentationElementsId);

CREATE INDEX I_HTS_LNS_ELEMENT ON HTS_L_TASKCLASS_DEADLINES (deadlineId);

CREATE INDEX I_HTS_LNS_TASKCLAS ON HTS_L_TASKCLASS_DEADLINES (taskClassId);

CREATE INDEX I_HTS_LTN_ELEMENT1 ON HTS_L_TASKCLASS_ESCALATION (escalationId);

CREATE INDEX I_HTS_LTN_TASKCLAS ON HTS_L_TASKCLASS_ESCALATION (taskClassId);

CREATE INDEX I_HTS_PRT_ELEMENT ON HTS_L_TASKCLASS_IMPORT (importId);

CREATE INDEX I_HTS_PRT_TASKCLAS ON HTS_L_TASKCLASS_IMPORT (taskClassId);

CREATE INDEX I_HTS_DSC_ELEMENT1 ON HTS_L_TASKCLASS_PRESELDESC (presentationElementsDescId);

CREATE INDEX I_HTS_DSC_TASKCLAS ON HTS_L_TASKCLASS_PRESELDESC (taskClassId);

CREATE INDEX I_HTS_LNM_ELEMENT ON HTS_L_TASKCLASS_PRESELNAME (presentationElementsNameId);

CREATE INDEX I_HTS_LNM_TASKCLAS ON HTS_L_TASKCLASS_PRESELNAME (taskClassId);

CREATE INDEX I_HTS_PRM_ELEMENT ON HTS_L_TASKCLASS_PRESELPARAM (presentationElementsParamsId);

CREATE INDEX I_HTS_PRM_TASKCLAS ON HTS_L_TASKCLASS_PRESELPARAM (taskClassId);

CREATE INDEX I_HTS_SBJ_ELEMENT ON HTS_L_TASKCLASS_PRESELSUBJ (presentationElementsSubjId);

CREATE INDEX I_HTS_SBJ_TASKCLAS ON HTS_L_TASKCLASS_PRESELSUBJ (taskClassId);

CREATE INDEX I_HTS_RTY_ELEMENT ON HTS_L_TASKCLASS_PROPERTY (propertyId);

CREATE INDEX I_HTS_RTY_TASKCLAS ON HTS_L_TASKCLASS_PROPERTY (taskClassId);

CREATE INDEX I_HTS_STR_ELEMENT ON HTS_L_TASKCLASS_PURGECNSTR (purgeConstraintId);

CREATE INDEX I_HTS_STR_TASKCLAS ON HTS_L_TASKCLASS_PURGECNSTR (taskClassId);

CREATE INDEX I_HTS_RNG_ELEMENT ON HTS_L_TASKCLASS_RENDERING (renderingId);

CREATE INDEX I_HTS_RNG_TASKCLAS ON HTS_L_TASKCLASS_RENDERING (taskClassId);

CREATE INDEX I_HTS_CRB_ELEMENT1 ON HTS_L_TASKCLASS_SUBSCRIBE (taskSubscriptionId);

CREATE INDEX I_HTS_CRB_TASKCLAS ON HTS_L_TASKCLASS_SUBSCRIBE (taskClassId);

CREATE INDEX I_HTS_YNM_ELEMENT ON HTS_L_TASKUSER_DISPLAYNAME (displayNameId);

CREATE INDEX I_HTS_YNM_USERID ON HTS_L_TASKUSER_DISPLAYNAME (userId);

CREATE INDEX I_HTS_RSL_ELEMENT ON HTS_L_TASK_PRESEL (presentationElementsId);

CREATE INDEX I_HTS_RSL_TASKID ON HTS_L_TASK_PRESEL (taskId);

CREATE INDEX I_HTS_DBY_ELEMENT ON HTS_L_TASK_READBY (taskReadById);

CREATE INDEX I_HTS_DBY_TASKID ON HTS_L_TASK_READBY (taskId);

CREATE INDEX I_HTS_TSK_ELEMENT ON HTS_L_TASK_TASK (childTskId);

CREATE INDEX I_HTS_TSK_TASKID ON HTS_L_TASK_TASK (taskId);

CREATE INDEX I_HTS_HRD_ELEMENT ON HTS_L_TASK_THREAD (threadId);

CREATE INDEX I_HTS_HRD_TASKID ON HTS_L_TASK_THREAD (taskId);

CREATE INDEX I_HTS_CRB_ELEMENT ON HTS_L_TASK_UNSUBSCRIBE (subscriptionId);

CREATE INDEX I_HTS_CRB_TASKID ON HTS_L_TASK_UNSUBSCRIBE (taskId);

CREATE INDEX I_HTS_SSG_TASK ON HTS_MESSAGE (taskId);

CREATE INDEX I_HTS_PST_HTSTASKU ON HTS_POST (userId);

CREATE INDEX I_HTS_PST_HTSTHREA ON HTS_POST (threadId);

CREATE INDEX I_HTS_PST_PARENTHT ON HTS_POST (parentId);

CREATE INDEX I_HTS_TSK_ACTUALOW ON HTS_TASK (actualOwner);

CREATE INDEX I_HTS_TSK_CREATEDB ON HTS_TASK (createdBy);

CREATE INDEX I_HTS_TSK_HTSCALLB ON HTS_TASK (callbackId);

CREATE INDEX I_HTS_TSK_TASKINIT ON HTS_TASK (taskInitiator);

CREATE INDEX I_HTS__BY_USER ON HTS_TASK_READ_BY (userId);

CREATE INDEX I_HTS_PTN_USER ON HTS_UNSUBSCRIPTION (userId);

CREATE UNIQUE INDEX IX_HTS_ATTAAUX ON HTS_ATTAAUX;

CREATE UNIQUE INDEX IX_HTS_CALLBAUX ON HTS_CALLBAUX;

CREATE UNIQUE INDEX IX_HTS_MSGAUX ON HTS_MSGAUX;

CREATE UNIQUE INDEX IX_HTS_POSAUX ON HTS_POSAUX;

CREATE UNIQUE INDEX IX_HTS_PREAUX ON HTS_PREAUX;

CREATE UNIQUE INDEX IX_HTS_PDEAUX ON HTS_PDEAUX;

CREATE UNIQUE INDEX IX_HTS_RENAUX ON HTS_RENAUX;

CREATE UNIQUE INDEX IX_HTS_TKCAUX ON HTS_TKCAUX;

CREATE UNIQUE INDEX IX_HTS_TC2AUX ON HTS_TC2AUX;

CREATE UNIQUE INDEX IX_HTS_TPCAUX ON HTS_TPCAUX;


-------------------------------------------------------------------------------
--$202-- primary keys add begin
-------------------------------------------------------------------------------

ALTER TABLE HTS_ATTACHMENT ADD PRIMARY KEY (attachmentId);

ALTER TABLE HTS_CALLBACK ADD PRIMARY KEY (callbackId);

ALTER TABLE HTS_CALLBACKPARAM ADD PRIMARY KEY (callbackParamId);

ALTER TABLE HTS_DEADLINE ADD PRIMARY KEY (deadlineId);

ALTER TABLE HTS_DEADLINE_INSTANCE ADD PRIMARY KEY (deadlineInstanceId);

ALTER TABLE HTS_ESCALATION ADD PRIMARY KEY (escalationId);

ALTER TABLE HTS_ESCALATION_HUMANROLES ADD PRIMARY KEY (escalationHumanRolesId);

ALTER TABLE HTS_ESCALATION_TO_PART ADD PRIMARY KEY (toPartId);

ALTER TABLE HTS_FOLDER ADD PRIMARY KEY (folderId);

ALTER TABLE HTS_HUMANROLE ADD PRIMARY KEY (humanRoleId);

ALTER TABLE HTS_IMPORT ADD PRIMARY KEY (importId);

ALTER TABLE HTS_LOCAL_NOTIFICATION ADD PRIMARY KEY (localNotificationId);

ALTER TABLE HTS_MESSAGE ADD PRIMARY KEY (messageId);

ALTER TABLE HTS_POST ADD PRIMARY KEY (postId);

ALTER TABLE HTS_PRESENTATIONDESCRIPTION ADD PRIMARY KEY (presentationDescriptionId);

ALTER TABLE HTS_PRESENTATIONELEMENTS ADD PRIMARY KEY (presentationElementsId);

ALTER TABLE HTS_PRESENTATIONELEMENTS_DESC ADD PRIMARY KEY (presentationElementsDescId);

ALTER TABLE HTS_PRESENTATIONELEMENTS_NAME ADD PRIMARY KEY (presentationElementsNameId );

ALTER TABLE HTS_PRESENTATIONELEMENTS_SUBJ ADD PRIMARY KEY (presentationElementsSubjId);

ALTER TABLE HTS_PRESENTELEMENTS_PARAMS ADD PRIMARY KEY (presentationElementsParamsId);

ALTER TABLE HTS_RENDERING ADD PRIMARY KEY (renderingId);

ALTER TABLE HTS_TASK ADD PRIMARY KEY (taskId);

ALTER TABLE HTS_TASKCLASS ADD PRIMARY KEY (taskClassId);

ALTER TABLE HTS_TASKCLASS_PROPERTY ADD PRIMARY KEY (propertyId);

ALTER TABLE HTS_TASKSUBSCRIPTION ADD PRIMARY KEY (taskSubscriptionId);

ALTER TABLE HTS_TASKUSER ADD PRIMARY KEY (userId);

ALTER TABLE HTS_TASK_PURGE_CONSTRAINT ADD PRIMARY KEY (purgeConstraintId);

ALTER TABLE HTS_TASK_READ_BY ADD PRIMARY KEY (taskReadById);

ALTER TABLE HTS_THREAD ADD PRIMARY KEY (threadId);

ALTER TABLE HTS_UNSUBSCRIPTION ADD PRIMARY KEY (subscriptionId);

ALTER TABLE HTS_USER_DISPLAY_NAME ADD PRIMARY KEY (displayNameId);

ALTER TABLE HTS_VERSION ADD PRIMARY KEY (versionId);

-------------------------------------------------------------------------------
--$240-- foreign keys add begin
-------------------------------------------------------------------------------




-------------------------------------------------------------------------------
--$210-- views create begin
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--$220-- server data inserts begin
-------------------------------------------------------------------------------

INSERT INTO HTS_VERSION (versionId, dbVersionId) VALUES ('2', 2);

-------------------------------------------------------------------------------
--	END HTS_CREATE_Hsql.sql        *  DO NOT EDIT  *
-------------------------------------------------------------------------------
