Fixed ambitious schema update

This commit is contained in:
Nick 2020-12-08 10:12:28 -05:00
parent d3c0944388
commit 6018dd0537
3 changed files with 33 additions and 26 deletions

View File

@ -55,7 +55,8 @@ public class ResourceTableFKProvider {
retval.add(new ResourceForeignKey("HFJ_SPIDX_URI", "RES_ID"));
retval.add(new ResourceForeignKey("HFJ_SUBSCRIPTION_STATS", "RES_ID"));
retval.add(new ResourceForeignKey("MPI_LINK", "GOLDEN_RESOURCE_PID"));
retval.add(new ResourceForeignKey("MPI_LINK", "SOURCE_PID"));
retval.add(new ResourceForeignKey("MPI_LINK", "TARGET_PID"));
retval.add(new ResourceForeignKey("MPI_LINK", "PERSON_PID"));
retval.add(new ResourceForeignKey("NPM_PACKAGE_VER", "BINARY_RES_ID"));
retval.add(new ResourceForeignKey("NPM_PACKAGE_VER_RES", "BINARY_RES_ID"));
retval.add(new ResourceForeignKey("TRM_CODESYSTEM", "RES_ID"));

View File

@ -45,7 +45,7 @@ import java.util.Date;
@Entity
@Table(name = "MPI_LINK", uniqueConstraints = {
@UniqueConstraint(name = "IDX_MDM_GOLDEN_RESOURCE_SRC", columnNames = {"GOLDEN_RESOURCE_PID", "SOURCE_PID"}),
@UniqueConstraint(name = "IDX_EMPI_PERSON_TGT", columnNames = {"PERSON_PID", "TARGET_PID"}),
})
public class MdmLink {
public static final int VERSION_LENGTH = 16;
@ -60,17 +60,26 @@ public class MdmLink {
private Long myId;
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "GOLDEN_RESOURCE_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_MDM_LINK_GOLDEN_RESOURCE"), insertable=false, updatable=false, nullable=false)
@JoinColumn(name = "GOLDEN_RESOURCE_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_EMPI_LINK_GOLDEN_RESOURCE"), insertable=false, updatable=false, nullable=false)
private ResourceTable myGoldenResource;
@Column(name = "GOLDEN_RESOURCE_PID", nullable=false)
private Long myGoldenResourcePid;
@Deprecated
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "SOURCE_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_MDM_LINK_SOURCE"), insertable=false, updatable=false, nullable=false)
@JoinColumn(name = "PERSON_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_EMPI_LINK_PERSON"), insertable=false, updatable=false, nullable=false)
private ResourceTable myPerson;
@Deprecated
@Column(name = "PERSON_PID", nullable=false)
private Long myPersonPid;
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "TARGET_PID", referencedColumnName = "RES_ID", foreignKey = @ForeignKey(name = "FK_EMPI_LINK_TARGET"), insertable=false, updatable=false, nullable=false)
private ResourceTable mySource;
@Column(name = "SOURCE_PID", updatable=false, nullable=false)
@Column(name = "TARGET_PID", updatable=false, nullable=false)
private Long mySourcePid;
@Column(name = "MATCH_RESULT", nullable = false)
@ -97,7 +106,7 @@ public class MdmLink {
private Boolean myEidMatch;
/** This link created a new person **/
@Column(name = "NEW_GOLDEN_RESOURCE")
@Column(name = "NEW_PERSON")
private Boolean myHadToCreateNewGoldenResource;
@Column(name = "VECTOR")
@ -116,7 +125,7 @@ public class MdmLink {
myVersion = theVersion;
}
@Column(name = "SOURCE_TYPE", nullable = true, length = SOURCE_TYPE_LENGTH)
@Column(name = "TARGET_TYPE", nullable = true, length = SOURCE_TYPE_LENGTH)
private String myMdmSourceType;
public Long getId() {
@ -135,6 +144,10 @@ public class MdmLink {
public MdmLink setGoldenResource(ResourceTable theGoldenResource) {
myGoldenResource = theGoldenResource;
myGoldenResourcePid = theGoldenResource.getId();
myPerson = theGoldenResource;
myPersonPid = theGoldenResource.getId();
return this;
}
@ -142,7 +155,18 @@ public class MdmLink {
return myGoldenResourcePid;
}
/**
* @deprecated Use {@link #setGoldenResourcePid(Long)} instead
*/
@Deprecated
public MdmLink setPersonPid(Long thePersonPid) {
myPersonPid = thePersonPid;
return this;
}
public MdmLink setGoldenResourcePid(Long theGoldenResourcePid) {
setPersonPid(theGoldenResourcePid);
myGoldenResourcePid = theGoldenResourcePid;
return this;
}

View File

@ -80,27 +80,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
mdmLink.addColumn("20201029.1", "GOLDEN_RESOURCE_PID").nonNullable().type(ColumnTypeEnum.LONG);
mdmLink.addColumn("20201029.2", "RULE_COUNT").nullable().type(ColumnTypeEnum.LONG);
mdmLink
.addForeignKey("20201029.3", "FK_MDM_LINK_GOLDEN_RESOURCE")
.addForeignKey("20201029.3", "FK_EMPI_LINK_GOLDEN_RESOURCE")
.toColumn("GOLDEN_RESOURCE_PID")
.references("HFJ_RESOURCE", "RES_ID");
mdmLink.dropIndex("20201029.4", "IDX_EMPI_PERSON_TGT");
mdmLink.dropForeignKey("20201029.5", "FK_EMPI_LINK_TARGET", "HFJ_RESOURCE");
mdmLink.dropForeignKey("20201029.6", "FK_EMPI_LINK_PERSON", "HFJ_RESOURCE");
mdmLink.renameColumn("20201029.7", "NEW_PERSON", "NEW_GOLDEN_RESOURCE");
mdmLink.renameColumn("20201029.8", "TARGET_PID", "SOURCE_PID");
mdmLink.renameColumn("20201029.9", "TARGET_TYPE", "SOURCE_TYPE");
mdmLink
.addForeignKey("20201029.10", "FK_MDM_LINK_SOURCE")
.toColumn("SOURCE_PID")
.references("HFJ_RESOURCE", "RES_ID");
mdmLink.addIndex("20201029.11", "IDX_MDM_GOLDEN_RESOURCE_SRC")
.unique(true).withColumns("GOLDEN_RESOURCE_PID", "SOURCE_PID");
mdmLink.dropColumn("20201029.12", "PERSON_PID");
}
protected void init510() {