Correct index init issue (#2662)

* Correct index init issue

* Add changelog
This commit is contained in:
James Agnew 2021-05-17 20:31:44 -04:00 committed by GitHub
parent 926bf393d3
commit 7a50454350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
type: add
issue: 2662
title: "It is now possible to declare database migrations as being mandatory even
when running in schema initialization mode."

View File

@ -89,7 +89,7 @@ public class FlywayMigrationTask implements JavaMigration {
} }
private void executeTask() throws SQLException { private void executeTask() throws SQLException {
if (myFlywayMigrator.isSchemaWasInitialized() && !(myTask instanceof InitializeSchemaTask)) { if (myFlywayMigrator.isSchemaWasInitialized() && !myTask.isRunDuringSchemaInitialization()) {
// Empty schema was initialized, stub out this non-schema-init task since we're starting with a fully migrated schema // Empty schema was initialized, stub out this non-schema-init task since we're starting with a fully migrated schema
myTask.setDoNothing(true); myTask.setDoNothing(true);
} }

View File

@ -58,11 +58,26 @@ public abstract class BaseTask {
private Set<DriverTypeEnum> myOnlyAppliesToPlatforms = new HashSet<>(); private Set<DriverTypeEnum> myOnlyAppliesToPlatforms = new HashSet<>();
private boolean myNoColumnShrink; private boolean myNoColumnShrink;
private boolean myFailureAllowed; private boolean myFailureAllowed;
private boolean myRunDuringSchemaInitialization;
protected BaseTask(String theProductVersion, String theSchemaVersion) { protected BaseTask(String theProductVersion, String theSchemaVersion) {
myProductVersion = theProductVersion; myProductVersion = theProductVersion;
mySchemaVersion = theSchemaVersion; mySchemaVersion = theSchemaVersion;
} }
public boolean isRunDuringSchemaInitialization() {
return myRunDuringSchemaInitialization;
}
/**
* Should this task run even if we're doing the very first initialization of an empty schema. By
* default we skip most tasks during that pass, since they just take up time and the
* schema should be fully initialized by the {@link InitializeSchemaTask}
*/
public void setRunDuringSchemaInitialization(boolean theRunDuringSchemaInitialization) {
myRunDuringSchemaInitialization = theRunDuringSchemaInitialization;
}
public void setOnlyAppliesToPlatforms(Set<DriverTypeEnum> theOnlyAppliesToPlatforms) { public void setOnlyAppliesToPlatforms(Set<DriverTypeEnum> theOnlyAppliesToPlatforms) {
Validate.notNull(theOnlyAppliesToPlatforms); Validate.notNull(theOnlyAppliesToPlatforms);
myOnlyAppliesToPlatforms = theOnlyAppliesToPlatforms; myOnlyAppliesToPlatforms = theOnlyAppliesToPlatforms;

View File

@ -33,9 +33,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
public class InitializeSchemaTask extends BaseTask { public class InitializeSchemaTask extends BaseTask {
private static final Logger ourLog = LoggerFactory.getLogger(InitializeSchemaTask.class);
public static final String DESCRIPTION_PREFIX = "Initialize schema for "; public static final String DESCRIPTION_PREFIX = "Initialize schema for ";
private static final Logger ourLog = LoggerFactory.getLogger(InitializeSchemaTask.class);
private final ISchemaInitializationProvider mySchemaInitializationProvider; private final ISchemaInitializationProvider mySchemaInitializationProvider;
private boolean myInitializedSchema; private boolean myInitializedSchema;
@ -45,6 +44,11 @@ public class InitializeSchemaTask extends BaseTask {
setDescription(DESCRIPTION_PREFIX + mySchemaInitializationProvider.getSchemaDescription()); setDescription(DESCRIPTION_PREFIX + mySchemaInitializationProvider.getSchemaDescription());
} }
@Override
public boolean isRunDuringSchemaInitialization() {
return true;
}
@Override @Override
public void validate() { public void validate() {
// nothing // nothing

View File

@ -83,8 +83,8 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
// For MSSQL only - Replace ForcedId index with a version that has an INCLUDE clause // For MSSQL only - Replace ForcedId index with a version that has an INCLUDE clause
Builder.BuilderWithTableName forcedId = version.onTable("HFJ_FORCED_ID"); Builder.BuilderWithTableName forcedId = version.onTable("HFJ_FORCED_ID");
forcedId.dropIndex("20210516.1", "IDX_FORCEDID_TYPE_FID").onlyAppliesToPlatforms(DriverTypeEnum.MSSQL_2012); forcedId.dropIndex("20210516.1", "IDX_FORCEDID_TYPE_FID").onlyAppliesToPlatforms(DriverTypeEnum.MSSQL_2012).runEvenDuringSchemaInitialization();
forcedId.addIndex("20210516.2", "IDX_FORCEDID_TYPE_FID").unique(true).includeColumns("RESOURCE_PID").withColumns("RESOURCE_TYPE", "FORCED_ID").onlyAppliesToPlatforms(DriverTypeEnum.MSSQL_2012); forcedId.addIndex("20210516.2", "IDX_FORCEDID_TYPE_FID").unique(true).includeColumns("RESOURCE_PID").withColumns("RESOURCE_TYPE", "FORCED_ID").onlyAppliesToPlatforms(DriverTypeEnum.MSSQL_2012).runEvenDuringSchemaInitialization();
} }

View File

@ -504,6 +504,10 @@ public class Builder {
return this; return this;
} }
public BuilderCompleteTask runEvenDuringSchemaInitialization() {
myTask.setRunDuringSchemaInitialization(true);
return this;
}
} }
} }