mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-07 05:28:21 +00:00
make migration table name configurable
This commit is contained in:
parent
8945e54346
commit
3d00634b16
@ -22,6 +22,7 @@ package ca.uhn.fhir.cli;
|
||||
|
||||
import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
|
||||
import ca.uhn.fhir.jpa.migrate.FlywayMigrator;
|
||||
import ca.uhn.fhir.jpa.migrate.SchemaMigrator;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
@ -37,6 +38,7 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
public abstract class BaseFlywayMigrateDatabaseCommand<T extends Enum> extends BaseCommand {
|
||||
|
||||
|
||||
public static final String MIGRATE_DATABASE = "migrate-database";
|
||||
private Set<String> myFlags;
|
||||
|
||||
@ -108,7 +110,7 @@ public abstract class BaseFlywayMigrateDatabaseCommand<T extends Enum> extends B
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
FlywayMigrator migrator = new FlywayMigrator();
|
||||
FlywayMigrator migrator = new FlywayMigrator(SchemaMigrator.HAPI_FHIR_MIGRATION_TABLENAME);
|
||||
migrator.setConnectionUrl(url);
|
||||
migrator.setDriverType(driverType);
|
||||
migrator.setUsername(username);
|
||||
|
@ -37,6 +37,7 @@ public class FlywayMigrator {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(FlywayMigrator.class);
|
||||
|
||||
private DriverTypeEnum myDriverType;
|
||||
private final String myMigrationTableName;
|
||||
private String myConnectionUrl;
|
||||
private String myUsername;
|
||||
private String myPassword;
|
||||
@ -44,9 +45,8 @@ public class FlywayMigrator {
|
||||
private boolean myDryRun;
|
||||
private boolean myNoColumnShrink;
|
||||
|
||||
public FlywayMigrator() {}
|
||||
|
||||
public FlywayMigrator(BasicDataSource theDataSource) {
|
||||
public FlywayMigrator(String theMigrationTableName, BasicDataSource theDataSource) {
|
||||
this(theMigrationTableName);
|
||||
myConnectionUrl = theDataSource.getUrl();
|
||||
myUsername = theDataSource.getUsername();
|
||||
myPassword = theDataSource.getPassword();
|
||||
@ -62,6 +62,10 @@ public class FlywayMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
public FlywayMigrator(String theMigrationTableName) {
|
||||
myMigrationTableName = theMigrationTableName;
|
||||
}
|
||||
|
||||
public void setDriverType(DriverTypeEnum theDriverType) {
|
||||
myDriverType = theDriverType;
|
||||
}
|
||||
@ -97,7 +101,8 @@ public class FlywayMigrator {
|
||||
|
||||
private Flyway initFlyway(DriverTypeEnum.ConnectionProperties theConnectionProperties) {
|
||||
// TODO KHS Is there a way we can use datasource instead of url, username, password here
|
||||
Flyway flyway = Flyway.configure()
|
||||
Flyway flyway = Flyway.configure()
|
||||
.table(myMigrationTableName)
|
||||
.dataSource(myConnectionUrl, myUsername, myPassword)
|
||||
.baselineOnMigrate(true)
|
||||
.javaMigrations(myTasks.toArray(new JavaMigration[0]))
|
||||
|
@ -16,19 +16,20 @@ import java.util.Properties;
|
||||
|
||||
public class SchemaMigrator {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(SchemaMigrator.class);
|
||||
public static final String HAPI_FHIR_MIGRATION_TABLENAME = "FLY_HFJ_MIGRATION";
|
||||
|
||||
private final BasicDataSource myDataSource;
|
||||
private final FlywayMigrator myMigrator;
|
||||
private final boolean mySkipValidation;
|
||||
|
||||
public SchemaMigrator(BasicDataSource theDataSource, Properties jpaProperties, List<BaseTask<?>> theMigrationTasks) {
|
||||
public SchemaMigrator(String theMigrationTableName, BasicDataSource theDataSource, Properties jpaProperties, List<BaseTask<?>> theMigrationTasks) {
|
||||
myDataSource = theDataSource;
|
||||
if (jpaProperties.containsKey(AvailableSettings.HBM2DDL_AUTO) && "update".equals(jpaProperties.getProperty(AvailableSettings.HBM2DDL_AUTO))) {
|
||||
mySkipValidation = true;
|
||||
} else {
|
||||
mySkipValidation = false;
|
||||
}
|
||||
myMigrator = new FlywayMigrator(theDataSource);
|
||||
myMigrator = new FlywayMigrator(theMigrationTableName, theDataSource);
|
||||
myMigrator.addTasks(theMigrationTasks);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class SchemaMigratorTest extends BaseTest {
|
||||
task.addSql(DriverTypeEnum.H2_EMBEDDED, "create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
|
||||
getMigrator().addTask(task);
|
||||
|
||||
SchemaMigrator schemaMigrator = new SchemaMigrator(getDataSource(), new Properties(), Collections.singletonList(task));
|
||||
SchemaMigrator schemaMigrator = new SchemaMigrator("TEST_MIGRATION", getDataSource(), new Properties(), Collections.singletonList(task));
|
||||
|
||||
try {
|
||||
schemaMigrator.validate();
|
||||
|
@ -41,7 +41,7 @@ public class BaseTest {
|
||||
myDataSource.setUsername("SA");
|
||||
myDataSource.setPassword("SA");
|
||||
myDataSource.setDriverClassName(DriverTypeEnum.H2_EMBEDDED.getDriverClassName());
|
||||
myMigrator = new FlywayMigrator(myDataSource);
|
||||
myMigrator = new FlywayMigrator("TEST_MIGRATION", myDataSource);
|
||||
}
|
||||
|
||||
protected BasicDataSource getDataSource() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user