
CREATE TABLE PARTY_STRUCT_RULE(
        STRUCT_TYPE_ID BIGINT NOT NULL,
        PARENT_TYPE_ID BIGINT NOT NULL,
	CHILD_TYPE_ID BIGINT NOT NULL,
	DIM_ID BIGINT,
	SCOPE_ID VARCHAR(50),
        CONSTRAINT PK_PARTY_STRUCT_RULE PRIMARY KEY(STRUCT_TYPE_ID,PARENT_TYPE_ID,CHILD_TYPE_ID),
        CONSTRAINT FK_PARTY_STRUCT_RULE_TYPE FOREIGN KEY(STRUCT_TYPE_ID) REFERENCES PARTY_STRUCT_TYPE(ID),
        CONSTRAINT FK_PARTY_STRUCT_RULE_TYPE_PARENT FOREIGN KEY(PARENT_TYPE_ID) REFERENCES PARTY_TYPE(ID),
        CONSTRAINT FK_PARTY_STRUCT_RULE_TYPE_CHILD FOREIGN KEY(CHILD_TYPE_ID) REFERENCES PARTY_TYPE(ID),
        CONSTRAINT FK_PARTY_STRUCT_RULE_DIM FOREIGN KEY(DIM_ID) REFERENCES PARTY_DIM(ID)
);

COMMENT ON TABLE PARTY_STRUCT_RULE IS '组织关系规则';
COMMENT ON COLUMN PARTY_STRUCT_RULE.STRUCT_TYPE_ID IS '外键，组织关系类型';
COMMENT ON COLUMN PARTY_STRUCT_RULE.PARENT_TYPE_ID IS '外键，上级类型';
COMMENT ON COLUMN PARTY_STRUCT_RULE.CHILD_TYPE_ID IS '外键，下级类型';
COMMENT ON COLUMN PARTY_STRUCT_RULE.SCOPE_ID IS '租户';
