create table ACT_HI_COMMENT(
   ID_   VARCHAR(64) not NULL,

   TYPE_ VARCHAR(255),

   TIME_ TIMESTAMP not null,

   USER_ID_ VARCHAR(255),

   TASK_ID_ VARCHAR(64),

   PROC_INST_ID_ VARCHAR(64),

   ACTION_ VARCHAR(255),

   MESSAGE_ VARCHAR(2000),

   FULL_MSG_ BLOB,

   constraint ACT_HI_COMMENT_PKEY primary KEY(ID_)
);

create table ACT_HI_DETAIL
(
    ID_           VARCHAR(64)  not NULL,
    TYPE_         VARCHAR(255) not null,
    PROC_INST_ID_ VARCHAR(64),
    EXECUTION_ID_ VARCHAR(64),
    TASK_ID_      VARCHAR(64),
    ACT_INST_ID_  VARCHAR(64),
    NAME_         VARCHAR(255) not null,
    VAR_TYPE_     VARCHAR(64),
    REV_          INT4,
    TIME_         TIMESTAMP not null,
    BYTEARRAY_ID_ VARCHAR(64),
    DOUBLE_ NUMERIC(30,10),
    LONG_ NUMERIC(19),
    TEXT_ VARCHAR(2000),
    TEXT2_ VARCHAR(2000),
    constraint ACT_HI_DETAIL_PKEY primary KEY(ID_)
);
create index ACT_IDX_HI_DETAIL_ACT_INST
    on ACT_HI_DETAIL (ACT_INST_ID_);
create index ACT_IDX_HI_DETAIL_NAME
    on ACT_HI_DETAIL (NAME_);
create index ACT_IDX_HI_DETAIL_PROC_INST
    on ACT_HI_DETAIL (PROC_INST_ID_);
create index ACT_IDX_HI_DETAIL_TASK_ID
    on ACT_HI_DETAIL (TASK_ID_);
create index ACT_IDX_HI_DETAIL_TIME
    on ACT_HI_DETAIL (TIME_);

create table ACT_HI_ENTITYLINK
(
    ID_          VARCHAR(64) not null,
    LINK_TYPE_   VARCHAR(255),
    CREATE_TIME_ TIMESTAMP,
    SCOPE_ID_ VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_ VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    PARENT_ELEMENT_ID_ VARCHAR(255),
    REF_SCOPE_ID_ VARCHAR(255),
    REF_SCOPE_TYPE_ VARCHAR(255),
    REF_SCOPE_DEFINITION_ID_ VARCHAR(255),
    ROOT_SCOPE_ID_ VARCHAR(255),
    ROOT_SCOPE_TYPE_ VARCHAR(255),
    HIERARCHY_TYPE_ VARCHAR(255),
    constraint ACT_HI_ENTITYLINK_PKEY primary key(ID_)
);

create index ACT_IDX_HI_ENT_LNK_REF_SCOPE
    on ACT_HI_ENTITYLINK (REF_SCOPE_ID_, REF_SCOPE_TYPE_, LINK_TYPE_);
create index ACT_IDX_HI_ENT_LNK_ROOT_SCOPE
    on ACT_HI_ENTITYLINK (ROOT_SCOPE_ID_, ROOT_SCOPE_TYPE_, LINK_TYPE_);
create index ACT_IDX_HI_ENT_LNK_SCOPE
    on ACT_HI_ENTITYLINK (SCOPE_ID_, SCOPE_TYPE_, LINK_TYPE_);
create index ACT_IDX_HI_ENT_LNK_SCOPE_DEF
    on ACT_HI_ENTITYLINK (SCOPE_DEFINITION_ID_, SCOPE_TYPE_, LINK_TYPE_);


create table ACT_HI_IDENTITYLINK(
    ID_          VARCHAR(64) not NULL,
    GROUP_ID_    VARCHAR(255),
    TYPE_        VARCHAR(255),
    USER_ID_     VARCHAR(255),
    TASK_ID_     VARCHAR(64),
    CREATE_TIME_ TIMESTAMP ,
    PROC_INST_ID_ VARCHAR(64),
    SCOPE_ID_ VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_ VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    constraint ACT_HI_IDENTITYLINK_PKEY primary KEY(ID_)
);

create index ACT_IDX_HI_IDENT_LNK_PROCINST
    on ACT_HI_IDENTITYLINK (PROC_INST_ID_);
create index ACT_IDX_HI_IDENT_LNK_SCOPE
    on ACT_HI_IDENTITYLINK (SCOPE_ID_, SCOPE_TYPE_);
create index ACT_IDX_HI_IDENT_LNK_SCOPE_DEF
    on ACT_HI_IDENTITYLINK (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);
create index ACT_IDX_HI_IDENT_LNK_SUB_SCOPE
    on ACT_HI_IDENTITYLINK (SUB_SCOPE_ID_, SCOPE_TYPE_);
create index ACT_IDX_HI_IDENT_LNK_TASK
    on ACT_HI_IDENTITYLINK (TASK_ID_);
create index ACT_IDX_HI_IDENT_LNK_USER
    on ACT_HI_IDENTITYLINK (USER_ID_);

create table ACT_HI_PROCINST
(
    ID_           VARCHAR(64) not NULL,
    REV_          INT4 default 1,
    PROC_INST_ID_ VARCHAR(64) not NULL,
    BUSINESS_KEY_ VARCHAR(255),
    PROC_DEF_ID_  VARCHAR(64) not null,
    START_TIME_   TIMESTAMP not null,
    END_TIME_ TIMESTAMP,
    DURATION_ NUMERIC(12,2),
    START_USER_ID_ VARCHAR(255),
    START_ACT_ID_ VARCHAR(255),
    END_ACT_ID_ VARCHAR(255),
    SUPER_PROCESS_INSTANCE_ID_ VARCHAR(64),
    DELETE_REASON_ text,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
    NAME_ VARCHAR(255),
    CALLBACK_ID_ VARCHAR(255),
    CALLBACK_TYPE_ VARCHAR(255),
    REFERENCE_ID_ VARCHAR(255),
    REFERENCE_TYPE_ VARCHAR(255),
    PROPAGATED_STAGE_INST_ID_ VARCHAR(255),
    BUSINESS_STATUS_ VARCHAR(255),
    constraint ACT_HI_PROCINST_PKEY primary KEY(ID_)
);
CREATE UNIQUE INDEX ACT_HI_PROCINST_PROC_INST_ID_UK  ON ACT_HI_PROCINST(PROC_INST_ID_);
create index ACT_IDX_HI_PRO_INST_END
    on ACT_HI_PROCINST (END_TIME_);
create index ACT_IDX_HI_PRO_I_BUSKEY
    on ACT_HI_PROCINST (BUSINESS_KEY_);

create table ACT_HI_TASKINST
(
    ID_                       VARCHAR(64) not NULL,
    REV_                      INT4 default 1,
    PROC_DEF_ID_              VARCHAR(64),
    TASK_DEF_ID_              VARCHAR(64),
    TASK_DEF_KEY_             VARCHAR(255),
    PROC_INST_ID_             VARCHAR(64),
    EXECUTION_ID_             VARCHAR(64),
    SCOPE_ID_                 VARCHAR(255),
    SUB_SCOPE_ID_             VARCHAR(255),
    SCOPE_TYPE_               VARCHAR(255),
    SCOPE_DEFINITION_ID_      VARCHAR(255),
    PROPAGATED_STAGE_INST_ID_ VARCHAR(255),
    PARENT_TASK_ID_           VARCHAR(64),
    NAME_                     VARCHAR(255),
    DESCRIPTION_              VARCHAR(2000),
    OWNER_                    VARCHAR(255),
    ASSIGNEE_                 VARCHAR(255),
    START_TIME_               TIMESTAMP not null,
    CLAIM_TIME_ TIMESTAMP,
    END_TIME_ TIMESTAMP,
    DURATION_ NUMERIC(19),
    DELETE_REASON_ VARCHAR(2000),
    PRIORITY_ INT4,
    DUE_DATE_ TIMESTAMP,
    FORM_KEY_ VARCHAR(255),
    CATEGORY_ VARCHAR(255),
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
    LAST_UPDATED_TIME_ TIMESTAMP,
    constraint ACT_HI_TASKINST_PKEY primary KEY(ID_)
);


create index ACT_IDX_HI_TASK_INST_PROCINST
    on ACT_HI_TASKINST (PROC_INST_ID_);
create index ACT_IDX_HI_TASK_SCOPE
    on ACT_HI_TASKINST (SCOPE_ID_, SCOPE_TYPE_);
create index ACT_IDX_HI_TASK_SCOPE_DEF
    on ACT_HI_TASKINST (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);
create index ACT_IDX_HI_TASK_SUB_SCOPE
    on ACT_HI_TASKINST (SUB_SCOPE_ID_, SCOPE_TYPE_);

create table ACT_HI_TSK_LOG (
        ID_         NUMERIC(19) not NULL,
        TYPE_       VARCHAR(64),
        TASK_ID_    VARCHAR(64) not null,
        TIME_STAMP_ TIMESTAMP not null,
        USER_ID_ VARCHAR(255),
        DATA_ VARCHAR(2000),
        EXECUTION_ID_ VARCHAR(64),
        PROC_INST_ID_ VARCHAR(64),
        PROC_DEF_ID_ VARCHAR(64),
        SCOPE_ID_ VARCHAR(255),
        SCOPE_DEFINITION_ID_ VARCHAR(255),
        SUB_SCOPE_ID_ VARCHAR(255),
        SCOPE_TYPE_ VARCHAR(255),
        TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
        constraint ACT_HI_TSK_LOG_PKEY primary KEY(ID_)
);

create table ACT_HI_VARINST
(
    ID_           VARCHAR(64)  not NULL,
    REV_          INT4 default 1,
    PROC_INST_ID_ VARCHAR(64),
    EXECUTION_ID_ VARCHAR(64),
    TASK_ID_      VARCHAR(64),
    NAME_         VARCHAR(255) not null,
    VAR_TYPE_     VARCHAR(100),
    SCOPE_ID_     VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_   VARCHAR(255),
    BYTEARRAY_ID_ VARCHAR(64),
    DOUBLE_       NUMERIC(12,2),
    LONG_         NUMERIC(12,2),
    TEXT_         text,
    TEXT2_        text,
    CREATE_TIME_  TIMESTAMP,
    LAST_UPDATED_TIME_ TIMESTAMP,
    constraint ACT_HI_VARINST_PKEY primary KEY(ID_)
);

create index ACT_IDX_HI_PROCVAR_EX
    on ACT_HI_VARINST (EXECUTION_ID_);
create index ACT_IDX_HI_PROCVAR_NAME_TYPE
    on ACT_HI_VARINST (NAME_, VAR_TYPE_);
create index ACT_IDX_HI_PROCVAR_PROC_INST
    on ACT_HI_VARINST (PROC_INST_ID_);
create index ACT_IDX_HI_PROCVAR_TASK_ID
    on ACT_HI_VARINST (TASK_ID_);
create index ACT_IDX_HI_VAR_SCOPE_ID_TYPE
    on ACT_HI_VARINST (SCOPE_ID_, SCOPE_TYPE_);
create index ACT_IDX_HI_VAR_SUB_ID_TYPE
    on ACT_HI_VARINST (SUB_SCOPE_ID_, SCOPE_TYPE_);

create table ACT_PROCDEF_INFO (
    ID_           VARCHAR(64) not NULL,
    PROC_DEF_ID_  VARCHAR(64) not null,
    REV_          INT4,
    INFO_JSON_ID_ VARCHAR(64),
    constraint ACT_PROCDEF_INFO_PKEY
        primary KEY(ID_)
);

create index ACT_IDX_PROCDEF_INFO_JSON
    on ACT_PROCDEF_INFO (INFO_JSON_ID_);
create index ACT_IDX_PROCDEF_INFO_PROC
    on ACT_PROCDEF_INFO (PROC_DEF_ID_);

create table ACT_RE_DEPLOYMENT
(
    ID_          VARCHAR(64) not NULL,
    NAME_        VARCHAR(255),
    CATEGORY_    VARCHAR(255),
    KEY_         VARCHAR(255),
    TENANT_ID_   VARCHAR(255) default 'NULL::CHARACTER VARYING',
    DEPLOY_TIME_ TIMESTAMP ,
    DERIVED_FROM_ VARCHAR(64),
    DERIVED_FROM_ROOT_ VARCHAR(64),
    PARENT_DEPLOYMENT_ID_ VARCHAR(255),
    ENGINE_VERSION_ VARCHAR(255),
    constraint ACT_RE_DEPLOYMENT_PKEY
        primary KEY(ID_)
);

create table ACT_RE_MODEL
(
    ID_          VARCHAR(64) not NULL,
    REV_         INT4,
    NAME_        VARCHAR(255),
    KEY_         VARCHAR(255),
    CATEGORY_    VARCHAR(255),
    CREATE_TIME_ TIMESTAMP,
    LAST_UPDATE_TIME_ TIMESTAMP,
    VERSION_ INT4,
    META_INFO_ VARCHAR(2000),
    DEPLOYMENT_ID_ VARCHAR(64),
    EDITOR_SOURCE_VALUE_ID_ VARCHAR(64),
    EDITOR_SOURCE_EXTRA_VALUE_ID_ VARCHAR(64),
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
    constraint ACT_RE_MODEL_PKEY
        primary key(ID_)
);

create index ACT_IDX_MODEL_DEPLOYMENT
    on ACT_RE_MODEL (DEPLOYMENT_ID_);
create index ACT_IDX_MODEL_SOURCE
    on ACT_RE_MODEL (EDITOR_SOURCE_VALUE_ID_);
create index ACT_IDX_MODEL_SOURCE_EXTRA
    on ACT_RE_MODEL (EDITOR_SOURCE_EXTRA_VALUE_ID_);

create table ACT_RE_PROCDEF
(
    ID_                     VARCHAR(64)  not NULL,
    REV_                    INT4,
    CATEGORY_               VARCHAR(255),
    NAME_                   VARCHAR(255),
    KEY_                    VARCHAR(255) not null,
    VERSION_                INT4 not null,
    DEPLOYMENT_ID_          VARCHAR(64),
    RESOURCE_NAME_          VARCHAR(2000),
    DGRM_RESOURCE_NAME_     VARCHAR(4000),
    DESCRIPTION_            VARCHAR(2000),
    HAS_START_FORM_KEY_     NUMERIC(1),
    HAS_GRAPHICAL_NOTATION_ NUMERIC(1),
    SUSPENSION_STATE_       INT4,
    TENANT_ID_              VARCHAR(255) default 'NULL::CHARACTER VARYING',
    DERIVED_FROM_           VARCHAR(64),
    DERIVED_FROM_ROOT_      VARCHAR(64),
    DERIVED_VERSION_        INT4 default 0 not null,
    ENGINE_VERSION_         VARCHAR(255),
    constraint ACT_RE_PROCDEF_PKEY primary key(ID_)
);
create unique index ACT_UNIQ_PROCDEF_UK on ACT_RE_PROCDEF(KEY_, VERSION_, DERIVED_VERSION_, TENANT_ID_);

create table ACT_RU_ACTINST
(
    ID_                VARCHAR(64)  not NULL,
    REV_               INT4 default 1,
    PROC_DEF_ID_       VARCHAR(64)  not null,
    PROC_INST_ID_      VARCHAR(64)  not null,
    EXECUTION_ID_      VARCHAR(64)  not null,
    ACT_ID_            VARCHAR(255) not null,
    TASK_ID_           VARCHAR(64),
    CALL_PROC_INST_ID_ VARCHAR(64),
    ACT_NAME_          VARCHAR(255),
    ACT_TYPE_          VARCHAR(255) not null,
    ASSIGNEE_          VARCHAR(255),
    START_TIME_        TIMESTAMP not null,
    END_TIME_ TIMESTAMP,
    DURATION_ NUMERIC(12,2),
    TRANSACTION_ORDER_ INT4,
    DELETE_REASON_ VARCHAR(2000),
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
    constraint ACT_RU_ACTINST_PKEY primary key(ID_)
);

create index ACT_IDX_RU_ACTI_END
    on ACT_RU_ACTINST (END_TIME_);
create index ACT_IDX_RU_ACTI_EXEC
    on ACT_RU_ACTINST (EXECUTION_ID_);
create index ACT_IDX_RU_ACTI_EXEC_ACT
    on ACT_RU_ACTINST (EXECUTION_ID_, ACT_ID_);
create index ACT_IDX_RU_ACTI_PROC
    on ACT_RU_ACTINST (PROC_INST_ID_);
create index ACT_IDX_RU_ACTI_PROC_ACT
    on ACT_RU_ACTINST (PROC_INST_ID_, ACT_ID_);
create index ACT_IDX_RU_ACTI_START
    on ACT_RU_ACTINST (START_TIME_);
create index ACT_IDX_RU_ACTI_TASK
    on ACT_RU_ACTINST (TASK_ID_);

create table ACT_RU_DEADLETTER_JOB
(
    ID_                  VARCHAR(64)  not NULL,
    REV_                 INT4,
    CATEGORY_            VARCHAR(255),
    TYPE_                VARCHAR(255) not null,
    EXCLUSIVE_           BOOL,
    EXECUTION_ID_        VARCHAR(64),
    PROCESS_INSTANCE_ID_ VARCHAR(64),
    PROC_DEF_ID_         VARCHAR(64),
    ELEMENT_ID_          VARCHAR(255),
    ELEMENT_NAME_        VARCHAR(255),
    SCOPE_ID_            VARCHAR(255),
    SUB_SCOPE_ID_        VARCHAR(255),
    SCOPE_TYPE_          VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    CORRELATION_ID_      VARCHAR(255),
    EXCEPTION_STACK_ID_  VARCHAR(64),
    EXCEPTION_MSG_       VARCHAR(4000),
    DUEDATE_             TIMESTAMP,
    REPEAT_ VARCHAR(255),
    HANDLER_TYPE_ VARCHAR(255),
    HANDLER_CFG_ text,
    CUSTOM_VALUES_ID_ VARCHAR(12),
    CREATE_TIME_ TIMESTAMP,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
    constraint ACT_RU_DEADLETTER_JOB_PKEY primary KEY(ID_)
);

create index ACT_IDX_DEADLETTER_JOB_CORRELATION_ID
    on ACT_RU_DEADLETTER_JOB (CORRELATION_ID_);
create index ACT_IDX_DEADLETTER_JOB_CUSTOM_VALUES_ID
    on ACT_RU_DEADLETTER_JOB (CUSTOM_VALUES_ID_);
create index ACT_IDX_DEADLETTER_JOB_EXCEPTION_STACK_ID
    on ACT_RU_DEADLETTER_JOB (EXCEPTION_STACK_ID_);
create index ACT_IDX_DJOB_EXECUTION_ID
    on ACT_RU_DEADLETTER_JOB (EXECUTION_ID_);
create index ACT_IDX_DJOB_PROC_DEF_ID
    on ACT_RU_DEADLETTER_JOB (PROC_DEF_ID_);
create index ACT_IDX_DJOB_PROC_INST_ID
    on ACT_RU_DEADLETTER_JOB (PROCESS_INSTANCE_ID_);
create index ACT_IDX_DJOB_SCOPE
    on ACT_RU_DEADLETTER_JOB (SCOPE_ID_, SCOPE_TYPE_);
create index ACT_IDX_DJOB_SCOPE_DEF
    on ACT_RU_DEADLETTER_JOB (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);
create index ACT_IDX_DJOB_SUB_SCOPE
    on ACT_RU_DEADLETTER_JOB (SUB_SCOPE_ID_, SCOPE_TYPE_);

create table ACT_RU_ENTITYLINK
(
    ID_          VARCHAR(64) not null,
    REV_         INT4,
    CREATE_TIME_ TIMESTAMP,
    LINK_TYPE_ VARCHAR(255),
    SCOPE_ID_ VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_ VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    PARENT_ELEMENT_ID_ VARCHAR(255),
    REF_SCOPE_ID_ VARCHAR(255),
    REF_SCOPE_TYPE_ VARCHAR(255),
    REF_SCOPE_DEFINITION_ID_ VARCHAR(255),
    ROOT_SCOPE_ID_ VARCHAR(255),
    ROOT_SCOPE_TYPE_ VARCHAR(255),
    HIERARCHY_TYPE_ VARCHAR(255)
);
create index ACT_IDX_ENT_LNK_REF_SCOPE
    on ACT_RU_ENTITYLINK (REF_SCOPE_ID_, REF_SCOPE_TYPE_, LINK_TYPE_);
create index ACT_IDX_ENT_LNK_ROOT_SCOPE
    on ACT_RU_ENTITYLINK (ROOT_SCOPE_ID_, ROOT_SCOPE_TYPE_, LINK_TYPE_);
create index ACT_IDX_ENT_LNK_SCOPE
    on ACT_RU_ENTITYLINK (SCOPE_ID_, SCOPE_TYPE_, LINK_TYPE_);
create index ACT_IDX_ENT_LNK_SCOPE_DEF
    on ACT_RU_ENTITYLINK (SCOPE_DEFINITION_ID_, SCOPE_TYPE_, LINK_TYPE_);

-- auto-generated definition
create table ACT_RU_EVENT_SUBSCR
(
    ID_            VARCHAR(64)  not null
        constraint ACT_RU_EVENT_SUBSCR_PKEY
            primary key,
    REV_           INT4,
    EVENT_TYPE_    VARCHAR(255) not null,
    EVENT_NAME_    VARCHAR(255),
    EXECUTION_ID_  VARCHAR(64),
    PROC_INST_ID_  VARCHAR(64),
    ACTIVITY_ID_   VARCHAR(64),
    CONFIGURATION_ VARCHAR(255),
    CREATED_       TIMESTAMP,
    PROC_DEF_ID_ VARCHAR(64),
    SUB_SCOPE_ID_ VARCHAR(64),
    SCOPE_ID_ VARCHAR(64),
    SCOPE_DEFINITION_ID_ VARCHAR(64),
    SCOPE_TYPE_ VARCHAR(64),
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING'
);

create index ACT_IDX_EVENT_SUBSCR_CONFIG_
    on ACT_RU_EVENT_SUBSCR (CONFIGURATION_);

-- auto-generated definition
create table ACT_RU_EXECUTION
(
    ID_                VARCHAR(64) not null
        constraint ACT_RU_EXECUTION_PKEY
            primary key,
    REV_               INT4,
    PROC_INST_ID_      VARCHAR(64),
    BUSINESS_KEY_      VARCHAR(255),
    PARENT_ID_         VARCHAR(64),
    PROC_DEF_ID_       VARCHAR(64),
    SUPER_EXEC_        VARCHAR(64),
    ROOT_PROC_INST_ID_ VARCHAR(64),
    ACT_ID_            VARCHAR(255),
    IS_ACTIVE_         NUMERIC(1),
    IS_CONCURRENT_     NUMERIC(1),
    IS_SCOPE_          NUMERIC(1),
    IS_EVENT_SCOPE_    NUMERIC(1),
    IS_MI_ROOT_        NUMERIC(1),
    SUSPENSION_STATE_  INT4,
    CACHED_ENT_STATE_  INT4,
    TENANT_ID_         VARCHAR(255) default 'NULL::CHARACTER VARYING',
    NAME_              VARCHAR(255),
    START_ACT_ID_      VARCHAR(255),
    START_TIME_        TIMESTAMP,
    START_USER_ID_ VARCHAR(255),
    LOCK_TIME_ TIMESTAMP,
    LOCK_OWNER_ VARCHAR(255),
    IS_COUNT_ENABLED_ NUMERIC(12,2),
    EVT_SUBSCR_COUNT_ INT4,
    TASK_COUNT_ INT4,
    JOB_COUNT_ INT4,
    TIMER_JOB_COUNT_ INT4,
    SUSP_JOB_COUNT_ INT4,
    DEADLETTER_JOB_COUNT_ INT4,
    EXTERNAL_WORKER_JOB_COUNT_ INT4,
    VAR_COUNT_ INT4,
    ID_LINK_COUNT_ INT4,
    CALLBACK_ID_ VARCHAR(255),
    CALLBACK_TYPE_ VARCHAR(255),
    REFERENCE_ID_ VARCHAR(255),
    REFERENCE_TYPE_ VARCHAR(255),
    PROPAGATED_STAGE_INST_ID_ VARCHAR(255),
    BUSINESS_STATUS_ VARCHAR(255)
);

create index ACT_IDX_EXEC_BUSKEY
    on ACT_RU_EXECUTION (BUSINESS_KEY_);

create index ACT_IDX_EXEC_REF_ID_
    on ACT_RU_EXECUTION (REFERENCE_ID_);

create index ACT_IDX_EXEC_ROOT
    on ACT_RU_EXECUTION (ROOT_PROC_INST_ID_);

create index ACT_IDX_EXE_PARENT
    on ACT_RU_EXECUTION (PARENT_ID_);

create index ACT_IDX_EXE_PROCDEF
    on ACT_RU_EXECUTION (PROC_DEF_ID_);

create index ACT_IDX_EXE_PROCINST
    on ACT_RU_EXECUTION (PROC_INST_ID_);

create index ACT_IDX_EXE_SUPER
    on ACT_RU_EXECUTION (SUPER_EXEC_);

create table ACT_RU_EXTERNAL_JOB
(
    ID_            VARCHAR(64)  not null
        constraint ACT_RU_EXTERNAL_JOB_PKEY
            primary key,
    REV_           INT4,
    CATEGORY_      VARCHAR(255),
    TYPE_          VARCHAR(255) not null,
    LOCK_EXP_TIME_ TIMESTAMP,
    LOCK_OWNER_ VARCHAR(255),
    EXCLUSIVE_ BOOL,
    EXECUTION_ID_ VARCHAR(64),
    PROCESS_INSTANCE_ID_ VARCHAR(64),
    PROC_DEF_ID_ VARCHAR(64),
    ELEMENT_ID_ VARCHAR(255),
    ELEMENT_NAME_ VARCHAR(255),
    SCOPE_ID_ VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_ VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    CORRELATION_ID_ VARCHAR(255),
    RETRIES_ INT4,
    EXCEPTION_STACK_ID_ VARCHAR(64),
    EXCEPTION_MSG_ text,
    DUEDATE_ TIMESTAMP,
    REPEAT_ VARCHAR(255),
    HANDLER_TYPE_ VARCHAR(255),
    HANDLER_CFG_ text,
    CUSTOM_VALUES_ID_ VARCHAR(64),
    CREATE_TIME_ TIMESTAMP,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING'
);

create index ACT_IDX_EJOB_SCOPE
    on ACT_RU_EXTERNAL_JOB (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_EJOB_SCOPE_DEF
    on ACT_RU_EXTERNAL_JOB (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);

create index ACT_IDX_EJOB_SUB_SCOPE
    on ACT_RU_EXTERNAL_JOB (SUB_SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_EXTERNAL_JOB_CORRELATION_ID
    on ACT_RU_EXTERNAL_JOB (CORRELATION_ID_);

create index ACT_IDX_EXTERNAL_JOB_CUSTOM_VALUES_ID
    on ACT_RU_EXTERNAL_JOB (CUSTOM_VALUES_ID_);

create index ACT_IDX_EXTERNAL_JOB_EXCEPTION_STACK_ID
    on ACT_RU_EXTERNAL_JOB (EXCEPTION_STACK_ID_);

create table ACT_RU_HISTORY_JOB
(
    ID_            VARCHAR(64) not null
        constraint ACT_RU_HISTORY_JOB_PKEY
            primary key,
    REV_           INT4,
    LOCK_EXP_TIME_ TIMESTAMP,
    LOCK_OWNER_ VARCHAR(255),
    RETRIES_ INT4,
    EXCEPTION_STACK_ID_ VARCHAR(64),
    EXCEPTION_MSG_ VARCHAR(4000),
    HANDLER_TYPE_ VARCHAR(255),
    HANDLER_CFG_ VARCHAR(4000),
    CUSTOM_VALUES_ID_ VARCHAR(64),
    ADV_HANDLER_CFG_ID_ VARCHAR(64),
    CREATE_TIME_ TIMESTAMP,
    SCOPE_TYPE_ VARCHAR(255),
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING'
);

create table ACT_RU_IDENTITYLINK
(
    ID_                  VARCHAR(64) not null
        constraint ACT_RU_IDENTITYLINK_PKEY
            primary key,
    REV_                 INT4,
    GROUP_ID_            VARCHAR(255),
    TYPE_                VARCHAR(255),
    USER_ID_             VARCHAR(255),
    TASK_ID_             VARCHAR(64),
    PROC_INST_ID_        VARCHAR(64),
    PROC_DEF_ID_         VARCHAR(64),
    SCOPE_ID_            VARCHAR(255),
    SUB_SCOPE_ID_        VARCHAR(255),
    SCOPE_TYPE_          VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255)
);

create index ACT_IDX_ATHRZ_PROCEDEF
    on ACT_RU_IDENTITYLINK (PROC_DEF_ID_);

create index ACT_IDX_IDENT_LNK_GROUP
    on ACT_RU_IDENTITYLINK (GROUP_ID_);

create index ACT_IDX_IDENT_LNK_SCOPE
    on ACT_RU_IDENTITYLINK (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_IDENT_LNK_SCOPE_DEF
    on ACT_RU_IDENTITYLINK (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);

create index ACT_IDX_IDENT_LNK_SUB_SCOPE
    on ACT_RU_IDENTITYLINK (SUB_SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_IDENT_LNK_USER
    on ACT_RU_IDENTITYLINK (USER_ID_);

create index ACT_IDX_IDL_PROCINST
    on ACT_RU_IDENTITYLINK (PROC_INST_ID_);

create index ACT_IDX_TSKASS_TASK
    on ACT_RU_IDENTITYLINK (TASK_ID_);

create table ACT_RU_JOB
(
    ID_            VARCHAR(64)  not null
        constraint ACT_RU_JOB_PKEY
            primary key,
    REV_           INT4,
    CATEGORY_      VARCHAR(255),
    TYPE_          VARCHAR(255) not null,
    LOCK_EXP_TIME_ TIMESTAMP,
    LOCK_OWNER_ VARCHAR(255),
    EXCLUSIVE_ BOOL,
    EXECUTION_ID_ VARCHAR(64),
    PROCESS_INSTANCE_ID_ VARCHAR(64),
    PROC_DEF_ID_ VARCHAR(64),
    ELEMENT_ID_ VARCHAR(255),
    ELEMENT_NAME_ VARCHAR(255),
    SCOPE_ID_ VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_ VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    CORRELATION_ID_ VARCHAR(255),
    RETRIES_ INT4,
    EXCEPTION_STACK_ID_ VARCHAR(64),
    EXCEPTION_MSG_ text,
    DUEDATE_ TIMESTAMP,
    REPEAT_ VARCHAR(255),
    HANDLER_TYPE_ VARCHAR(255),
    HANDLER_CFG_ VARCHAR(4000),
    CUSTOM_VALUES_ID_ VARCHAR(64),
    CREATE_TIME_ TIMESTAMP,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING'
);

create index ACT_IDX_JOB_CORRELATION_ID
    on ACT_RU_JOB (CORRELATION_ID_);

create index ACT_IDX_JOB_CUSTOM_VALUES_ID
    on ACT_RU_JOB (CUSTOM_VALUES_ID_);

create index ACT_IDX_JOB_EXCEPTION_STACK_ID
    on ACT_RU_JOB (EXCEPTION_STACK_ID_);

create index ACT_IDX_JOB_EXECUTION_ID
    on ACT_RU_JOB (EXECUTION_ID_);

create index ACT_IDX_JOB_PROC_DEF_ID
    on ACT_RU_JOB (PROC_DEF_ID_);

create index ACT_IDX_JOB_PROC_INST_ID
    on ACT_RU_JOB (PROCESS_INSTANCE_ID_);

create index ACT_IDX_JOB_SCOPE
    on ACT_RU_JOB (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_JOB_SCOPE_DEF
    on ACT_RU_JOB (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);

create index ACT_IDX_JOB_SUB_SCOPE
    on ACT_RU_JOB (SUB_SCOPE_ID_, SCOPE_TYPE_);

create table ACT_RU_SUSPENDED_JOB
(
    ID_                  VARCHAR(64)  not null
        constraint ACT_RU_SUSPENDED_JOB_PKEY
            primary key,
    REV_                 INT4,
    CATEGORY_            VARCHAR(255),
    TYPE_                VARCHAR(255) not null,
    EXCLUSIVE_           BOOL,
    EXECUTION_ID_        VARCHAR(64),
    PROCESS_INSTANCE_ID_ VARCHAR(64),
    PROC_DEF_ID_         VARCHAR(64),
    ELEMENT_ID_          VARCHAR(255),
    ELEMENT_NAME_        VARCHAR(255),
    SCOPE_ID_            VARCHAR(255),
    SUB_SCOPE_ID_        VARCHAR(255),
    SCOPE_TYPE_          VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    CORRELATION_ID_      VARCHAR(255),
    RETRIES_             INT4,
    EXCEPTION_STACK_ID_  VARCHAR(64),
    EXCEPTION_MSG_       VARCHAR(4000),
    DUEDATE_             TIMESTAMP,
    REPEAT_ VARCHAR(255),
    HANDLER_TYPE_ VARCHAR(255),
    HANDLER_CFG_ VARCHAR(4000),
    CUSTOM_VALUES_ID_ VARCHAR(64),
    CREATE_TIME_ TIMESTAMP,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING'
);

create index ACT_IDX_SJOB_EXECUTION_ID
    on ACT_RU_SUSPENDED_JOB (EXECUTION_ID_);

create index ACT_IDX_SJOB_PROC_DEF_ID
    on ACT_RU_SUSPENDED_JOB (PROC_DEF_ID_);

create index ACT_IDX_SJOB_PROC_INST_ID
    on ACT_RU_SUSPENDED_JOB (PROCESS_INSTANCE_ID_);

create index ACT_IDX_SJOB_SCOPE
    on ACT_RU_SUSPENDED_JOB (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_SJOB_SCOPE_DEF
    on ACT_RU_SUSPENDED_JOB (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);

create index ACT_IDX_SJOB_SUB_SCOPE
    on ACT_RU_SUSPENDED_JOB (SUB_SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_SUSPENDED_JOB_CORRELATION_ID
    on ACT_RU_SUSPENDED_JOB (CORRELATION_ID_);

create index ACT_IDX_SUSPENDED_JOB_CUSTOM_VALUES_ID
    on ACT_RU_SUSPENDED_JOB (CUSTOM_VALUES_ID_);

create index ACT_IDX_SUSPENDED_JOB_EXCEPTION_STACK_ID
    on ACT_RU_SUSPENDED_JOB (EXCEPTION_STACK_ID_);

create table ACT_RU_TASK
(
    ID_                       VARCHAR(64) not null
        constraint ACT_RU_TASK_PKEY
            primary key,
    REV_                      INT4,
    EXECUTION_ID_             VARCHAR(64),
    PROC_INST_ID_             VARCHAR(64),
    PROC_DEF_ID_              VARCHAR(64),
    TASK_DEF_ID_              VARCHAR(64),
    SCOPE_ID_                 VARCHAR(255),
    SUB_SCOPE_ID_             VARCHAR(255),
    SCOPE_TYPE_               VARCHAR(255),
    SCOPE_DEFINITION_ID_      VARCHAR(255),
    PROPAGATED_STAGE_INST_ID_ VARCHAR(255),
    NAME_                     VARCHAR(255),
    PARENT_TASK_ID_           VARCHAR(64),
    DESCRIPTION_              VARCHAR(2000),
    TASK_DEF_KEY_             VARCHAR(255),
    OWNER_                    VARCHAR(255),
    ASSIGNEE_                 VARCHAR(255),
    DELEGATION_               VARCHAR(64),
    PRIORITY_                 INT4,
    CREATE_TIME_              TIMESTAMP ,
    DUE_DATE_ TIMESTAMP,
    CATEGORY_ VARCHAR(255),
    SUSPENSION_STATE_ INT4,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING',
    FORM_KEY_ VARCHAR(255),
    CLAIM_TIME_ TIMESTAMP,
    IS_COUNT_ENABLED_ NUMERIC(12,2),
    VAR_COUNT_ INT4,
    ID_LINK_COUNT_ INT4,
    SUB_TASK_COUNT_ INT4
);

create index ACT_IDX_TASK_CREATE
    on ACT_RU_TASK (CREATE_TIME_);

create index ACT_IDX_TASK_EXEC
    on ACT_RU_TASK (EXECUTION_ID_);

create index ACT_IDX_TASK_PROCDEF
    on ACT_RU_TASK (PROC_DEF_ID_);

create index ACT_IDX_TASK_PROCINST
    on ACT_RU_TASK (PROC_INST_ID_);

create index ACT_IDX_TASK_SCOPE
    on ACT_RU_TASK (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_TASK_SCOPE_DEF
    on ACT_RU_TASK (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);

create index ACT_IDX_TASK_SUB_SCOPE
    on ACT_RU_TASK (SUB_SCOPE_ID_, SCOPE_TYPE_);

create table ACT_RU_TIMER_JOB
(
    ID_            VARCHAR(64)  not null
        constraint ACT_RU_TIMER_JOB_PKEY
            primary key,
    REV_           INT4,
    CATEGORY_      VARCHAR(255),
    TYPE_          VARCHAR(255) not null,
    LOCK_EXP_TIME_ TIMESTAMP,
    LOCK_OWNER_ VARCHAR(255),
    EXCLUSIVE_ BOOL,
    EXECUTION_ID_ VARCHAR(64),
    PROCESS_INSTANCE_ID_ VARCHAR(64),
    PROC_DEF_ID_ VARCHAR(64),
    ELEMENT_ID_ VARCHAR(255),
    ELEMENT_NAME_ VARCHAR(255),
    SCOPE_ID_ VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_ VARCHAR(255),
    SCOPE_DEFINITION_ID_ VARCHAR(255),
    CORRELATION_ID_ VARCHAR(255),
    RETRIES_ INT4,
    EXCEPTION_STACK_ID_ VARCHAR(64),
    EXCEPTION_MSG_ VARCHAR(4000),
    DUEDATE_ TIMESTAMP,
    REPEAT_ VARCHAR(255),
    HANDLER_TYPE_ VARCHAR(255),
    HANDLER_CFG_ VARCHAR(4000),
    CUSTOM_VALUES_ID_ VARCHAR(64),
    CREATE_TIME_ TIMESTAMP,
    TENANT_ID_ VARCHAR(255) default 'NULL::CHARACTER VARYING'
);

create index ACT_IDX_TIMER_JOB_CORRELATION_ID
    on ACT_RU_TIMER_JOB (CORRELATION_ID_);

create index ACT_IDX_TIMER_JOB_CUSTOM_VALUES_ID
    on ACT_RU_TIMER_JOB (CUSTOM_VALUES_ID_);

create index ACT_IDX_TIMER_JOB_DUEDATE
    on ACT_RU_TIMER_JOB (DUEDATE_);

create index ACT_IDX_TIMER_JOB_EXCEPTION_STACK_ID
    on ACT_RU_TIMER_JOB (EXCEPTION_STACK_ID_);

create index ACT_IDX_TJOB_EXECUTION_ID
    on ACT_RU_TIMER_JOB (EXECUTION_ID_);

create index ACT_IDX_TJOB_PROC_DEF_ID
    on ACT_RU_TIMER_JOB (PROC_DEF_ID_);

create index ACT_IDX_TJOB_PROC_INST_ID
    on ACT_RU_TIMER_JOB (PROCESS_INSTANCE_ID_);

create index ACT_IDX_TJOB_SCOPE
    on ACT_RU_TIMER_JOB (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_TJOB_SCOPE_DEF
    on ACT_RU_TIMER_JOB (SCOPE_DEFINITION_ID_, SCOPE_TYPE_);

create index ACT_IDX_TJOB_SUB_SCOPE
    on ACT_RU_TIMER_JOB (SUB_SCOPE_ID_, SCOPE_TYPE_);

create table ACT_RU_VARIABLE
(
    ID_           VARCHAR(64)  not null
        constraint ACT_RU_VARIABLE_PKEY
            primary key,
    REV_          INT4,
    TYPE_         VARCHAR(255) not null,
    NAME_         VARCHAR(255) not null,
    EXECUTION_ID_ VARCHAR(64),
    PROC_INST_ID_ VARCHAR(64),
    TASK_ID_      VARCHAR(64),
    SCOPE_ID_     VARCHAR(255),
    SUB_SCOPE_ID_ VARCHAR(255),
    SCOPE_TYPE_   VARCHAR(255),
    BYTEARRAY_ID_ VARCHAR(64),
    DOUBLE_       NUMERIC(12,2),
    LONG_         NUMERIC(12,2),
    TEXT_         VARCHAR(2000),
    TEXT2_        VARCHAR(2000)
);

create index ACT_IDX_RU_VAR_SCOPE_ID_TYPE
    on ACT_RU_VARIABLE (SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_RU_VAR_SUB_ID_TYPE
    on ACT_RU_VARIABLE (SUB_SCOPE_ID_, SCOPE_TYPE_);

create index ACT_IDX_VARIABLE_TASK_ID
    on ACT_RU_VARIABLE (TASK_ID_);

create index ACT_IDX_VAR_BYTEARRAY
    on ACT_RU_VARIABLE (BYTEARRAY_ID_);

create index ACT_IDX_VAR_EXE
    on ACT_RU_VARIABLE (EXECUTION_ID_);

create index ACT_IDX_VAR_PROCINST
    on ACT_RU_VARIABLE (PROC_INST_ID_);