Search in sources :

Example 66 with Liquibase

use of liquibase.Liquibase in project jOOQ by jOOQ.

the class LiquibaseDatabase method export.

@Override
protected void export() throws Exception {
    String rootPath = getProperties().getProperty("rootPath");
    String scripts = getProperties().getProperty("scripts");
    includeLiquibaseTables = Boolean.parseBoolean(getProperties().getProperty("includeLiquibaseTables", "false"));
    if (isBlank(scripts)) {
        scripts = "";
        log.warn("No scripts defined", "It is recommended that you provide an explicit script directory to scan");
    }
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection()));
    String contexts = "";
    // Database.setXyz() configuration setter calls
    for (Entry<Object, Object> entry : getProperties().entrySet()) {
        String key = "" + entry.getKey();
        if (key.startsWith("database.")) {
            String property = key.substring("database.".length());
            Method setter = SETTERS.get("set" + Character.toUpperCase(property.charAt(0)) + property.substring(1));
            try {
                if (setter != null)
                    setter.invoke(database, Convert.convert(entry.getValue(), setter.getParameterTypes()[0]));
            } catch (Exception e) {
                log.warn("Configuration error", e.getMessage(), e);
            }
        } else // [#9872] Some changeLogParameters can also be passed along
        if (key.startsWith("changeLogParameters.")) {
            String property = key.substring("changeLogParameters.".length());
            if ("contexts".equals(property))
                contexts = "" + entry.getValue();
        }
    }
    // Retrieve changeLog table names as they might be overridden by configuration setters
    databaseChangeLogTableName = database.getDatabaseChangeLogTableName();
    databaseChangeLogLockTableName = database.getDatabaseChangeLogLockTableName();
    // [#9866] Allow for loading included files from the classpath or using absolute paths.
    // [#12872] [#13021] The decision is made based on the presence of the rootPath property
    ResourceAccessor ra = StringUtils.isBlank(rootPath) ? new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader())) : new FileSystemResourceAccessor(new File(rootPath));
    Liquibase liquibase = new Liquibase(scripts, ra, database);
    liquibase.update(contexts);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) JdbcConnection(liquibase.database.jvm.JdbcConnection) Method(java.lang.reflect.Method) SQLException(java.sql.SQLException) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) AbstractInterpretingDatabase(org.jooq.meta.extensions.AbstractInterpretingDatabase) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) File(java.io.File)

Example 67 with Liquibase

use of liquibase.Liquibase in project gocd by gocd.

the class LiquibaseMigtrationTest method migrate.

private void migrate(String migration) throws SQLException, LiquibaseException {
    Connection connection = dataSource.getConnection();
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
    Liquibase liquibase = new Liquibase("db-migration-scripts/" + migration, new ClassLoaderResourceAccessor(getClass().getClassLoader()), database);
    liquibase.update("test");
}
Also used : Liquibase(liquibase.Liquibase) Connection(java.sql.Connection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Database(liquibase.database.Database) JdbcConnection(liquibase.database.jvm.JdbcConnection) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 68 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class AbstractIntegrationTest method runUpdateOnOldChangelogTableFormat.

@Test
public void runUpdateOnOldChangelogTableFormat() throws Exception {
    if (database == null) {
        return;
    }
    Liquibase liquibase = createLiquibase(completeChangeLog);
    clearDatabase(liquibase);
    ((JdbcConnection) database.getConnection()).getUnderlyingConnection().createStatement().execute("CREATE TABLE DATABASECHANGELOG (id varchar(150) NOT NULL, " + "author varchar(150) NOT NULL, " + "filename varchar(255) NOT NULL, " + "dateExecuted " + DataTypeFactory.getInstance().fromDescription("datetime", database).toDatabaseDataType(database) + " NOT NULL, " + "md5sum varchar(32), " + "description varchar(255), " + "comments varchar(255), " + "tag varchar(255), " + "liquibase varchar(10), " + "PRIMARY KEY(id, author, filename))");
    liquibase = createLiquibase(completeChangeLog);
    liquibase.update(this.contexts);
}
Also used : Liquibase(liquibase.Liquibase) JdbcConnection(liquibase.database.jvm.JdbcConnection) Test(org.junit.Test)

Example 69 with Liquibase

use of liquibase.Liquibase 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 70 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class AbstractIntegrationTest method testOutputChangeLogIgnoringSchema.

@Test
public void testOutputChangeLogIgnoringSchema() throws Exception {
    if (getDatabase() == null) {
        return;
    }
    String schemaName = getDatabase().getDefaultSchemaName();
    if (schemaName == null) {
        return;
    }
    getDatabase().setOutputDefaultSchema(false);
    getDatabase().setOutputDefaultCatalog(false);
    StringWriter output = new StringWriter();
    Liquibase liquibase = createLiquibase(includedChangeLog);
    clearDatabase(liquibase);
    liquibase = createLiquibase(includedChangeLog);
    liquibase.update(contexts, output);
    String outputResult = output.getBuffer().toString();
    assertNotNull(outputResult);
    //should be pretty big
    assertTrue(outputResult.length() > 100);
    //        System.out.println(outputResult);
    CharSequence expected = "CREATE TABLE " + getDatabase().escapeTableName(getDatabase().getLiquibaseCatalogName(), getDatabase().getLiquibaseSchemaName(), getDatabase().getDatabaseChangeLogTableName());
    assertTrue("create databasechangelog command not found in: \n" + outputResult, outputResult.contains(expected));
    assertTrue("create databasechangeloglock command not found in: \n" + outputResult, outputResult.contains(expected));
    assertFalse("the scheame name '" + schemaName + "' should be ignored\n\n" + outputResult, outputResult.contains(schemaName + "."));
//        System.out.println("expected    : " + expected);
//        System.out.println("outputResult: " + outputResult);
}
Also used : Liquibase(liquibase.Liquibase) Test(org.junit.Test)

Aggregations

Liquibase (liquibase.Liquibase)125 LiquibaseException (liquibase.exception.LiquibaseException)37 JdbcConnection (liquibase.database.jvm.JdbcConnection)35 Database (liquibase.database.Database)33 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)33 Test (org.junit.Test)30 IOException (java.io.IOException)27 Contexts (liquibase.Contexts)24 SQLException (java.sql.SQLException)23 ResourceAccessor (liquibase.resource.ResourceAccessor)14 ChangeSet (liquibase.changelog.ChangeSet)13 DatabaseException (liquibase.exception.DatabaseException)12 ValidationFailedException (liquibase.exception.ValidationFailedException)12 LabelExpression (liquibase.LabelExpression)11 Connection (java.sql.Connection)10 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 BuildException (org.apache.tools.ant.BuildException)10 LockException (liquibase.exception.LockException)9