use of liquibase.Liquibase in project pay-adminusers by alphagov.
the class DaoTestBase method cleanUp.
@AfterAll
public static void cleanUp() {
try (Connection connection = DriverManager.getConnection(postgres.getConnectionUrl(), postgres.getUsername(), postgres.getPassword())) {
Liquibase migrator = new Liquibase("config/initial-db-state.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
Liquibase migrator2 = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
migrator2.dropAll();
migrator.dropAll();
} catch (Exception e) {
logger.error("Error stopping docker", e);
}
env.stop();
}
use of liquibase.Liquibase in project pay-adminusers by alphagov.
the class DropwizardAppWithPostgresExtension method doSecondaryDatabaseMigration.
private void doSecondaryDatabaseMigration() throws SQLException, LiquibaseException {
try (Connection connection = DriverManager.getConnection(postgres.getConnectionUrl(), postgres.getUsername(), postgres.getPassword())) {
Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
migrator.update("");
}
}
use of liquibase.Liquibase in project pay-adminusers by alphagov.
the class MigrateToInitialDbState method performInitialMigration.
private void performInitialMigration(Connection connection) {
try {
Liquibase migrator = new Liquibase("config/initial-db-state.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
migrator.update("");
} catch (LiquibaseException e) {
LOGGER.error("Error performing liquibase initial database migration", e);
throw new RuntimeException(e);
}
}
use of liquibase.Liquibase in project micronaut-liquibase by micronaut-projects.
the class LiquibaseMigrationRunner method migrate.
/**
* Performs liquibase update for the given data datasource and configuration.
*
* @param config The {@link LiquibaseConfigurationProperties}
* @param dataSource The {@link DataSource}
*/
private void migrate(LiquibaseConfigurationProperties config, DataSource dataSource) {
Connection connection;
try {
connection = dataSource.getConnection();
} catch (SQLException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Migration failed! Could not connect to the datasource.", e);
}
throw new ApplicationStartupException("Migration failed! Could not connect to the datasource.", e);
}
Liquibase liquibase = null;
try {
liquibase = createLiquibase(connection, config);
generateRollbackFile(liquibase, config);
performUpdate(liquibase, config);
} catch (LiquibaseException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Migration failed! Liquibase encountered an exception.", e);
}
throw new ApplicationStartupException("Migration failed! Liquibase encountered an exception.", e);
} finally {
Database database = null;
if (liquibase != null) {
database = liquibase.getDatabase();
}
if (database != null) {
try {
database.close();
} catch (DatabaseException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Error closing the connection after the migration.", e);
}
}
}
}
}
use of liquibase.Liquibase in project micronaut-liquibase by micronaut-projects.
the class AbstractLiquibaseMigration method migrate.
/**
* Performs liquibase update for the given data datasource and configuration.
*
* @param config The {@link LiquibaseConfigurationProperties}
* @param dataSource The {@link DataSource}
*/
private void migrate(LiquibaseConfigurationProperties config, DataSource dataSource) {
Connection connection;
try {
connection = dataSource.getConnection();
} catch (SQLException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Migration failed! Could not connect to the datasource.", e);
}
applicationContext.close();
return;
}
Liquibase liquibase = null;
try {
if (LOG.isInfoEnabled()) {
LOG.info("Running migrations for database with qualifier [{}]", config.getNameQualifier());
}
liquibase = createLiquibase(connection, config);
generateRollbackFile(liquibase, config);
performUpdate(liquibase, config);
} catch (LiquibaseException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Migration failed! Liquibase encountered an exception.", e);
}
applicationContext.close();
} finally {
Database database = null;
if (liquibase != null) {
database = liquibase.getDatabase();
}
if (database != null) {
try {
database.close();
} catch (DatabaseException e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Error closing the connection after the migration.", e);
}
}
}
}
}
Aggregations