Search in sources :

Example 21 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class AbstractIntegrationTest method testRollbackableChangeLogScriptOnFutureDatabase.

@Test
public void testRollbackableChangeLogScriptOnFutureDatabase() throws Exception {
    if (database == null) {
        return;
    }
    StringWriter writer = new StringWriter();
    Liquibase liquibase = createLiquibase(rollbackChangeLog);
    clearDatabase(liquibase);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.futureRollbackSQL(new Contexts(this.contexts), new LabelExpression(), writer);
//        System.out.println("Rollback SQL for future "+driverName+"\n\n"+writer.toString());
}
Also used : Liquibase(liquibase.Liquibase) LabelExpression(liquibase.LabelExpression) Contexts(liquibase.Contexts) Test(org.junit.Test)

Example 22 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class AbstractIntegrationTest method invalidIncludeDoesntBreakLiquibase.

@Test
public void invalidIncludeDoesntBreakLiquibase() throws Exception {
    if (database == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(invalidReferenceChangeLog);
    try {
        liquibase.update(new Contexts());
        fail("Did not fail with invalid include");
    } catch (ChangeLogParseException ignored) {
    //expected
    }
    LockService lockService = LockServiceFactory.getInstance().getLockService(database);
    assertFalse(lockService.hasChangeLogLock());
}
Also used : Liquibase(liquibase.Liquibase) LockService(liquibase.lockservice.LockService) ChangeLogParseException(liquibase.exception.ChangeLogParseException) Contexts(liquibase.Contexts) Test(org.junit.Test)

Example 23 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class AbstractIntegrationTest method testUnrunChangeSetsEmptyDatabase.

@Test
public void testUnrunChangeSetsEmptyDatabase() throws Exception {
    if (database == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(completeChangeLog);
    clearDatabase(liquibase);
    liquibase = createLiquibase(completeChangeLog);
    List<ChangeSet> list = liquibase.listUnrunChangeSets(new Contexts(this.contexts), new LabelExpression());
    assertTrue(list.size() > 0);
}
Also used : Liquibase(liquibase.Liquibase) LabelExpression(liquibase.LabelExpression) Contexts(liquibase.Contexts) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 24 with Contexts

use of liquibase.Contexts in project minijax by minijax.

the class LiquibaseHelper method validateDatabaseState.

/**
 * Validates that the database is in a good state.
 *
 * @param database The database.
 * @param fileName The change log file name.
 * @param resourceAccessor The change log file loader.
 */
private void validateDatabaseState(final Database database) throws LiquibaseException {
    final Liquibase liquibase = getLiquibase(database);
    // all contexts
    final Contexts contexts = new Contexts();
    // no filters
    final LabelExpression labels = new LabelExpression();
    final List<ChangeSet> unrunChangeSets = liquibase.listUnrunChangeSets(contexts, labels);
    if (!unrunChangeSets.isEmpty()) {
        throw new IllegalStateException("Unrun change sets!  Please migrate the database first");
    }
}
Also used : Liquibase(liquibase.Liquibase) LabelExpression(liquibase.LabelExpression) Contexts(liquibase.Contexts) ChangeSet(liquibase.changelog.ChangeSet)

Example 25 with Contexts

use of liquibase.Contexts in project activityinfo by bedatadriven.

the class TestConnectionProvider method initializeDatabase.

private static void initializeDatabase() throws SQLException, LiquibaseException {
    Connection connection;
    try {
        connection = DriverManager.getConnection(connectionUrl(DATABASE_NAME), USERNAME, PASSWORD);
        Statement stmt = connection.createStatement();
        stmt.execute("DROP DATABASE IF EXISTS " + DATABASE_NAME);
        stmt.execute("CREATE DATABASE " + DATABASE_NAME);
        stmt.execute("USE " + DATABASE_NAME);
    } catch (SQLException e) {
        // Database probably doesn't exist yet
        connection = DriverManager.getConnection(connectionUrl(""), USERNAME, PASSWORD);
        Statement stmt = connection.createStatement();
        stmt.execute("CREATE DATABASE " + DATABASE_NAME);
        stmt.close();
        connection.close();
        // Re-open specifically for this database
        connection = DriverManager.getConnection(connectionUrl(DATABASE_NAME), USERNAME, PASSWORD);
    }
    Liquibase liquibase = new Liquibase("org/activityinfo/database/changelog/db.changelog-master.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
    liquibase.update(new Contexts());
    connection.close();
}
Also used : Liquibase(liquibase.Liquibase) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(liquibase.database.jvm.JdbcConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) Contexts(liquibase.Contexts)

Aggregations

Contexts (liquibase.Contexts)32 Test (org.junit.Test)18 Liquibase (liquibase.Liquibase)16 ChangeSet (liquibase.changelog.ChangeSet)12 LabelExpression (liquibase.LabelExpression)10 LiquibaseException (liquibase.exception.LiquibaseException)8 IOException (java.io.IOException)5 Database (liquibase.database.Database)5 BuildException (org.apache.tools.ant.BuildException)5 FileResource (org.apache.tools.ant.types.resources.FileResource)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 RuntimeEnvironment (liquibase.RuntimeEnvironment)4 Writer (java.io.Writer)3 Connection (java.sql.Connection)3 ContextChangeSetFilter (liquibase.changelog.filter.ContextChangeSetFilter)3 JdbcConnection (liquibase.database.jvm.JdbcConnection)3 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)3 ResourceAccessor (liquibase.resource.ResourceAccessor)3 OutputStreamWriter (java.io.OutputStreamWriter)2 SQLException (java.sql.SQLException)2