use of liquibase.Liquibase in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method initDatabase.
private static DataSource initDatabase(final String dbUrlPropertyName, final String dbUserNamePropertyName, final String dbPasswordPropertyName, final String... liquibaseChangeLogXmls) throws Exception {
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(H2_DRIVER);
dataSource.setUrl(TEST_PROPERTIES.value(dbUrlPropertyName));
dataSource.setUsername(TEST_PROPERTIES.value(dbUserNamePropertyName));
dataSource.setPassword(TEST_PROPERTIES.value(dbPasswordPropertyName));
boolean dropped = false;
final JdbcConnection jdbcConnection = new JdbcConnection(dataSource.getConnection());
for (String liquibaseChangeLogXml : liquibaseChangeLogXmls) {
Liquibase liquibase = new Liquibase(liquibaseChangeLogXml, new ClassLoaderResourceAccessor(), jdbcConnection);
if (!dropped) {
liquibase.dropAll();
dropped = true;
}
liquibase.update("");
}
return dataSource;
}
use of liquibase.Liquibase in project iaf by ibissource.
the class LiquibaseMigrator method update.
@Override
public void update() {
List<String> changes = new ArrayList<>();
try (Liquibase liquibase = createMigrator()) {
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(contexts, labelExpression);
for (ChangeSet changeSet : changeSets) {
changes.add("LiquiBase applying change [" + changeSet.getId() + ":" + changeSet.getAuthor() + "] description [" + changeSet.getDescription() + "]");
}
if (!changeSets.isEmpty()) {
liquibase.update(contexts);
ChangeSet lastChange = changeSets.get(changeSets.size() - 1);
String tag = lastChange.getId() + ":" + lastChange.getAuthor();
liquibase.tag(tag);
if (changes.size() > 1) {
logConfigurationMessage("LiquiBase applied [" + changes.size() + "] change(s) and added tag [" + tag + "]");
} else {
for (String change : changes) {
logConfigurationMessage(change + " tag [" + tag + "]");
}
}
}
} catch (Exception e) {
String errorMsg = "Error running LiquiBase update. Failed to execute [" + changes.size() + "] change(s): ";
errorMsg += e.getMessage();
ConfigurationWarnings.add(this, log, errorMsg, e);
}
}
use of liquibase.Liquibase in project iaf by ibissource.
the class LiquibaseMigrator method createMigrator.
private Liquibase createMigrator(Resource resource) throws SQLException, LiquibaseException {
if (resource == null) {
throw new LiquibaseException("no resource provided");
}
ResourceAccessor resourceAccessor = new LiquibaseResourceAccessor(resource);
DatabaseConnection connection = getDatabaseConnection();
return new Liquibase(resource.getSystemId(), resourceAccessor, connection);
}
use of liquibase.Liquibase in project iaf by ibissource.
the class LiquibaseMigrator method doValidate.
private void doValidate() throws LiquibaseException, SQLException {
try (Liquibase liquibase = createMigrator()) {
Database database = liquibase.getDatabase();
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.waitForLock();
List<RanChangeSet> alreadyExecutedChangeSets = database.getRanChangeSetList();
for (RanChangeSet ranChangeSet : alreadyExecutedChangeSets) {
CheckSum checkSum = ranChangeSet.getLastCheckSum();
if (checkSum != null && checkSum.getVersion() < CheckSum.getCurrentVersion()) {
migrationLog.warn("checksum [" + checkSum + "] for changeset [" + ranChangeSet + "] is outdated and will be updated");
}
}
DatabaseChangeLog changeLog;
try {
changeLog = liquibase.getDatabaseChangeLog();
ChangeLogHistoryService changeLogHistoryService = ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database);
changeLogHistoryService.init();
// Validate old checksums and update if required
changeLogHistoryService.upgradeChecksums(changeLog, contexts, labelExpression);
changeLogHistoryService.reset();
// Validate the new (updated) checksums
changeLog.validate(database, contexts, labelExpression);
} finally {
try {
lockService.releaseLock();
} catch (LockException e) {
log.warn("unable to clean up Liquibase Lock", e);
}
LockServiceFactory.getInstance().resetAll();
ChangeLogHistoryServiceFactory.getInstance().resetAll();
Scope.getCurrentScope().getSingleton(ExecutorService.class).reset();
liquibase.setChangeExecListener(null);
}
}
}
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);
}
Aggregations