abort schema initialization if HFJ_RESOURCE table already exists

This commit is contained in:
Ken Stevens 2019-11-02 17:03:45 -04:00
parent 5577680a85
commit 0404454167
1 changed files with 8 additions and 0 deletions

View File

@ -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<InitializeSchemaTask> {
private static final Logger ourLog = LoggerFactory.getLogger(InitializeSchemaTask.class);
@ -29,6 +31,12 @@ public class InitializeSchemaTask extends BaseTask<InitializeSchemaTask> {
public void execute() throws SQLException {
DriverTypeEnum driverType = getDriverType();
Set<String> 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<String> sqlStatements = mySchemaInitializationProvider.getSqlStatements(driverType);