From 05df4f082731edd4a97660a329aa37242623e437 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 10 Jun 2020 09:56:49 -0400 Subject: [PATCH] Migration task updates --- .../fhir/jpa/packages/JpaPackageCache.java | 3 +- .../tasks/HapiFhirJpaMigrationTasks.java | 68 +++++++++++++++---- .../model/entity/NpmPackageVersionEntity.java | 16 +---- .../NpmPackageVersionResourceEntity.java | 8 +-- 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/JpaPackageCache.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/JpaPackageCache.java index a4c1d69ab49..6b71e5f0258 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/JpaPackageCache.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/packages/JpaPackageCache.java @@ -237,7 +237,6 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac packageVersion.setFhirVersion(fhirVersion); packageVersion.setCurrentVersion(currentVersion); packageVersion.setPackageSizeBytes(bytes.length); - packageVersion.setName(npmPackage.name()); packageVersion = myPackageVersionDao.save(packageVersion); String dirName = "package"; @@ -469,7 +468,7 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac NpmPackageMetadataJson.Version version = new NpmPackageMetadataJson.Version(); version.setFhirVersion(next.getFhirVersionId()); version.setDescription(next.getDescription()); - version.setName(next.getName()); + version.setName(next.getPackageId()); version.setVersion(next.getVersionId()); version.setBytes(next.getPackageSizeBytes()); retVal.addVersion(version); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java index 80fe4746e7a..60101f22b16 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java @@ -75,7 +75,52 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { private void init510() { Builder version = forVersion(VersionEnum.V5_1_0); -// version.addTableByColumns("20200524.1", "") + // NPM Packages + version.addIdGenerator("20200610.1", "SEQ_NPM_PACK"); + Builder.BuilderAddTableByColumns pkg = version.addTableByColumns("20200610.2", "NPM_PACKAGE", "PID"); + pkg.addColumn("PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkg.addColumn("PACKAGE_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkg.addColumn("CUR_VERSION_ID").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkg.addColumn("UPDATED_TIME").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + pkg.addColumn("PACKAGE_DESC").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkg.addIndex("20200610.3", "IDX_PACK_ID").unique(true).withColumns("PACKAGE_ID"); + + version.addIdGenerator("20200610.4", "SEQ_NPM_PACKVER"); + Builder.BuilderAddTableByColumns pkgVer = version.addTableByColumns("20200610.5", "NPM_PACKAGE_VER", "PID"); + pkgVer.addColumn("PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVer.addColumn("PACKAGE_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVer.addColumn("VERSION_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVer.addColumn("PACKAGE_PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVer.addColumn("BINARY_RES_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVer.addColumn("SAVED_TIME").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + pkgVer.addColumn("PKG_DESC").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVer.addColumn("DESC_UPPER").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVer.addColumn("CURRENT_VERSION").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.BOOLEAN); + pkgVer.addColumn("FHIR_VERSION_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 10); + pkgVer.addColumn("FHIR_VERSION").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 10); + pkgVer.addColumn("PACKAGE_SIZE_BYTES").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVer.addColumn("UPDATED_TIME").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + pkgVer.addForeignKey("20200610.6", "FK_NPM_PKV_PKG").toColumn("PACKAGE_PID").references("NPM_PACKAGE", "PID"); + pkgVer.addForeignKey("20200610.7", "FK_NPM_PKV_RESID").toColumn("BINARY_RES_ID").references("HFJ_RESOURCE", "RES_ID"); + pkgVer.addIndex("20200610.8", "IDX_PACKVER").unique(true).withColumns("PACKAGE_ID", "VERSION_ID"); + + version.addIdGenerator("20200610.9", "SEQ_NPM_PACKVERRES"); + Builder.BuilderAddTableByColumns pkgVerRes = version.addTableByColumns("20200610.10", "NPM_PACKAGE_VER_RES", "PID"); + pkgVerRes.addColumn("PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVerRes.addColumn("PACKVER_PID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVerRes.addColumn("BINARY_RES_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVerRes.addColumn("FILE_DIR").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVerRes.addColumn("FILE_NAME").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVerRes.addColumn("RES_TYPE").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 40); + pkgVerRes.addColumn("CANONICAL_URL").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVerRes.addColumn("CANONICAL_VERSION").nullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 200); + pkgVerRes.addColumn("FHIR_VERSION_ID").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 10); + pkgVerRes.addColumn("FHIR_VERSION").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.STRING, 10); + pkgVerRes.addColumn("RES_SIZE_BYTES").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + pkgVerRes.addColumn("UPDATED_TIME").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.DATE_TIMESTAMP); + pkgVerRes.addForeignKey("20200610.11", "FK_NPM_PACKVERRES_PACKVER").toColumn("PACKVER_PID").references("NPM_PACKAGE_VER", "PID"); + pkgVerRes.addForeignKey("20200610.12", "FK_NPM_PKVR_RESID").toColumn("BINARY_RES_ID").references("HFJ_RESOURCE", "PID"); + pkgVerRes.addIndex("20200610.13", "IDX_PACKVERRES_URL").unique(false).withColumns("CANONICAL_URL"); } @@ -254,7 +299,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { protected void init420() { // 20191015 - 20200217 Builder version = forVersion(VersionEnum.V4_2_0); - // TermValueSetConceptDesignation + // TermValueSetConceptDesignation version.onTable("TRM_VALUESET_C_DESIGNATION").dropIndex("20200202.1", "IDX_VALUESET_C_DSGNTN_VAL").failureAllowed(); Builder.BuilderWithTableName searchTable = version.onTable("HFJ_SEARCH"); searchTable.dropIndex("20200203.1", "IDX_SEARCH_LASTRETURNED"); @@ -454,7 +499,6 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .renameColumn("20190722.29", "CODE", "CODEVAL", false, true); - // TermValueSet version.startSectionWithMessage("Processing table: TRM_VALUESET"); version.addIdGenerator("20190722.30", "SEQ_VALUESET_PID"); @@ -757,9 +801,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .nullable() .type(AddColumnTask.ColumnTypeEnum.LONG); spidxString - .addIndex("20180903.27","IDX_SP_STRING_HASH_EXCT") + .addIndex("20180903.27", "IDX_SP_STRING_HASH_EXCT") .unique(false) - .withColumns( "HASH_EXACT"); + .withColumns("HASH_EXACT"); spidxString .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.28") .setColumnName("HASH_NORM_PREFIX") @@ -797,17 +841,17 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .unique(false) .withColumns("HASH_IDENTITY"); spidxToken - .addIndex("20180903.36","IDX_SP_TOKEN_HASH_S") + .addIndex("20180903.36", "IDX_SP_TOKEN_HASH_S") .unique(false) - .withColumns( "HASH_SYS"); + .withColumns("HASH_SYS"); spidxToken .addIndex("20180903.37", "IDX_SP_TOKEN_HASH_SV") .unique(false) .withColumns("HASH_SYS_AND_VALUE"); spidxToken - .addIndex("20180903.38","IDX_SP_TOKEN_HASH_V") + .addIndex("20180903.38", "IDX_SP_TOKEN_HASH_V") .unique(false) - .withColumns( "HASH_VALUE"); + .withColumns("HASH_VALUE"); spidxToken .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.39") .setColumnName("HASH_IDENTITY") @@ -835,9 +879,9 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { .nullable() .type(AddColumnTask.ColumnTypeEnum.LONG); spidxUri - .addIndex("20180903.43","IDX_SP_URI_HASH_URI") + .addIndex("20180903.43", "IDX_SP_URI_HASH_URI") .unique(false) - .withColumns( "HASH_URI"); + .withColumns("HASH_URI"); spidxUri .addTask(new CalculateHashesTask(VersionEnum.V3_5_0, "20180903.44") .setColumnName("HASH_IDENTITY") @@ -893,7 +937,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { trmConcept .addIndex("20180903.51", "IDX_CONCEPT_UPDATED") .unique(false) - .withColumns( "CONCEPT_UPDATED"); + .withColumns("CONCEPT_UPDATED"); trmConcept .modifyColumn("20180903.52", "CODE") .nonNullable() diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionEntity.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionEntity.java index 0470f7b9e17..2669c5a6d43 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionEntity.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionEntity.java @@ -49,7 +49,7 @@ import java.util.List; @Entity() @Table(name = "NPM_PACKAGE_VER", uniqueConstraints = { }, indexes = { - @Index(name = "IDX_PACKVER", columnList = "PACKAGE_ID,VERSION_ID") + @Index(name = "IDX_PACKVER", columnList = "PACKAGE_ID,VERSION_ID", unique = true) }) public class NpmPackageVersionEntity { @@ -74,9 +74,9 @@ public class NpmPackageVersionEntity { @Temporal(TemporalType.TIMESTAMP) @Column(name = "SAVED_TIME", nullable = false) private Date mySavedTime; - @Column(name = "PKG_DESC", nullable = false, length = 500) + @Column(name = "PKG_DESC", nullable = false, length = 200) private String myDescription; - @Column(name = "DESC_UPPER", nullable = false, length = 500) + @Column(name = "DESC_UPPER", nullable = false, length = 200) private String myDescriptionUpper; @Column(name = "CURRENT_VERSION", nullable = false) private boolean myCurrentVersion; @@ -91,8 +91,6 @@ public class NpmPackageVersionEntity { @Version @Column(name = "UPDATED_TIME", nullable = false) private Date myUpdatedTime; - @Column(name = "PACKAGE_NAME", nullable = true, length = 200) - private String myName; @OneToMany(mappedBy = "myPackageVersion") private List myResources; @@ -188,14 +186,6 @@ public class NpmPackageVersionEntity { .toString(); } - public String getName() { - return myName; - } - - public void setName(String theName) { - myName = theName; - } - public List getResources() { return myResources; } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionResourceEntity.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionResourceEntity.java index efb444509de..682b031a8f3 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionResourceEntity.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/NpmPackageVersionResourceEntity.java @@ -48,15 +48,13 @@ import java.util.Date; }) public class NpmPackageVersionResourceEntity { - public static final int VERSION_ID_LENGTH = 200; - @Id @SequenceGenerator(name = "SEQ_NPM_PACKVERRES", sequenceName = "SEQ_NPM_PACKVERRES") @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_NPM_PACKVERRES") - @Column(name = "SP_ID") + @Column(name = "PID") private Long myId; @ManyToOne - @JoinColumn(name = "PACKVER_PID", referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_NPM_PACKVERRES_PACKVER")) + @JoinColumn(name = "PACKVER_PID", referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_NPM_PACKVERRES_PACKVER"), nullable = false) private NpmPackageVersionEntity myPackageVersion; @OneToOne @JoinColumn(name = "BINARY_RES_ID", referencedColumnName = "RES_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_NPM_PKVR_RESID")) @@ -65,7 +63,7 @@ public class NpmPackageVersionResourceEntity { private String myDirectory; @Column(name = "FILE_NAME", length = 200) private String myFilename; - @Column(name = "RES_TYPE", length = ResourceTable.RESTYPE_LEN) + @Column(name = "RES_TYPE", length = ResourceTable.RESTYPE_LEN, nullable = false) private String myResourceType; @Column(name = "CANONICAL_URL", length = 200) private String myCanonicalUrl;