set client_encoding=utf8;

CREATE TABLE U_VAULT(
    SOURCE_CLASS_ID int NOT NULL, 
    SOURCE_OBJECT_ID int NOT NULL,
    SOURCE_NAME varchar(256) NULL,
    VAULT varchar(256) NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID)
);

CREATE TABLE U_VAULT_PATH(
    SOURCE_CLASS_ID int NOT NULL, 
    SOURCE_OBJECT_ID int NOT NULL,
    SOURCE_PATH varchar(256) NULL,
    VAULT varchar(256) NULL,
    VIRTUAL_DISK varchar(256) NULL,
    PATH varchar(256) NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_PATH)
);

CREATE TABLE U_CLASS_MAPPING(
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NULL,
PRIMARY KEY(SOURCE_CLASS_ID)
);

CREATE TABLE U_WORKFLOW_META_TEMPLATE(
    SOURCE_CLASS_ID int NOT NULL, 
    SOURCE_OBJECT_ID int NOT NULL,
    workflow_meta_template_id varchar(64) NULL,
    workflow_meta_template_classification varchar(64) NULL,
    workflow_meta_template_use_type varchar(64) NULL,
    UPGRADE_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
    IMPORT_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID)
);

CREATE TABLE U_WORKFLOW_META_PROCESS(
    SOURCE_CLASS_ID int NOT NULL,     
    SOURCE_OBJECT_ID int NOT NULL,
    SOURCE_WORKFLOW_META_PROCESS_ID varchar(64) NOT NULL,
    WORKFLOW_META_PROCESS_ID varchar(64) NULL,
    workflow_meta_template_id varchar(64) NULL,
    UPGRADE_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
    IMPORT_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_WORKFLOW_META_PROCESS_ID)
);

CREATE TABLE U_WORKFLOW_META_ACTIVITY(
    SOURCE_CLASS_ID int NOT NULL, 
    SOURCE_OBJECT_ID int NOT NULL,
    SOURCE_WORKFLOW_META_PROCESS_ID varchar(64) NOT NULL,
    SOURCE_WORKFLOW_META_ACTIVITY_ID varchar(64) NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL,
    WORKFLOW_META_PROCESS_ID varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL,
    WORKFLOW_META_TEMPLATE_NAME varchar(64) NULL,
    WORKFLOW_META_TEMPLATE_FILE_NAME varchar(64) NULL,
    WORKFLOW_META_PROCESS_NAME varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_NAME varchar(64) NULL,
    UPGRADE_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
    IMPORT_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_WORKFLOW_META_PROCESS_ID,SOURCE_WORKFLOW_META_ACTIVITY_ID)
);

CREATE TABLE U_WORKFLOW_META_TRANSITION(
    SOURCE_CLASS_ID int NOT NULL, 
    SOURCE_OBJECT_ID int NOT NULL,
    SOURCE_WORKFLOW_META_PROCESS_ID varchar(64) NOT NULL,
    SOURCE_WORKFLOW_META_TRANSITION_ID varchar(64) NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL,
    WORKFLOW_META_PROCESS_ID varchar(64) NULL,
    WORKFLOW_META_TRANSITION_ID varchar(64) NULL,
    UPGRADE_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
    IMPORT_SUCCESS_FLAG smallint DEFAULT 0 NOT NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_WORKFLOW_META_PROCESS_ID,SOURCE_WORKFLOW_META_TRANSITION_ID)
);

CREATE TABLE U_CLASSEXPINDEXSET(
    SOURCE_SECU_CLASS_ID int NOT NULL, 
    SOURCE_PROPERTY_FILTER_INDEX int NOT NULL,
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    RBAC_META_INTERNAL_NAME varchar(56) NOT NULL,
PRIMARY KEY(OBJECT_ID)
);

CREATE TABLE U_WFProcessInst(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_PROCESS_ID varchar(64) NULL, 
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL, 
    WORKFLOW_META_TEMPLATE_INSTANCE_ID varchar(64) NULL, 
    WORKFLOW_META_TEMPLATE_CLASSIFICATION varchar(64) NULL, 
    WORKFLOW_META_TEMPLATE_USE_TYPE varchar(64) NULL, 
PRIMARY KEY(SOURCE_OBJECT_ID)
);

CREATE INDEX IDX_U_WFProcessInst ON U_WFProcessInst(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);

CREATE TABLE  U_WFActivityInst(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_PROCESS_ID varchar(64) NULL, 
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL, 
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL, 
primary key(source_object_id)
);

CREATE INDEX IDX_U_WFActivityInst ON U_WFActivityInst(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);

CREATE TABLE U_WFWorkitem(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL, 
    WORKFLOW_META_TASK_CLASSIFICATION varchar(64) NULL, 
    WORKFLOW_META_TASK_USE_TYPE varchar(64) NULL, 
PRIMARY KEY(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_WFWorkitem ON U_WFWorkitem(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);


CREATE TABLE U_WfTransitionInst(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_TRANSITION_ID varchar(64) NULL, 
    WORKFLOW_FROM_META_ACTIVITY_ID varchar(64) NULL, 
    WORKFLOW_TO_META_ACTIVITY_ID varchar(64) NULL,
PRIMARY KEY(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_WfTransitionInst ON U_WfTransitionInst(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);


CREATE TABLE U_WfParticipantInst (
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_PROCESS_ID varchar(64) NULL, 
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL,
PRIMARY KEY(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_WfParticipantInst ON U_WfParticipantInst(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);


CREATE TABLE U_WFDynamicPerform(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL, 
    WORKFLOW_META_PROCESS_ID varchar(64) NULL,
primary key(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_WFDynamicPerform ON U_WFDynamicPerform(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);

CREATE TABLE U_DelegateData(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_TEMPLATE_IDS text NULL,
primary key(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_DelegateData ON U_DelegateData(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);

CREATE TABLE U_OpinionToTargetLink(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    ROLEB_OBJECT_ID bigint NULL, 
    ROLEB_INTERNAL_NAME varchar(56)  NULL,
PRIMARY KEY(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_OpinionToTargetLink ON U_OpinionToTargetLink(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);


CREATE TABLE U_WFWorkitemReviewObjectLink(
    SOURCE_OBJECT_ID int NOT NULL, 
    SOURCE_CLASS_ID int NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    ROLEA_OBJECT_ID bigint NULL, 
    ROLEA_INTERNAL_NAME varchar(56)  NULL,
    ROLEB_OBJECT_ID bigint NULL, 
    ROLEB_INTERNAL_NAME varchar(56)  NULL,
PRIMARY KEY(SOURCE_OBJECT_ID)
);
CREATE INDEX IDX_U_WFWorkitemReviewObjectLink ON U_WFWorkitemReviewObjectLink(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);


CREATE TABLE u_ObjPersonRoleSecuSet(
    SOURCE_CLASS_ID integer NOT NULL, 
    SOURCE_OBJECT_ID integer NOT NULL,
    INTERNAL_NAME varchar(56) NULL,
    OBJECT_ID bigint NULL,
    SOURCE_RBAC_CLASS_ID integer NOT NULL,
    SOURCE_RBAC_OBJECT_ID integer NOT NULL,
    RBAC_OBJECT_ID bigint NULL,
    RBAC_META_INTERNAL_NAME varchar(56) NULL,
    SOURCE_ACTOR_CLASS_ID integer NULL,
    SOURCE_ACTOR_OBJECT_ID integer NULL,
    ACTOR_INTERNAL_NAME varchar(56) NULL,
    ACTOR_OBJECT_ID bigint NULL,
    SOURCE_ROLE_CLASS_ID integer NULL,
    SOURCE_ROLE_OBJECT_ID integer NULL,
    ROLE_INTERNAL_NAME varchar(56) NULL,
    ROLE_OBJECT_ID bigint NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID)
);


CREATE TABLE u_rbac_object_team(
    OBJECT_ID bigint NOT NULL, 
    INTERNAL_NAME varchar(56) NOT NULL,
    PARENT_OBJECT_ID bigint NULL,
    PARENT_INTERNAL_NAME varchar(56) NULL,
    TEAM_OWNER_OBJECT_ID bigint NULL,
    TEAM_OWNER_INTERNAL_NAME varchar(56) NULL,
    TEAM_OBJECT_ID bigint NULL,
    TEAM_INTERNAL_NAME varchar(56) NULL,
PRIMARY KEY(OBJECT_ID,INTERNAL_NAME)
);

CREATE TABLE u_nonactor_object(
    SOURCE_RBAC_CLASS_ID integer NOT NULL, 
    SOURCE_RBAC_OBJECT_ID integer NOT NULL,
    RBAC_META_INTERNAL_NAME varchar(56) NOT NULL,
    RBAC_OBJECT_ID bigint NOT NULL,
    TEAM_OBJECT_ID bigint NULL,
    TEAM_INTERNAL_NAME varchar(56) NULL,
    TEAM_OWNER_OBJECT_ID bigint NULL,
    TEAM_OWNER_INTERNAL_NAME varchar(56) NULL,
    NONACTOR_ROLE_INTERNAL_NAME varchar(56) NULL,
    NONACTOR_ROLE_OBJECT_ID bigint NULL,
PRIMARY KEY(SOURCE_RBAC_CLASS_ID,SOURCE_RBAC_OBJECT_ID)
);

ALTER TABLE u_nonactor_object ADD TEAM_OBJECT_ID bigint NULL;
ALTER TABLE u_nonactor_object ADD TEAM_INTERNAL_NAME varchar(56) NULL;
ALTER TABLE u_nonactor_object ADD TEAM_OWNER_OBJECT_ID bigint NULL;
ALTER TABLE u_nonactor_object ADD TEAM_OWNER_INTERNAL_NAME varchar(56) NULL;

CREATE TABLE u_upgrade_info(
    NAME varchar(256) NOT NULL,
PRIMARY KEY(NAME)
);

CREATE TABLE U_DocumentExternRef(
	SOURCE_CLASS_ID integer NOT NULL,
	SOURCE_OBJECT_ID integer NOT NULL,
	SOURCE_ROLEA_CLASS_ID integer NOT NULL,
	SOURCE_ROLEA_ID integer NOT NULL,
	SOURCE_ROLEB_CLASS_ID integer NOT NULL,
	SOURCE_ROLEB_ID integer NOT NULL,
	INTERNAL_NAME varchar(56) NOT NULL,
	OBJECT_ID bigint NOT NULL,
	ROLEA_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEA_OBJECT_ID bigint NOT NULL,
    ROLEB_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEB_OBJECT_ID bigint NOT NULL,
	PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID)
);

CREATE TABLE UH_DocumentExternRef(
	SOURCE_CLASS_ID integer NOT NULL,
	SOURCE_OBJECT_ID integer NOT NULL,
    SOURCE_SNAPSHOT_OBJECT_ID integer NOT NULL,
    SOURCE_SNAPSHOT_CLASS_ID integer NOT NULL,
	SOURCE_ROLEA_CLASS_ID integer NOT NULL,
	SOURCE_ROLEA_ID integer NOT NULL,
	SOURCE_ROLEB_CLASS_ID integer NOT NULL,
	SOURCE_ROLEB_ID integer NOT NULL,
	INTERNAL_NAME varchar(56) NOT NULL,
	OBJECT_ID bigint NOT NULL,
	ROLEA_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEA_OBJECT_ID bigint NOT NULL,
    ROLEB_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEB_OBJECT_ID bigint NOT NULL,
    SNAPSHOT_OBJECT_ID bigint NOT NULL,
	PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_SNAPSHOT_OBJECT_ID,SOURCE_SNAPSHOT_CLASS_ID)
);

CREATE TABLE U_SIGNATURELOCATIONCFG(
    SOURCE_CLASS_ID integer NOT NULL, 
    SOURCE_OBJECT_ID integer NOT NULL,
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL,
    WORKFLOW_META_TEMPLATE_NAME varchar(128) NULL,
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_NAME varchar(128) NULL,
    FROM_HISTORY_FLAG smallint DEFAULT 0 NULL, 
PRIMARY KEY(OBJECT_ID)
);
CREATE INDEX IDX_U_SIGNATURELOCATIONCFG ON U_SIGNATURELOCATIONCFG(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);

CREATE TABLE U_SIGNATURE(
    SOURCE_CLASS_ID integer NOT NULL, 
    SOURCE_OBJECT_ID integer NOT NULL,
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL,
    WORKFLOW_META_TEMPLATE_NAME varchar(128) NULL,
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_NAME varchar(128) NULL,
    FROM_HISTORY_FLAG smallint DEFAULT 0 NULL, 
PRIMARY KEY(SOURCE_OBJECT_ID, SOURCE_CLASS_ID)
);

CREATE TABLE U_DOCUMENTSIGNATURE(
	SOURCE_CLASS_ID integer NOT NULL,
	SOURCE_OBJECT_ID integer NOT NULL,
	SOURCE_ROLEA_CLASS_ID integer NOT NULL,
	SOURCE_ROLEA_ID integer NOT NULL,
	SOURCE_ROLEB_CLASS_ID integer NOT NULL,
	SOURCE_ROLEB_ID integer NOT NULL,
	INTERNAL_NAME varchar(56) NOT NULL,
	OBJECT_ID bigint NOT NULL,
	ROLEA_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEA_OBJECT_ID bigint NOT NULL,
    ROLEB_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEB_OBJECT_ID bigint NOT NULL,
    FROM_HISTORY_FLAG smallint DEFAULT 0 NULL, 
	PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID)    
);


CREATE TABLE U_WORKFLOW_META_TEMPLATE_ACTIVITY(
    SOURCE_CLASS_ID integer NOT NULL, 
    SOURCE_OBJECT_ID integer NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_ID varchar(64) NOT NULL,
    WORKFLOW_META_TEMPLATE_NAME varchar(64) NULL,
    WORKFLOW_META_TEMPLATE_FILE_NAME varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_NAME varchar(64) NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,WORKFLOW_META_ACTIVITY_ID)
);

CREATE INDEX IDX_U_WORKFLOW_META_TEMPLATE_ACTIVITY ON U_WORKFLOW_META_TEMPLATE_ACTIVITY(SOURCE_OBJECT_ID, SOURCE_CLASS_ID);

CREATE TABLE UH_SIGNATURE(
    SOURCE_CLASS_ID integer NOT NULL, 
    SOURCE_OBJECT_ID integer NOT NULL,
    SOURCE_SNAPSHOT_OBJECT_ID integer NOT NULL,
    SOURCE_SNAPSHOT_CLASS_ID integer NOT NULL,
    INTERNAL_NAME varchar(56) NOT NULL,
    OBJECT_ID bigint NOT NULL,
    WORKFLOW_META_TEMPLATE_ID varchar(64) NULL,
    WORKFLOW_META_TEMPLATE_NAME varchar(128) NULL,
    WORKFLOW_META_ACTIVITY_ID varchar(64) NULL,
    WORKFLOW_META_ACTIVITY_NAME varchar(128) NULL,
    SNAPSHOT_OBJECT_ID bigint NOT NULL,
PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_SNAPSHOT_OBJECT_ID,SOURCE_SNAPSHOT_CLASS_ID)
);



CREATE TABLE UH_DOCUMENTSIGNATURE(
	SOURCE_CLASS_ID integer NOT NULL,
	SOURCE_OBJECT_ID integer NOT NULL,
    SOURCE_SNAPSHOT_OBJECT_ID integer NOT NULL,
    SOURCE_SNAPSHOT_CLASS_ID integer NOT NULL,
	SOURCE_ROLEA_CLASS_ID integer NOT NULL,
	SOURCE_ROLEA_ID integer NOT NULL,
	SOURCE_ROLEB_CLASS_ID integer NOT NULL,
	SOURCE_ROLEB_ID integer NOT NULL,
	INTERNAL_NAME varchar(56) NOT NULL,
	OBJECT_ID bigint NOT NULL,
	ROLEA_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEA_OBJECT_ID bigint NOT NULL,
    ROLEB_INTERNAL_NAME varchar(56) NOT NULL,
	ROLEB_OBJECT_ID bigint NOT NULL,
    SNAPSHOT_OBJECT_ID bigint NOT NULL,
	PRIMARY KEY(SOURCE_CLASS_ID,SOURCE_OBJECT_ID,SOURCE_SNAPSHOT_OBJECT_ID,SOURCE_SNAPSHOT_CLASS_ID)
);

CREATE TABLE u_obj_behavior_method_mapping(
    SOURCE_CLASS_ID integer NOT NULL, 
    BEHAVIOR_NAME varchar(64) NULL,
    METHOD_NAME varchar(64) NULL,
    INTERNAL_NAME varchar(56) NOT NULL,
    PERMISSION_ITEM_BEHAVIOR_NAME varchar(64) NULL,
    PERMISSION_ITEM_METHOD_NAME varchar(64) NULL,
    PERMISSION_ITEM_KEY varchar(255) NOT NULL,
PRIMARY KEY(SOURCE_CLASS_ID,PERMISSION_ITEM_KEY)
);
CREATE INDEX IDX_u_obj_behavior_method_mapping ON u_obj_behavior_method_mapping(SOURCE_CLASS_ID, BEHAVIOR_NAME, METHOD_NAME);

CREATE TABLE u_nonactor_classification_mapping(
   NONACTOR_ROLE_INTERNAL_NAME varchar(56) NULL,
   NONACTOR_ROLE_OBJECT_ID bigint NOT NULL,
   PERMISSION_CLASSIFICATION varchar(255) NOT NULL, 
   PERMISSION_ITEM_KEY varchar(255) NULL, 
PRIMARY KEY(NONACTOR_ROLE_OBJECT_ID, PERMISSION_CLASSIFICATION)
);

