Search in sources :

Example 6 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project microservice_framework by CJSCommonPlatform.

the class EventsPageIT method initEventDatabase.

private void initEventDatabase() throws Exception {
    Liquibase eventStoreLiquibase = new Liquibase(LIQUIBASE_EVENT_STORE_CHANGELOG_XML, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
    eventStoreLiquibase.dropAll();
    eventStoreLiquibase.update("");
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 7 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project microservice_framework by CJSCommonPlatform.

the class CakeShopPostgresIT method initDatabase.

private static DataSource initDatabase(final String dbUrlPropertyName, final String dbUserNamePropertyName, final String dbPasswordPropertyName, final String... liquibaseChangeLogXmls) throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(POSTGRES_DRIVER);
    dataSource.setUrl(TEST_PROPERTIES.value(dbUrlPropertyName));
    dataSource.setUsername(TEST_PROPERTIES.value(dbUserNamePropertyName));
    dataSource.setPassword(TEST_PROPERTIES.value(dbPasswordPropertyName));
    boolean dropped = false;
    final JdbcConnection jdbcConnection = new JdbcConnection(dataSource.getConnection());
    for (String liquibaseChangeLogXml : liquibaseChangeLogXmls) {
        Liquibase liquibase = new Liquibase(liquibaseChangeLogXml, new ClassLoaderResourceAccessor(), jdbcConnection);
        if (!dropped) {
            liquibase.dropAll();
            dropped = true;
        }
        liquibase.update("");
    }
    return dataSource;
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource)

Example 8 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project microservice_framework by CJSCommonPlatform.

the class TestDataSourceFactory method initDatabase.

private void initDatabase() throws LiquibaseException, SQLException {
    final Liquibase liquibase = new Liquibase(liquibaseLocation, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
    liquibase.dropAll();
    liquibase.update("");
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 9 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project microservice_framework by CJSCommonPlatform.

the class DefaultAggregateServiceIT method initDatabase.

private void initDatabase() throws Exception {
    final Liquibase snapshotLiquidBase = new Liquibase(LIQUIBASE_EVENT_STORE_CHANGELOG_XML, new ClassLoaderResourceAccessor(), new JdbcConnection(dataSource.getConnection()));
    snapshotLiquidBase.dropAll();
    snapshotLiquidBase.update("");
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 10 with ClassLoaderResourceAccessor

use of liquibase.resource.ClassLoaderResourceAccessor in project webcert by sklintyg.

the class DbChecker method checkDb.

@PostConstruct
public void checkDb() {
    try {
        DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
        Liquibase liquibase = new Liquibase(script, new ClassLoaderResourceAccessor(), database);
        LOG.info("Checking database: {} URL:{}", database.getDatabaseProductName(), database.getConnection().getURL());
        List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(null, liquibase.getChangeLogParameters().getLabels());
        if (!changeSets.isEmpty()) {
            StringBuilder errors = new StringBuilder();
            for (ChangeSet changeSet : changeSets) {
                errors.append('>').append(changeSet.toString()).append('\n');
            }
            throw new Error("Database version mismatch. Check liquibase status. Errors:\n" + errors.toString() + database.getDatabaseProductName() + ", " + database);
        }
    } catch (liquibase.exception.LiquibaseException | SQLException e) {
        throw new Error("Database not ok, aborting startup.", e);
    }
    LOG.info("Liquibase ok");
}
Also used : SQLException(java.sql.SQLException) JdbcConnection(liquibase.database.jvm.JdbcConnection) Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) DatabaseConnection(liquibase.database.DatabaseConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) ChangeSet(liquibase.changelog.ChangeSet) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)38 Liquibase (liquibase.Liquibase)25 JdbcConnection (liquibase.database.jvm.JdbcConnection)20 SQLException (java.sql.SQLException)11 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)9 Database (liquibase.database.Database)8 LiquibaseException (liquibase.exception.LiquibaseException)8 Connection (java.sql.Connection)7 DatabaseException (liquibase.exception.DatabaseException)7 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)7 ResourceAccessor (liquibase.resource.ResourceAccessor)7 File (java.io.File)6 ArrayList (java.util.ArrayList)3 Contexts (liquibase.Contexts)3 FileOutputStream (java.io.FileOutputStream)2 DataSource (javax.sql.DataSource)2 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)2 ChangeSet (liquibase.changelog.ChangeSet)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 DatabaseConnection (liquibase.database.DatabaseConnection)2