From ea21b59fde3ba754a230348db056532c84553f4d Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Sun, 3 Nov 2019 14:02:28 -0500 Subject: [PATCH] generalize initialize schema interface --- .../jpa/migrate/taskdef/InitializeSchemaTask.java | 5 +++-- .../migrate/tasks/HapiFhirJpaMigrationTasks.java | 2 +- .../tasks/SchemaInitializationProvider.java | 14 +++++++++++++- .../tasks/api/ISchemaInitializationProvider.java | 2 ++ .../migrate/taskdef/InitializeSchemaTaskTest.java | 5 +++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTask.java index 0c7d6555410..21cebbb3bac 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTask.java @@ -31,8 +31,9 @@ public class InitializeSchemaTask extends BaseTask { DriverTypeEnum driverType = getDriverType(); Set tableNames = JdbcUtils.getTableNames(getConnectionProperties()); - if (tableNames.contains("HFJ_RESOURCE")) { - logInfo(ourLog, "The table HFJ_RESOURCE already exists. Skipping schema initialization for {}", driverType); + String schemaExistsIndicatorTable = mySchemaInitializationProvider.getSchemaExistsIndicatorTable(); + if (tableNames.contains(schemaExistsIndicatorTable)) { + logInfo(ourLog, "The table {} already exists. Skipping schema initialization for {}", schemaExistsIndicatorTable, driverType); return; } 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 cab8c055a46..68892d19e05 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 @@ -867,7 +867,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { private void init330() { // 20180114 - 20180329 Builder version = forVersion(VersionEnum.V3_3_0); - version.initializeSchema("20180115.0", new SchemaInitializationProvider("/ca/uhn/hapi/fhir/jpa/docs/database")); + version.initializeSchema("20180115.0", new SchemaInitializationProvider("/ca/uhn/hapi/fhir/jpa/docs/database", "HFJ_RESOURCE")); Builder.BuilderWithTableName hfjResource = version.onTable("HFJ_RESOURCE"); version.startSectionWithMessage("Starting work on table: " + hfjResource.getTableName()); diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java index 4210f99126f..6f35e17ddc0 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/SchemaInitializationProvider.java @@ -14,9 +14,16 @@ import java.util.List; public class SchemaInitializationProvider implements ISchemaInitializationProvider { private final String mySchemaFileClassPath; + private final String mySchemaExistsIndicatorTable; - public SchemaInitializationProvider(String theSchemaFileClassPath) { + /** + * + * @param theSchemaFileClassPath pathname to script used to initialize schema + * @param theSchemaExistsIndicatorTable a table name we can use to determine if this schema has already been initialized + */ + public SchemaInitializationProvider(String theSchemaFileClassPath, String theSchemaExistsIndicatorTable) { mySchemaFileClassPath = theSchemaFileClassPath; + mySchemaExistsIndicatorTable = theSchemaExistsIndicatorTable; } @Override @@ -64,4 +71,9 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid .append(size()) .toHashCode(); } + + @Override + public String getSchemaExistsIndicatorTable() { + return mySchemaExistsIndicatorTable; + } } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/ISchemaInitializationProvider.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/ISchemaInitializationProvider.java index 1f894332cd1..473a2b21600 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/ISchemaInitializationProvider.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/ISchemaInitializationProvider.java @@ -6,4 +6,6 @@ import java.util.List; public interface ISchemaInitializationProvider { List getSqlStatements(DriverTypeEnum theDriverType); + + String getSchemaExistsIndicatorTable(); } diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java index 082b7974d7a..a55cd045f9d 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java @@ -35,6 +35,11 @@ public class InitializeSchemaTaskTest extends BaseTest { return Collections.singletonList("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); } + @Override + public String getSchemaExistsIndicatorTable() { + return "DONT_MATCH_ME"; + } + @Override public boolean equals(Object theO) { if (this == theO) return true;