name schema initializer to distinguish between different schemas

This commit is contained in:
Ken Stevens 2019-11-28 12:10:34 -05:00
parent bf003f0d16
commit a58da3b535
5 changed files with 21 additions and 6 deletions

View File

@ -39,7 +39,7 @@ public class InitializeSchemaTask extends BaseTask<InitializeSchemaTask> {
public InitializeSchemaTask(String theProductVersion, String theSchemaVersion, ISchemaInitializationProvider theSchemaInitializationProvider) {
super(theProductVersion, theSchemaVersion);
mySchemaInitializationProvider = theSchemaInitializationProvider;
setDescription("Initialize schema");
setDescription("Initialize schema for " + theSchemaInitializationProvider.getDescription());
}
@Override

View File

@ -875,7 +875,7 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
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", "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

@ -38,15 +38,17 @@ import java.util.regex.Pattern;
import static org.apache.commons.lang3.StringUtils.isBlank;
public class SchemaInitializationProvider implements ISchemaInitializationProvider {
private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)");
private final String mySchemaDescription;
private final String mySchemaFileClassPath;
private final String mySchemaExistsIndicatorTable;
/**
* @param theSchemaDescription description of the schema being updated (for logging)
* @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;
}
@ -75,13 +77,19 @@ public class SchemaInitializationProvider implements ISchemaInitializationProvid
return retval;
}
private static final Pattern ourTrailingCommaPattern = Pattern.compile(",(\\s+)\\)");
static String clean(String theStatement) {
// Remove commas before brackets. Some databases don't like this and
// some schemas shipped with Quartz include them
// Remove commas before brackets. The Quartz h2 schema has a comma before a closing bracket that fails to execute...
Matcher matcher = ourTrailingCommaPattern.matcher(theStatement);
return matcher.replaceAll("$1\\)");
}
@Override
public String getDescription() {
return mySchemaDescription;
}
@Nonnull
protected String getInitScript(DriverTypeEnum theDriverType) {
return theDriverType.getSchemaFilename();

View File

@ -28,4 +28,6 @@ public interface ISchemaInitializationProvider {
List<String> getSqlStatements(DriverTypeEnum theDriverType);
String getSchemaExistsIndicatorTable();
String getDescription();
}

View File

@ -40,6 +40,11 @@ public class InitializeSchemaTaskTest extends BaseTest {
return "DONT_MATCH_ME";
}
@Override
public String getDescription() {
return "test";
}
@Override
public boolean equals(Object theO) {
if (this == theO) return true;