Merge pull request #1729 from jamesagnew/ks-20200204-quiet-migrate-in-test

Ks 20200204 quiet migrate in test
This commit is contained in:
Ken Stevens 2020-02-25 14:04:32 -05:00 committed by GitHub
commit 5656ca5b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 8 deletions

View File

@ -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<BaseTask> 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

View File

@ -108,7 +108,9 @@ public abstract class BaseTask<T extends 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) {

View File

@ -34,12 +34,13 @@ import java.util.Set;
public class InitializeSchemaTask extends BaseTask<InitializeSchemaTask> {
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<InitializeSchemaTask> {
return;
}
logInfo(ourLog, "Initializing schema for {}", driverType);
logInfo(ourLog, "Initializing {} schema for {}", driverType, mySchemaInitializationProvider.getSchemaDescription());
List<String> 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<InitializeSchemaTask> {
protected void generateHashCode(HashCodeBuilder theBuilder) {
theBuilder.append(mySchemaInitializationProvider);
}
public ISchemaInitializationProvider getSchemaInitializationProvider() {
return mySchemaInitializationProvider;
}
}

View File

@ -901,10 +901,10 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
}
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());

View File

@ -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;
}
}

View File

@ -81,6 +81,13 @@ public class BaseMigrationTasks<T extends Enum> {
return retval;
}
protected BaseTask getTaskWithVersion(String theFlywayVersion) {
return myTasks.values().stream()
.filter(task -> theFlywayVersion.equals(task.getFlywayVersion()))
.findFirst()
.get();
}
void validate(Collection<BaseTask> theTasks) {
for (BaseTask task: theTasks) {
task.validateVersion();

View File

@ -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<String> getSqlStatements(DriverTypeEnum theDriverType);
String getSchemaExistsIndicatorTable();
String getSchemaDescription();
SchemaInitializationProvider setSchemaDescription(String theSchemaDescription);
}

View File

@ -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;