Search in sources :

Example 16 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class PostgreSQLIntegrationTest method testDependenciesInGenerateChangeLog.

@Test
public void testDependenciesInGenerateChangeLog() throws Exception {
    assumeNotNull(this.getDatabase());
    Liquibase liquibase = createLiquibase(this.dependenciesChangeLog);
    clearDatabase();
    try {
        liquibase.update(new Contexts());
        Database database = liquibase.getDatabase();
        DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, null, new CompareControl());
        DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, new DiffOutputControl(false, false, false, null));
        List<ChangeSet> changeSets = changeLogWriter.generateChangeSets();
        Assert.assertTrue(changeSets.size() > 0);
        ChangeSet addPrimaryKeyChangeSet = changeSets.stream().filter(changeSet -> changeSet.getChanges().get(0) instanceof AddPrimaryKeyChange).findFirst().orElse(null);
        Assert.assertNull(addPrimaryKeyChangeSet);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Database(liquibase.database.Database) CompareControl(liquibase.diff.compare.CompareControl) DiffOutputControl(liquibase.diff.output.DiffOutputControl) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) AddPrimaryKeyChange(liquibase.change.core.AddPrimaryKeyChange) DiffResult(liquibase.diff.DiffResult) Contexts(liquibase.Contexts) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 17 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class ChangeLogIteratorTest method runChangeSet_singleFilterIterator.

@Test
public void runChangeSet_singleFilterIterator() throws Exception {
    TestChangeSetVisitor testChangeLogVisitor = new TestChangeSetVisitor();
    ChangeLogIterator iterator = new ChangeLogIterator(changeLog, new ContextChangeSetFilter(new Contexts("test1")));
    iterator.run(testChangeLogVisitor, new RuntimeEnvironment(null, null, null));
    assertEquals(4, testChangeLogVisitor.visitedChangeSets.size());
}
Also used : RuntimeEnvironment(liquibase.RuntimeEnvironment) ContextChangeSetFilter(liquibase.changelog.filter.ContextChangeSetFilter) Contexts(liquibase.Contexts) Test(org.junit.Test)

Example 18 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class ChangeLogIteratorTest method runChangeSet_reverseVisitor.

@Test
public void runChangeSet_reverseVisitor() throws Exception {
    TestChangeSetVisitor testChangeLogVisitor = new ReverseChangeSetVisitor();
    ChangeLogIterator iterator = new ChangeLogIterator(changeLog, new ContextChangeSetFilter(new Contexts("test1")), new DbmsChangeSetFilter(new MySQLDatabase()));
    iterator.run(testChangeLogVisitor, new RuntimeEnvironment(null, null, null));
    assertEquals(3, testChangeLogVisitor.visitedChangeSets.size());
    assertEquals("5", testChangeLogVisitor.visitedChangeSets.get(0).getId());
    assertEquals("4", testChangeLogVisitor.visitedChangeSets.get(1).getId());
    assertEquals("1", testChangeLogVisitor.visitedChangeSets.get(2).getId());
}
Also used : RuntimeEnvironment(liquibase.RuntimeEnvironment) ContextChangeSetFilter(liquibase.changelog.filter.ContextChangeSetFilter) MySQLDatabase(liquibase.database.core.MySQLDatabase) DbmsChangeSetFilter(liquibase.changelog.filter.DbmsChangeSetFilter) Contexts(liquibase.Contexts) Test(org.junit.Test)

Example 19 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class DropAllCommand method run.

@Override
protected CommandResult run() throws Exception {
    try {
        LockServiceFactory.getInstance().getLockService(database).waitForLock();
        for (CatalogAndSchema schema : schemas) {
            log.info("Dropping Database Objects in schema: " + schema);
            checkLiquibaseTables(false, null, new Contexts(), new LabelExpression());
            database.dropDatabaseObjects(schema);
        }
    } catch (DatabaseException e) {
        throw e;
    } catch (Exception e) {
        throw new DatabaseException(e);
    } finally {
        LockServiceFactory.getInstance().getLockService(database).destroy();
        resetServices();
    }
    return new CommandResult("All objects dropped from " + database.getConnection().getConnectionUserName() + "@" + database.getConnection().getURL());
}
Also used : LabelExpression(liquibase.LabelExpression) CatalogAndSchema(liquibase.CatalogAndSchema) Contexts(liquibase.Contexts) DatabaseException(liquibase.exception.DatabaseException) DatabaseException(liquibase.exception.DatabaseException) LiquibaseException(liquibase.exception.LiquibaseException) CommandResult(liquibase.command.CommandResult)

Example 20 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class XMLChangeLogSAXParserTest method testIgnoreDuplicateChangeSets.

@Test
public void testIgnoreDuplicateChangeSets() throws ChangeLogParseException, Exception {
    XMLChangeLogSAXParser xmlParser = new XMLChangeLogSAXParser();
    DatabaseChangeLog changeLog = xmlParser.parse("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/master.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
    final List<ChangeSet> changeSets = new ArrayList<ChangeSet>();
    new ChangeLogIterator(changeLog).run(new ChangeSetVisitor() {

        @Override
        public Direction getDirection() {
            return Direction.FORWARD;
        }

        @Override
        public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
            changeSets.add(changeSet);
        }
    }, new RuntimeEnvironment(new MockDatabase(), new Contexts(), new LabelExpression()));
    Assert.assertEquals(8, changeSets.size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(0).toString());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(1).toString());
    Assert.assertEquals(1, changeSets.get(1).getContexts().getContexts().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(2).toString());
    Assert.assertEquals(1, changeSets.get(2).getLabels().getLabels().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(3).toString());
    Assert.assertEquals(2, changeSets.get(3).getLabels().getLabels().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog4.xml::1::testuser", changeSets.get(4).toString());
    Assert.assertEquals(1, changeSets.get(4).getDbmsSet().size());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog1.xml::1::testuser", changeSets.get(5).toString());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog3.xml::1::testuser", changeSets.get(6).toString());
    Assert.assertEquals("liquibase/parser/core/xml/ignoreDuplicatedChangeLogs/included.changelog2.xml::1::testuser", changeSets.get(7).toString());
}
Also used : ChangeSetVisitor(liquibase.changelog.visitor.ChangeSetVisitor) RuntimeEnvironment(liquibase.RuntimeEnvironment) JUnitResourceAccessor(liquibase.test.JUnitResourceAccessor) ArrayList(java.util.ArrayList) Contexts(liquibase.Contexts) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) ChangeLogIterator(liquibase.changelog.ChangeLogIterator) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) LabelExpression(liquibase.LabelExpression) MockDatabase(liquibase.sdk.database.MockDatabase) LiquibaseException(liquibase.exception.LiquibaseException) ChangeSetFilterResult(liquibase.changelog.filter.ChangeSetFilterResult) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

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