Search in sources :

Example 96 with Liquibase

use of liquibase.Liquibase in project dropwizard by dropwizard.

the class DbLocksCommandTest method testFailsWhenBothListAndRelease.

@Test
void testFailsWhenBothListAndRelease() {
    final Liquibase liquibase = Mockito.mock(Liquibase.class);
    assertThatIllegalArgumentException().isThrownBy(() -> locksCommand.run(new Namespace(Maps.of("list", true, "release", true)), liquibase)).withMessage("Must specify either --list or --force-release");
}
Also used : Liquibase(liquibase.Liquibase) Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.jupiter.api.Test)

Example 97 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class ChangeLogSyncTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    OutputStreamWriter writer = null;
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = new OutputStreamWriter(outputFile.getOutputStream(), getOutputEncoding());
            liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels(), writer);
        } else {
            liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels());
        }
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate sync SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate sync SQL. Error creating output writer.", e);
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to sync change log: " + e.getMessage(), e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) LiquibaseException(liquibase.exception.LiquibaseException) Contexts(liquibase.Contexts)

Example 98 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class DropAllTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    try {
        if (StringUtil.trimToNull(schemas) != null) {
            List<String> schemaNames = StringUtil.splitAndTrim(this.schemas, ",");
            List<CatalogAndSchema> schemas = new ArrayList<>();
            for (String name : schemaNames) {
                schemas.add(new CatalogAndSchema(catalog, name));
            }
            liquibase.dropAll(schemas.toArray(new CatalogAndSchema[schemas.size()]));
        } else {
            liquibase.dropAll();
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to drop all objects from database: " + e.getMessage(), e);
    }
}
Also used : Liquibase(liquibase.Liquibase) ArrayList(java.util.ArrayList) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) CatalogAndSchema(liquibase.CatalogAndSchema)

Example 99 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class MarkNextChangeSetRanTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    Writer writer = null;
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = getOutputFileWriter();
            liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels(), writer);
        } else {
            liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels());
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to mark next changeset as ran: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new BuildException("Unable to mark next changeset as ran. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 100 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class GenerateChangeLogTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    Database database = liquibase.getDatabase();
    CatalogAndSchema catalogAndSchema = buildCatalogAndSchema(database);
    DiffOutputControl diffOutputControl = getDiffOutputControl();
    DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffOutputControl);
    for (ChangeLogOutputFile changeLogOutputFile : changeLogOutputFiles) {
        String encoding = getOutputEncoding(changeLogOutputFile);
        PrintStream printStream = null;
        try {
            FileResource outputFile = changeLogOutputFile.getOutputFile();
            ChangeLogSerializer changeLogSerializer = changeLogOutputFile.getChangeLogSerializer();
            log("Writing change log file " + outputFile.toString(), Project.MSG_INFO);
            printStream = new PrintStream(outputFile.getOutputStream(), true, encoding);
            liquibase.generateChangeLog(catalogAndSchema, diffToChangeLog, printStream, changeLogSerializer);
        } catch (UnsupportedEncodingException e) {
            throw new BuildException("Unable to generate a change log. Encoding [" + encoding + "] is not supported.", e);
        } catch (IOException e) {
            throw new BuildException("Unable to generate a change log. Error creating output stream.", e);
        } catch (ParserConfigurationException e) {
            throw new BuildException("Unable to generate a change log. Error configuring parser.", e);
        } catch (DatabaseException e) {
            throw new BuildException("Unable to generate a change log: " + e.getMessage(), e);
        } finally {
            FileUtils.close(printStream);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) FileResource(org.apache.tools.ant.types.resources.FileResource) DiffOutputControl(liquibase.diff.output.DiffOutputControl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChangeLogSerializer(liquibase.serializer.ChangeLogSerializer) JsonChangeLogSerializer(liquibase.serializer.core.json.JsonChangeLogSerializer) StringChangeLogSerializer(liquibase.serializer.core.string.StringChangeLogSerializer) IOException(java.io.IOException) CatalogAndSchema(liquibase.CatalogAndSchema) ChangeLogOutputFile(liquibase.integration.ant.type.ChangeLogOutputFile) Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) BuildException(org.apache.tools.ant.BuildException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DatabaseException(liquibase.exception.DatabaseException)

Aggregations

Liquibase (liquibase.Liquibase)151 JdbcConnection (liquibase.database.jvm.JdbcConnection)57 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)48 Database (liquibase.database.Database)44 LiquibaseException (liquibase.exception.LiquibaseException)44 Contexts (liquibase.Contexts)31 SQLException (java.sql.SQLException)30 Test (org.junit.Test)30 IOException (java.io.IOException)29 Connection (java.sql.Connection)27 LabelExpression (liquibase.LabelExpression)17 ResourceAccessor (liquibase.resource.ResourceAccessor)16 DatabaseException (liquibase.exception.DatabaseException)15 ChangeSet (liquibase.changelog.ChangeSet)13 ValidationFailedException (liquibase.exception.ValidationFailedException)12 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)11 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 LockException (liquibase.exception.LockException)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 BuildException (org.apache.tools.ant.BuildException)10