Search in sources :

Example 6 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class AbstractIntegrationTest method testEncodingUpdating2SQL.

@Test
public void testEncodingUpdating2SQL() throws Exception {
    if (database == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(encodingChangeLog);
    StringWriter writer = new StringWriter();
    liquibase.update(this.contexts, writer);
    assertTrue("Update to SQL preserves encoding", new RegexMatcher(writer.toString(), new String[] { //For the UTF-8 encoded cvs
    "^.*INSERT.*VALUES.*àèìòùáéíóúÀÈÌÒÙÁÉÍÓÚâêîôûäëïöü.*$", "çñ®", //For the latin1 one
    "^.*INSERT.*VALUES.*àèìòùáéíóúÀÈÌÒÙÁÉÍÓÚâêîôûäëïöü.*$", "çñ®" }).allMatchedInSequentialOrder());
}
Also used : Liquibase(liquibase.Liquibase) RegexMatcher(liquibase.util.RegexMatcher) Test(org.junit.Test)

Example 7 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class AbstractIntegrationTest method testRollbackToChange.

@Test
public void testRollbackToChange() throws Exception {
    if (database == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(rollbackChangeLog);
    liquibase.dropAll(getSchemasToDrop());
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.update(this.contexts);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.rollback(8, this.contexts);
    liquibase.tag("testRollbackToChange");
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.update(this.contexts);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.rollback("testRollbackToChange", this.contexts);
}
Also used : Liquibase(liquibase.Liquibase) Test(org.junit.Test)

Example 8 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class AbstractIntegrationTest method testRollbackableChangeLog.

@Test
public void testRollbackableChangeLog() throws Exception {
    if (database == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(rollbackChangeLog);
    clearDatabase(liquibase);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.update(this.contexts);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.rollback(new Date(0), this.contexts);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.update(this.contexts);
    liquibase = createLiquibase(rollbackChangeLog);
    liquibase.rollback(new Date(0), this.contexts);
}
Also used : Liquibase(liquibase.Liquibase) Test(org.junit.Test)

Example 9 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class LiquibaseMigrateSQL method createLiquibase.

@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
    Liquibase liquibase = super.createLiquibase(fo, db);
    // Setup the output file writer
    try {
        if (!migrationSqlOutputFile.exists()) {
            // Ensure the parent directories exist
            migrationSqlOutputFile.getParentFile().mkdirs();
            // Create the actual file
            if (!migrationSqlOutputFile.createNewFile()) {
                throw new MojoExecutionException("Cannot create the migration SQL file; " + migrationSqlOutputFile.getAbsolutePath());
            }
        }
        outputWriter = getOutputWriter(migrationSqlOutputFile);
    } catch (IOException e) {
        getLog().error(e);
        throw new MojoExecutionException("Failed to create SQL output writer", e);
    }
    getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
    return liquibase;
}
Also used : Liquibase(liquibase.Liquibase) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 10 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class LiquibaseRollbackSQL method createLiquibase.

@Override
protected Liquibase createLiquibase(ResourceAccessor fo, Database db) throws MojoExecutionException {
    Liquibase liquibase = super.createLiquibase(fo, db);
    // Setup the output file writer
    try {
        if (!migrationSqlOutputFile.exists()) {
            // Ensure the parent directories exist
            migrationSqlOutputFile.getParentFile().mkdirs();
            // Create the actual file
            if (!migrationSqlOutputFile.createNewFile()) {
                throw new MojoExecutionException("Cannot create the migration SQL file; " + migrationSqlOutputFile.getAbsolutePath());
            }
        }
        outputWriter = getOutputWriter(migrationSqlOutputFile);
    } catch (IOException e) {
        getLog().error(e);
        throw new MojoExecutionException("Failed to create SQL output writer", e);
    }
    getLog().info("Output SQL Migration File: " + migrationSqlOutputFile.getAbsolutePath());
    return liquibase;
}
Also used : Liquibase(liquibase.Liquibase) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException)

Aggregations

Liquibase (liquibase.Liquibase)97 Test (org.junit.Test)29 LiquibaseException (liquibase.exception.LiquibaseException)25 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)25 JdbcConnection (liquibase.database.jvm.JdbcConnection)24 IOException (java.io.IOException)22 Database (liquibase.database.Database)22 SQLException (java.sql.SQLException)17 Contexts (liquibase.Contexts)17 ValidationFailedException (liquibase.exception.ValidationFailedException)11 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 DatabaseException (liquibase.exception.DatabaseException)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 BuildException (org.apache.tools.ant.BuildException)10 ChangeSet (liquibase.changelog.ChangeSet)9 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)9 Connection (java.sql.Connection)8 ResourceAccessor (liquibase.resource.ResourceAccessor)8 FileNotFoundException (java.io.FileNotFoundException)6 Date (java.util.Date)6