﻿SET SESSION FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS ACT_RU_JOB;
DROP TABLE IF EXISTS ACT_RU_VARIABLE;
DROP TABLE IF EXISTS ACT_GE_BYTEARRAY;
DROP TABLE IF EXISTS ACT_RU_IDENTITYLINK;
DROP TABLE IF EXISTS ACT_RU_TASK;
DROP TABLE IF EXISTS ACT_RU_EXECUTION;
DROP TABLE IF EXISTS ACT_RE_DEPLOYMENT;
DROP TABLE IF EXISTS ACT_RU_ACTINST;
DROP TABLE IF EXISTS ACT_RE_PROCDEF;
DROP TABLE IF EXISTS TB_HIS_APPROVAL;
DROP TABLE IF EXISTS ACT_HI_ACTINST;
DROP TABLE IF EXISTS ACT_HI_COMMENT;
DROP TABLE IF EXISTS ACT_HI_PROCINST;
DROP TABLE IF EXISTS ACT_HI_TASKINST;
DROP TABLE IF EXISTS ACT_HI_VARINST;
DROP TABLE IF EXISTS ACT_DE_MODEL;
DROP TABLE IF EXISTS ACT_DE_MODEL_HISTORY;
DROP TABLE IF EXISTS ACT_DE_MODEL_RELATION;
DROP TABLE IF EXISTS ACT_FO_FORM_INSTANCE;
DROP TABLE IF EXISTS ACT_FO_FORM_RESOURCE;
DROP TABLE IF EXISTS ACT_FO_FORM_DEFINITION;
DROP TABLE IF EXISTS ACT_FO_FORM_DEPLOYMENT;


DROP TABLE IF EXISTS ACT_APP_APPDEF;
DROP TABLE IF EXISTS ACT_APP_DATABASECHANGELOG;
DROP TABLE IF EXISTS ACT_APP_DATABASECHANGELOGLOCK;
DROP TABLE IF EXISTS ACT_APP_DEPLOYMENT;
DROP TABLE IF EXISTS ACT_APP_DEPLOYMENT_RESOURCE;
DROP TABLE IF EXISTS ACT_CMMN_CASEDEF;
DROP TABLE IF EXISTS ACT_CMMN_DATABASECHANGELOG;
DROP TABLE IF EXISTS ACT_CMMN_DATABASECHANGELOGLOCK;
DROP TABLE IF EXISTS ACT_CMMN_DEPLOYMENT;
DROP TABLE IF EXISTS ACT_CMMN_DEPLOYMENT_RESOURCE;
DROP TABLE IF EXISTS ACT_CMMN_HI_CASE_INST;
DROP TABLE IF EXISTS ACT_CMMN_HI_MIL_INST;
DROP TABLE IF EXISTS ACT_CMMN_HI_PLAN_ITEM_INST;
DROP TABLE IF EXISTS ACT_CMMN_RU_CASE_INST;
DROP TABLE IF EXISTS ACT_CMMN_RU_MIL_INST;
DROP TABLE IF EXISTS ACT_CMMN_RU_PLAN_ITEM_INST;
DROP TABLE IF EXISTS ACT_CMMN_RU_SENTRY_PART_INST;
DROP TABLE IF EXISTS ACT_CO_CONTENT_ITEM;
DROP TABLE IF EXISTS ACT_CO_DATABASECHANGELOG;
DROP TABLE IF EXISTS ACT_CO_DATABASECHANGELOGLOCK;
DROP TABLE IF EXISTS ACT_DMN_DATABASECHANGELOG;
DROP TABLE IF EXISTS ACT_DMN_DATABASECHANGELOGLOCK;
DROP TABLE IF EXISTS ACT_DMN_DECISION_TABLE;
DROP TABLE IF EXISTS ACT_DMN_DEPLOYMENT;
DROP TABLE IF EXISTS ACT_DMN_DEPLOYMENT_RESOURCE;
DROP TABLE IF EXISTS ACT_DMN_HI_DECISION_EXECUTION;
DROP TABLE IF EXISTS ACT_EVT_LOG;
DROP TABLE IF EXISTS ACT_FO_DATABASECHANGELOG;
DROP TABLE IF EXISTS ACT_FO_DATABASECHANGELOGLOCK;
DROP TABLE IF EXISTS ACT_GE_PROPERTY;
DROP TABLE IF EXISTS ACT_HI_ATTACHMENT;
DROP TABLE IF EXISTS ACT_HI_DETAIL;
DROP TABLE IF EXISTS ACT_HI_ENTITYLINK;
DROP TABLE IF EXISTS ACT_HI_IDENTITYLINK;
DROP TABLE IF EXISTS ACT_HI_TSK_LOG;
DROP TABLE IF EXISTS ACT_ID_BYTEARRAY;
DROP TABLE IF EXISTS ACT_ID_GROUP;
DROP TABLE IF EXISTS ACT_ID_INFO;
DROP TABLE IF EXISTS ACT_ID_MEMBERSHIP;
DROP TABLE IF EXISTS ACT_ID_PRIV;
DROP TABLE IF EXISTS ACT_ID_PRIV_MAPPING;
DROP TABLE IF EXISTS ACT_ID_PROPERTY;
DROP TABLE IF EXISTS ACT_ID_TOKEN;
DROP TABLE IF EXISTS ACT_ID_USER;
DROP TABLE IF EXISTS ACT_PROCDEF_INFO;
DROP TABLE IF EXISTS ACT_RE_MODEL;
DROP TABLE IF EXISTS ACT_RU_DEADLETTER_JOB;
DROP TABLE IF EXISTS ACT_RU_ENTITYLINK;
DROP TABLE IF EXISTS ACT_RU_EVENT_SUBSCR;
DROP TABLE IF EXISTS ACT_RU_HISTORY_JOB;
DROP TABLE IF EXISTS ACT_RU_SUSPENDED_JOB;
DROP TABLE IF EXISTS ACT_RU_TIMER_JOB;


CREATE TABLE ACT_DE_MODEL  (
                               ID varchar(255) NOT NULL,
                               NAME varchar(400) NOT NULL,
                               MODEL_KEY varchar(400) NOT NULL,
                               DESCRIPTION varchar(4000) ,
                               MODEL_COMMENT varchar(4000) ,
                               CREATED datetime(6) ,
                               CREATED_BY varchar(255) ,
                               LAST_UPDATED datetime(6) ,
                               LAST_UPDATED_BY varchar(255) ,
                               VERSION int(11) ,
                               MODEL_EDITOR_JSON longtext,
                               THUMBNAIL longblob,
                               MODEL_TYPE int(11) ,
                               TENANT_ID varchar(255),
                               PRIMARY KEY (ID),
                               INDEX IDX_PROC_MOD_CREATED(CREATED_BY) USING BTREE
);


CREATE TABLE ACT_DE_MODEL_HISTORY (
                                      ID varchar(255) NOT NULL,
                                      NAME varchar(400) NOT NULL,
                                      MODEL_KEY varchar(400) NOT NULL,
                                      DESCRIPTION varchar(4000) ,
                                      MODEL_COMMENT varchar(4000) ,
                                      CREATED datetime(6) ,
                                      CREATED_BY varchar(255) ,
                                      LAST_UPDATED datetime(6) ,
                                      LAST_UPDATED_BY varchar(255) ,
                                      REMOVAL_DATE datetime(6) ,
                                      VERSION int(11) ,
                                      MODEL_EDITOR_JSON longtext,
                                      MODEL_ID varchar(255) NOT NULL,
                                      MODEL_TYPE int(11) ,
                                      TENANT_ID varchar(255) ,
                                      PRIMARY KEY (ID) USING BTREE,
                                      INDEX IDX_PROC_MOD_HISTORY_PROC(MODEL_ID) USING BTREE
);


CREATE TABLE ACT_DE_MODEL_RELATION  (
                                        ID varchar(255) NOT NULL,
                                        PARENT_MODEL_ID varchar(255) ,
                                        MODEL_ID varchar(255) ,
                                        RELATION_TYPE varchar(255) ,
                                        PRIMARY KEY (ID) USING BTREE,
                                        INDEX FK_RELATION_PARENT(PARENT_MODEL_ID) USING BTREE,
                                        INDEX FK_RELATION_CHILD(MODEL_ID) USING BTREE,
                                        CONSTRAINT FK_RELATION_CHILD FOREIGN KEY (MODEL_ID) REFERENCES ACT_DE_MODEL (ID) ON DELETE RESTRICT ON UPDATE RESTRICT,
                                        CONSTRAINT FK_RELATION_PARENT FOREIGN KEY (PARENT_MODEL_ID) REFERENCES ACT_DE_MODEL (ID) ON DELETE RESTRICT ON UPDATE RESTRICT
);


create or replace view OA_SUMMARY_VIEW as
select ID,BUESSINESSNO,USERID,USERNAME,CATEGORY,CATEGORYID,FILEANNEX,STATES,GUIDANG,ASSIGNEE,ASSIGNEENAME,CREATEUSER,CREATEDATE,DEPLOYMENTID,PROCESSDEFINITIONID,CREATEUSERNAME,PROCESSINSTANCEID,TENANTID,PACKAGEID
FROM ocr_taskchild_picture
;