Skip to content

Commit

Permalink
Replace use of deprecated Liquibase#update in H2LiquibaseExtension (#406
Browse files Browse the repository at this point in the history
)

* Replace  deprecated Liquibase#update method with the
  new Command API

Closes #389
  • Loading branch information
sleberknight authored Jul 25, 2023
1 parent 010454f commit 1760e3d
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import static java.util.Objects.nonNull;

import liquibase.Contexts;
import liquibase.Liquibase;
import liquibase.command.CommandScope;
import liquibase.command.core.UpdateCommandStep;
import liquibase.command.core.helpers.DbUrlConnectionCommandStep;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.exception.CommandExecutionException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.extension.AfterAllCallback;
Expand Down Expand Up @@ -121,11 +123,17 @@ public void beforeAll(ExtensionContext context) throws Exception {
LOG.trace("Running Liquibase migrations using migrations file: {}", migrationClassPathLocation);
try (var conn = database.getDataSource().getConnection()) {
var liquibaseDb = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn));
var liquibase = new Liquibase(migrationClassPathLocation, new ClassLoaderResourceAccessor(), liquibaseDb);
liquibase.update(new Contexts());
runLiquibaseUpdate(liquibaseDb, migrationClassPathLocation);
}
}

private static void runLiquibaseUpdate(Database database, String changeLogLocation) throws CommandExecutionException {
var updateCommand = new CommandScope(UpdateCommandStep.COMMAND_NAME)
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, changeLogLocation);
updateCommand.execute();
}

/**
* Deletes the directory where the H2 test database resides, unless exiting a nested test class.
*
Expand Down

0 comments on commit 1760e3d

Please sign in to comment.