From 04044541679bddf184bb7fd7e462e139a101df3c Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Sat, 2 Nov 2019 17:03:45 -0400 Subject: [PATCH] abort schema initialization if HFJ_RESOURCE table already exists --- .../fhir/jpa/migrate/taskdef/InitializeSchemaTask.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 57a6a771160..d481760e595 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 @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; +import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.tasks.api.ISchemaInitializationProvider; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -10,6 +11,7 @@ import org.slf4j.LoggerFactory; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Set; public class InitializeSchemaTask extends BaseTask { private static final Logger ourLog = LoggerFactory.getLogger(InitializeSchemaTask.class); @@ -29,6 +31,12 @@ public class InitializeSchemaTask extends BaseTask { public void execute() throws SQLException { 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); + return; + } + logInfo(ourLog, "Initializing schema for {}", driverType); List sqlStatements = mySchemaInitializationProvider.getSqlStatements(driverType);