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);
}
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");
}
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);
}
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());
}
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);
}
Aggregations