diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java index 8b60927345e..7373e1889ee 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/FlywayMigrator.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.migrate; */ import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask; +import ca.uhn.fhir.jpa.migrate.taskdef.InitializeSchemaTask; import com.google.common.annotations.VisibleForTesting; import org.flywaydb.core.Flyway; import org.flywaydb.core.api.MigrationInfoService; @@ -87,7 +88,11 @@ public class FlywayMigrator extends BaseMigrator { @Override public void addTasks(List theTasks) { - theTasks.forEach(this::addTask); + if ("true".equals(System.getProperty("unit_test_mode"))) { + theTasks.stream().filter(task -> task instanceof InitializeSchemaTask).forEach(this::addTask); + } else { + theTasks.forEach(this::addTask); + } } @Override diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java index e68d1609158..696f70be553 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTask.java @@ -108,7 +108,9 @@ public abstract class BaseTask { JdbcTemplate jdbcTemplate = getConnectionProperties().newJdbcTemplate(); try { int changesCount = jdbcTemplate.update(theSql, theArguments); - logInfo(ourLog, "SQL \"{}\" returned {}", theSql, changesCount); + if (!"true".equals(System.getProperty("unit_test_mode"))) { + logInfo(ourLog, "SQL \"{}\" returned {}", theSql, changesCount); + } return changesCount; } catch (DataAccessException e) { if (myFailureAllowed) { 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 2c856eac168..e7c0481f56c 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 @@ -34,12 +34,13 @@ import java.util.Set; public class InitializeSchemaTask extends BaseTask { private static final Logger ourLog = LoggerFactory.getLogger(InitializeSchemaTask.class); + private final ISchemaInitializationProvider mySchemaInitializationProvider; public InitializeSchemaTask(String theProductVersion, String theSchemaVersion, ISchemaInitializationProvider theSchemaInitializationProvider) { super(theProductVersion, theSchemaVersion); mySchemaInitializationProvider = theSchemaInitializationProvider; - setDescription("Initialize schema"); + setDescription("Initialize schema for " + mySchemaInitializationProvider.getSchemaDescription()); } @Override @@ -58,13 +59,15 @@ public class InitializeSchemaTask extends BaseTask { return; } - logInfo(ourLog, "Initializing schema for {}", driverType); + logInfo(ourLog, "Initializing {} schema for {}", driverType, mySchemaInitializationProvider.getSchemaDescription()); List sqlStatements = mySchemaInitializationProvider.getSqlStatements(driverType); for (String nextSql : sqlStatements) { executeSql(null, nextSql); } + + logInfo(ourLog, "{} schema for {} initialized successfully", driverType, mySchemaInitializationProvider.getSchemaDescription()); } @Override @@ -77,4 +80,8 @@ public class InitializeSchemaTask extends BaseTask { protected void generateHashCode(HashCodeBuilder theBuilder) { theBuilder.append(mySchemaInitializationProvider); } + + public ISchemaInitializationProvider getSchemaInitializationProvider() { + return mySchemaInitializationProvider; + } } 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 7731f589210..b6df9abad7f 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 @@ -901,10 +901,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { } - private void init330() { // 20180114 - 20180329 + protected void init330() { // 20180114 - 20180329 Builder version = forVersion(VersionEnum.V3_3_0); - version.initializeSchema("20180115.0", new SchemaInitializationProvider("/ca/uhn/hapi/fhir/jpa/docs/database", "HFJ_RESOURCE")); + version.initializeSchema("20180115.0", new SchemaInitializationProvider("HAPI FHIR", "/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 6e8a0c25f7e..262dbb576af 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 @@ -37,14 +37,17 @@ import static org.apache.commons.lang3.StringUtils.isBlank; public class SchemaInitializationProvider implements ISchemaInitializationProvider { - private final String mySchemaFileClassPath; + private String mySchemaFileClassPath; + + private String mySchemaDescription; private final String mySchemaExistsIndicatorTable; /** * @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) { + public SchemaInitializationProvider(String theSchemaDescription, String theSchemaFileClassPath, String theSchemaExistsIndicatorTable) { + mySchemaDescription = theSchemaDescription; mySchemaFileClassPath = theSchemaFileClassPath; mySchemaExistsIndicatorTable = theSchemaExistsIndicatorTable; } @@ -110,5 +113,21 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid public String getSchemaExistsIndicatorTable() { return mySchemaExistsIndicatorTable; } + + public SchemaInitializationProvider setSchemaFileClassPath(String theSchemaFileClassPath) { + mySchemaFileClassPath = theSchemaFileClassPath; + return this; + } + + @Override + public String getSchemaDescription() { + return mySchemaDescription; + } + + @Override + public SchemaInitializationProvider setSchemaDescription(String theSchemaDescription) { + mySchemaDescription = theSchemaDescription; + return this; + } } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java index 5d7c819744c..7198767ee0e 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasks.java @@ -81,6 +81,13 @@ public class BaseMigrationTasks { return retval; } + protected BaseTask getTaskWithVersion(String theFlywayVersion) { + return myTasks.values().stream() + .filter(task -> theFlywayVersion.equals(task.getFlywayVersion())) + .findFirst() + .get(); + } + void validate(Collection theTasks) { for (BaseTask task: theTasks) { task.validateVersion(); 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 b645498c9bc..85d2af206bc 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 @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.migrate.tasks.api; */ import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; +import ca.uhn.fhir.jpa.migrate.tasks.SchemaInitializationProvider; import java.util.List; @@ -28,4 +29,8 @@ public interface ISchemaInitializationProvider { List getSqlStatements(DriverTypeEnum theDriverType); String getSchemaExistsIndicatorTable(); + + String getSchemaDescription(); + + SchemaInitializationProvider setSchemaDescription(String theSchemaDescription); } 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 a55cd045f9d..1247c332246 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 @@ -40,6 +40,11 @@ public class InitializeSchemaTaskTest extends BaseTest { return "DONT_MATCH_ME"; } + @Override + public String getSchemaDescription() { + return "TEST"; + } + @Override public boolean equals(Object theO) { if (this == theO) return true;