Search in sources :

Example 71 with Liquibase

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();
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) JdbcConnection(liquibase.database.jvm.JdbcConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) AfterAll(org.junit.jupiter.api.AfterAll)

Example 72 with Liquibase

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("");
    }
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) JdbcConnection(liquibase.database.jvm.JdbcConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 73 with Liquibase

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);
    }
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) LiquibaseException(liquibase.exception.LiquibaseException) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 74 with Liquibase

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);
                }
            }
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) OfflineConnection(liquibase.database.OfflineConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) ApplicationStartupException(io.micronaut.runtime.exceptions.ApplicationStartupException) DatabaseException(liquibase.exception.DatabaseException)

Example 75 with Liquibase

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);
                }
            }
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) OfflineConnection(liquibase.database.OfflineConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) DatabaseException(liquibase.exception.DatabaseException)

Aggregations

Liquibase (liquibase.Liquibase)185 JdbcConnection (liquibase.database.jvm.JdbcConnection)83 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)77 Database (liquibase.database.Database)59 LiquibaseException (liquibase.exception.LiquibaseException)52 Contexts (liquibase.Contexts)47 SQLException (java.sql.SQLException)44 Connection (java.sql.Connection)40 Test (org.junit.Test)32 IOException (java.io.IOException)29 LabelExpression (liquibase.LabelExpression)28 DatabaseException (liquibase.exception.DatabaseException)27 ChangeSet (liquibase.changelog.ChangeSet)22 ResourceAccessor (liquibase.resource.ResourceAccessor)20 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)14 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)13 ValidationFailedException (liquibase.exception.ValidationFailedException)12 Properties (java.util.Properties)10 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 LockException (liquibase.exception.LockException)10