CREATE TABLE OPERATIONAL_INFO (
    CREATED              TIMESTAMP NOT NULL,
    MODIFIED             TIMESTAMP NULL,
    MODIFIED_INCLUDING_CHILDREN TIMESTAMP NULL,
    NODE_ID              VARCHAR2(255) NULL,
    AUTHORIZED_NAME      VARCHAR2(255) NULL,
    ENTITY_KEY           VARCHAR2(255) NOT NULL,
    FORMAT_KEY           VARCHAR2(255) NOT NULL,
    DELETED              VARCHAR2(5) NULL,
    PRIMARY KEY (ENTITY_KEY)
);

CREATE TABLE BUSINESS_ENTITY (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    AUTHORIZED_NAME      VARCHAR2(255) NOT NULL,
    PUBLISHER_ID         VARCHAR2(20) NULL,
    OPERATOR             VARCHAR2(255) NOT NULL,
    LAST_UPDATE          TIMESTAMP NOT NULL,
    DELETED              VARCHAR2(5) NULL,
    PRIMARY KEY (BUSINESS_KEY)
);

CREATE TABLE BUSINESS_DESCR (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    BUSINESS_DESCR_ID    NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, BUSINESS_DESCR_ID),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE BUSINESS_CATEGORY (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CATEGORY_ID          NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, CATEGORY_ID),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE BUSINESS_CATEGORY_KEY_REF_GRP (
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, KEY_REF_GROUP_ID), 
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE BUSINESS_CATEGORY_REF_GRP_KEY (
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    KEY_REF_GROUP_KEY_ID NUMBER(10) NOT NULL,
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, KEY_REF_GROUP_ID, KEY_REF_GROUP_KEY_ID), 
    FOREIGN KEY (BUSINESS_KEY, KEY_REF_GROUP_ID)
        REFERENCES BUSINESS_CATEGORY_KEY_REF_GRP (BUSINESS_KEY, KEY_REF_GROUP_ID)
);

CREATE TABLE BUSINESS_IDENTIFIER (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    IDENTIFIER_ID        NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, IDENTIFIER_ID),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE BUSINESS_NAME (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    BUSINESS_NAME_ID     NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    NAME                 VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, BUSINESS_NAME_ID),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE CONTACT (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    USE_TYPE             VARCHAR2(255) NULL,
    PERSON_NAME          VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE CONTACT_DESCR (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    CONTACT_DESCR_ID     NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID, CONTACT_DESCR_ID),
    FOREIGN KEY (BUSINESS_KEY, CONTACT_ID)
        REFERENCES CONTACT (BUSINESS_KEY, CONTACT_ID)
);

CREATE TABLE PERSON_NAME (
    NAME                 VARCHAR2(255) NULL,
    PERSON_NAME_ID       NUMBER(10) NOT NULL,
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID, PERSON_NAME_ID), 
    FOREIGN KEY (BUSINESS_KEY, CONTACT_ID)
        REFERENCES CONTACT (BUSINESS_KEY, CONTACT_ID)
);

CREATE TABLE ADDRESS (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    ADDRESS_ID           NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    USE_TYPE             VARCHAR2(255) NULL,
    SORT_CODE            VARCHAR2(10) NULL,
    TMODEL_KEY           VARCHAR2(255) NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID, ADDRESS_ID),
    FOREIGN KEY (BUSINESS_KEY, CONTACT_ID)
        REFERENCES CONTACT (BUSINESS_KEY, CONTACT_ID)
);

CREATE TABLE ADDRESS_LINE (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    ADDRESS_ID           NUMBER(10) NOT NULL,
    ADDRESS_LINE_ID      NUMBER(10) NOT NULL,
    LINE                 VARCHAR2(80) NOT NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID, ADDRESS_ID, ADDRESS_LINE_ID),
    FOREIGN KEY (BUSINESS_KEY, CONTACT_ID, ADDRESS_ID)
        REFERENCES ADDRESS (BUSINESS_KEY, CONTACT_ID, ADDRESS_ID)
);

CREATE TABLE EMAIL (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    EMAIL_ID             NUMBER(10) NOT NULL,
    USE_TYPE             VARCHAR2(255) NULL,
    EMAIL_ADDRESS        VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID, EMAIL_ID),
    FOREIGN KEY (BUSINESS_KEY, CONTACT_ID)
        REFERENCES CONTACT (BUSINESS_KEY, CONTACT_ID)
);

CREATE TABLE PHONE (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    CONTACT_ID           NUMBER(10) NOT NULL,
    PHONE_ID             NUMBER(10) NOT NULL,
    USE_TYPE             VARCHAR2(255) NULL,
    PHONE_NUMBER         VARCHAR2(50) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, CONTACT_ID, PHONE_ID),
    FOREIGN KEY (BUSINESS_KEY, CONTACT_ID)
        REFERENCES CONTACT (BUSINESS_KEY,CONTACT_ID)
);

CREATE TABLE DISCOVERY_URL (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    DISCOVERY_URL_ID     NUMBER(10) NOT NULL,
    USE_TYPE             VARCHAR2(255) NOT NULL,
    URL                  VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BUSINESS_KEY, DISCOVERY_URL_ID),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE BUSINESS_SERVICE (
    BUSINESS_KEY         VARCHAR2(255) NOT NULL,
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    LAST_UPDATE          TIMESTAMP NOT NULL,
    DELETED              VARCHAR2(5) NULL,
    PRIMARY KEY (SERVICE_KEY),
    FOREIGN KEY (BUSINESS_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY)
);

CREATE TABLE SERVICE_DESCR (
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    SERVICE_DESCR_ID     NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (SERVICE_KEY, SERVICE_DESCR_ID),
    FOREIGN KEY (SERVICE_KEY)
        REFERENCES BUSINESS_SERVICE (SERVICE_KEY)
);

CREATE TABLE SERVICE_CATEGORY (
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    CATEGORY_ID          NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    PRIMARY KEY (SERVICE_KEY, CATEGORY_ID),
    FOREIGN KEY (SERVICE_KEY)
        REFERENCES BUSINESS_SERVICE (SERVICE_KEY)
);

CREATE TABLE SERVICE_CATEGORY_KEY_REF_GRP (
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    PRIMARY KEY (KEY_REF_GROUP_ID, SERVICE_KEY), 
    FOREIGN KEY (SERVICE_KEY)
        REFERENCES BUSINESS_SERVICE (SERVICE_KEY)
);

CREATE TABLE SERVICE_CATEGORY_REF_GRP_KEY (
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    KEY_REF_GROUP_KEY_ID NUMBER(10) NOT NULL,
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    PRIMARY KEY (KEY_REF_GROUP_ID, KEY_REF_GROUP_KEY_ID, SERVICE_KEY), 
    FOREIGN KEY (KEY_REF_GROUP_ID, SERVICE_KEY)
        REFERENCES SERVICE_CATEGORY_KEY_REF_GRP (KEY_REF_GROUP_ID, SERVICE_KEY)
);

CREATE TABLE SERVICE_NAME (
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    SERVICE_NAME_ID      NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    NAME                 VARCHAR2(255) NOT NULL,
    PRIMARY KEY (SERVICE_KEY, SERVICE_NAME_ID),
    FOREIGN KEY (SERVICE_KEY)
        REFERENCES BUSINESS_SERVICE (SERVICE_KEY)
);

CREATE TABLE BINDING_TEMPLATE (
    SERVICE_KEY          VARCHAR2(255) NOT NULL,
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    ACCESS_POINT_TYPE    VARCHAR2(20) NULL,
    ACCESS_POINT_URL     VARCHAR2(255) NULL,
    HOSTING_REDIRECTOR   VARCHAR2(255) NULL,
    LAST_UPDATE          TIMESTAMP NOT NULL,
    DELETED              VARCHAR2(5) NULL,
    PRIMARY KEY (BINDING_KEY),
    FOREIGN KEY (SERVICE_KEY)
        REFERENCES BUSINESS_SERVICE (SERVICE_KEY)
);

CREATE TABLE BINDING_CATEGORY (
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    CATEGORY_ID          NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BINDING_KEY, CATEGORY_ID),
    FOREIGN KEY (BINDING_KEY)
        REFERENCES BINDING_TEMPLATE (BINDING_KEY)
);

CREATE TABLE BINDING_CATEGORY_KEY_REF_GRP (
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BINDING_KEY, KEY_REF_GROUP_ID), 
    FOREIGN KEY (BINDING_KEY)
        REFERENCES BINDING_TEMPLATE (BINDING_KEY)
);

CREATE TABLE BINDING_CATEGORY_REF_GRP_KEY (
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    KEY_REF_GROUP_KEY_ID NUMBER(10) NOT NULL,
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BINDING_KEY, KEY_REF_GROUP_ID, KEY_REF_GROUP_KEY_ID), 
    FOREIGN KEY (BINDING_KEY, KEY_REF_GROUP_ID)
        REFERENCES BINDING_CATEGORY_KEY_REF_GRP (BINDING_KEY, KEY_REF_GROUP_ID)
);

CREATE TABLE BINDING_DESCR (
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    BINDING_DESCR_ID     NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BINDING_KEY, BINDING_DESCR_ID),
    FOREIGN KEY (BINDING_KEY)
        REFERENCES BINDING_TEMPLATE (BINDING_KEY)
);

CREATE TABLE TMODEL_INSTANCE_INFO (
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    TMODEL_INSTANCE_INFO_ID NUMBER(10) NOT NULL,
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    OVERVIEW_URL         VARCHAR2(255) NULL,
    INSTANCE_PARMS       VARCHAR2(255) NULL,
    PRIMARY KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID),
    FOREIGN KEY (BINDING_KEY)
        REFERENCES BINDING_TEMPLATE (BINDING_KEY)
);

CREATE TABLE TMODEL_INSTANCE_INFO_DESCR (
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    TMODEL_INSTANCE_INFO_ID NUMBER(10) NOT NULL,
    TMODEL_INSTANCE_INFO_DESCR_ID NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID, TMODEL_INSTANCE_INFO_DESCR_ID),
    FOREIGN KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID)
        REFERENCES TMODEL_INSTANCE_INFO (BINDING_KEY, TMODEL_INSTANCE_INFO_ID)
);

CREATE TABLE INSTANCE_DETAILS_DESCR (
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    TMODEL_INSTANCE_INFO_ID NUMBER(10) NOT NULL,
    INSTANCE_DETAILS_DESCR_ID NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID, INSTANCE_DETAILS_DESCR_ID),
    FOREIGN KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID)
        REFERENCES TMODEL_INSTANCE_INFO (BINDING_KEY, TMODEL_INSTANCE_INFO_ID)
);

CREATE TABLE INSTANCE_DETAILS_DOC (
    INSTANCE_DETAILS_DOC_ID NUMBER(10) NOT NULL,
    USE_TYPE             VARCHAR2(255) NULL,
    OVERVIEW_URL         VARCHAR2(255) NOT NULL,
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    TMODEL_INSTANCE_INFO_ID NUMBER(10) NOT NULL,
    PRIMARY KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID, INSTANCE_DETAILS_DOC_ID), 
    FOREIGN KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID)
        REFERENCES TMODEL_INSTANCE_INFO (BINDING_KEY, TMODEL_INSTANCE_INFO_ID)
);

CREATE TABLE INSTANCE_DETAILS_DOC_DESCR (
    BINDING_KEY          VARCHAR2(255) NOT NULL,
    TMODEL_INSTANCE_INFO_ID NUMBER(10) NOT NULL,
    INSTANCE_DETAILS_DOC_DESCR_ID NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    INSTANCE_DETAILS_DOC_ID NUMBER(10) NOT NULL,
    PRIMARY KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID, INSTANCE_DETAILS_DOC_ID, INSTANCE_DETAILS_DOC_DESCR_ID), 
    FOREIGN KEY (BINDING_KEY, TMODEL_INSTANCE_INFO_ID, INSTANCE_DETAILS_DOC_ID)
        REFERENCES INSTANCE_DETAILS_DOC (BINDING_KEY, TMODEL_INSTANCE_INFO_ID, INSTANCE_DETAILS_DOC_ID)
);

CREATE TABLE TMODEL (
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    AUTHORIZED_NAME      VARCHAR2(255) NOT NULL,
    PUBLISHER_ID         VARCHAR2(20) NULL,
    OPERATOR             VARCHAR2(255) NOT NULL,
    NAME                 VARCHAR2(255) NOT NULL,
    OVERVIEW_URL         VARCHAR2(255) NULL,
    LAST_UPDATE          TIMESTAMP NOT NULL,
    DELETED              VARCHAR2(5) NULL,
    PRIMARY KEY (TMODEL_KEY)
);

CREATE TABLE TMODEL_DESCR (
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    TMODEL_DESCR_ID      NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    PRIMARY KEY (TMODEL_KEY, TMODEL_DESCR_ID),
    FOREIGN KEY (TMODEL_KEY)
        REFERENCES TMODEL (TMODEL_KEY)
);

CREATE TABLE TMODEL_CATEGORY (
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    CATEGORY_ID          NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    PRIMARY KEY (TMODEL_KEY, CATEGORY_ID),
    FOREIGN KEY (TMODEL_KEY)
        REFERENCES TMODEL (TMODEL_KEY)
);

CREATE TABLE TMODEL_CATEGORY_KEY_REF_GRP (
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    PRIMARY KEY (TMODEL_KEY, KEY_REF_GROUP_ID), 
    FOREIGN KEY (TMODEL_KEY)
        REFERENCES TMODEL (TMODEL_KEY)
);

CREATE TABLE TMODEL_CATEGORY_REF_GRP_KEY (
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    KEY_REF_GROUP_KEY_ID NUMBER(10) NOT NULL,
    KEY_REF_GROUP_ID     NUMBER(10) NOT NULL,
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    PRIMARY KEY (TMODEL_KEY, KEY_REF_GROUP_ID, KEY_REF_GROUP_KEY_ID), 
    FOREIGN KEY (TMODEL_KEY, KEY_REF_GROUP_ID)
        REFERENCES TMODEL_CATEGORY_KEY_REF_GRP (TMODEL_KEY, KEY_REF_GROUP_ID)
);

CREATE TABLE TMODEL_IDENTIFIER (
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    IDENTIFIER_ID        NUMBER(10) NOT NULL,
    TMODEL_KEY_REF       VARCHAR2(255) NULL,
    KEY_NAME             VARCHAR2(255) NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    PRIMARY KEY (TMODEL_KEY, IDENTIFIER_ID),
    FOREIGN KEY (TMODEL_KEY)
        REFERENCES TMODEL (TMODEL_KEY)
);

CREATE TABLE TMODEL_DOC (
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    TMODEL_DOC_ID        NUMBER(10) NOT NULL,
    OVERVIEW_URL         VARCHAR2(255) NULL,
    USE_TYPE             VARCHAR2(255) NULL,
    PRIMARY KEY (TMODEL_KEY, TMODEL_DOC_ID), 
    FOREIGN KEY (TMODEL_KEY)
        REFERENCES TMODEL (TMODEL_KEY)
);

CREATE TABLE TMODEL_DOC_DESCR (
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    TMODEL_DOC_DESCR_ID  NUMBER(10) NOT NULL,
    LANG_CODE            VARCHAR2(5) NULL,
    DESCR                VARCHAR2(255) NOT NULL,
    TMODEL_DOC_ID        NUMBER(10) NOT NULL,
    PRIMARY KEY (TMODEL_KEY, TMODEL_DOC_ID, TMODEL_DOC_DESCR_ID), 
    FOREIGN KEY (TMODEL_KEY, TMODEL_DOC_ID)
        REFERENCES TMODEL_DOC (TMODEL_KEY, TMODEL_DOC_ID)
);

CREATE TABLE PUBLISHER_ASSERTION (
    FROM_KEY             VARCHAR2(255) NOT NULL,
    TO_KEY               VARCHAR2(255) NOT NULL,
    TMODEL_KEY           VARCHAR2(255) NOT NULL,
    KEY_NAME             VARCHAR2(255) NOT NULL,
    KEY_VALUE            VARCHAR2(255) NOT NULL,
    FROM_CHECK           VARCHAR2(5) NOT NULL,
    TO_CHECK             VARCHAR2(5) NOT NULL,
    LAST_UPDATE          TIMESTAMP NOT NULL,
    FOREIGN KEY (FROM_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY),
    FOREIGN KEY (TO_KEY)
        REFERENCES BUSINESS_ENTITY (BUSINESS_KEY) 
);

CREATE TABLE PUBLISHER (
    PUBLISHER_ID         VARCHAR2(20) NOT NULL,
    PUBLISHER_NAME       VARCHAR2(255) NOT NULL,
    EMAIL_ADDRESS        VARCHAR2(255) NULL,
    IS_ADMIN             VARCHAR2(5) NULL,
    IS_ENABLED           VARCHAR2(5) NULL,
    PRIMARY KEY (PUBLISHER_ID)
);

CREATE TABLE AUTH_TOKEN (
    AUTH_TOKEN           VARCHAR2(51) NOT NULL,
    PUBLISHER_ID         VARCHAR2(20) NOT NULL,
    PUBLISHER_NAME       VARCHAR2(255) NOT NULL,
    CREATED              TIMESTAMP NOT NULL,
    LAST_USED            TIMESTAMP NOT NULL,
    NUMBER_OF_USES       NUMBER(10) NOT NULL,
    TOKEN_STATE          NUMBER(10) NOT NULL,
    PRIMARY KEY (AUTH_TOKEN)
);

CREATE TABLE ENTITY_SIGNATURE (
    ENTITY_KEY           VARCHAR2(255) NOT NULL,
    SIG_ID               NUMBER(10) NOT NULL,
    SIGNATURE            BLOB NULL
);

CREATE TABLE PUBLISHER_ASSERTION_SIGNATURE (
    ENTITY_KEY           VARCHAR2(255) NOT NULL,
    SIG_ID               NUMBER(10) NOT NULL,
    SIGNATURE            BLOB NULL,
    FROM_CHECK           VARCHAR2(5) NOT NULL,
    TO_CHECK             VARCHAR2(5) NOT NULL
);

CREATE TABLE SUBSCRIPTION (
    SUBSCRIPTION_KEY     VARCHAR2(255) NOT NULL,
    PUBLISHER_ID         VARCHAR2(20) NULL,
    SUBSCRIPTION_FILTER  BLOB NULL,
    BINDING_KEY          VARCHAR2(255) NULL,
    NOTIFICATION_INTERVAL VARCHAR2(20) NULL,
    MAX_ENTITIES         NUMBER(10) NULL,
    EXPIRES_AFTER        TIMESTAMP NULL,
    BRIEF                VARCHAR2(5) NULL,
    PRIMARY KEY (SUBSCRIPTION_KEY)
);

CREATE TABLE NOTIFICATION (
    SUBSCRIPTION_KEY     VARCHAR2(255) NOT NULL,
    LAST_NOTIFICATION    TIMESTAMP NULL,
    LAST_UPDATE          TIMESTAMP NULL,
    FOREIGN KEY (SUBSCRIPTION_KEY) 
        REFERENCES SUBSCRIPTION (SUBSCRIPTION_KEY) 
);

CREATE TABLE HIGHWATERMARK (
    NODE_ID              VARCHAR2(255) NOT NULL,
    LAST_UPDATE          TIMESTAMP NULL,
    HIGHWATERMARKS       BLOB NULL,
    PRIMARY KEY (NODE_ID)
);

CREATE TABLE CHANGERECORD (
    LOCAL_USN            NUMBER(10) NOT NULL,
    NODE_ID              VARCHAR2(255) NOT NULL,
    OPERATING_USN        NUMBER(10) NOT NULL,
    LAST_UPDATE          TIMESTAMP NULL,
    CHANGERECORD_TYPE    NUMBER(10) NOT NULL,
    CHANGERECORD_ENTITY_KEY VARCHAR2(255) NOT NULL,
    CHANGERECORD_BYTES   BLOB NULL,
    UNIQUE (NODE_ID,OPERATING_USN),
    PRIMARY KEY (LOCAL_USN)
);
