
CREATE TABLE PARTY_ENTITY(
        ID BIGINT NOT NULL,
        TYPE_ID BIGINT,
        NAME VARCHAR(100),
	REF VARCHAR(100),
	SCOPE_ID VARCHAR(50),
        CONSTRAINT PK_PARTY_ENTITY PRIMARY KEY(ID),
        CONSTRAINT FK_PARTY_ENTITY_TYPE FOREIGN KEY(TYPE_ID) REFERENCES PARTY_TYPE(ID)
);

CREATE INDEX I_PARTY_ENTITY_REFERENCE_TYPE ON PARTY_ENTITY(REF, TYPE_ID);

CREATE INDEX I_PARTY_ENTITY_NAME ON PARTY_ENTITY(NAME);

COMMENT ON TABLE PARTY_ENTITY IS '组织实体';
COMMENT ON COLUMN PARTY_ENTITY.ID IS '主键';
COMMENT ON COLUMN PARTY_ENTITY.TYPE_ID IS '外键，组织类型';
COMMENT ON COLUMN PARTY_ENTITY.NAME IS '名称';
COMMENT ON COLUMN PARTY_ENTITY.REF IS '外部引用';
COMMENT ON COLUMN PARTY_ENTITY.SCOPE_ID IS '租户';
