Overview
Purpose
I use Hibernate as OR-Mapping Framework. While developing a installer and later a in-application upgrader I wanted that the installer should only use the hibernate mapping and only the upgrader should execute the liquibase ChangeSets.
After running the installer I have no information which ChangeSet was already installed by the installer and which one is a real new change coming from a new feature, which was develop after the installer finished.
Usage
Use this extension once per changeset to keep better control over your release cycle and display both to yourself or your installer/updater, which changeSets are already run and which onces are already installed because the date of installation is before the changesets release date.
...
Code Block |
---|
|
Database liquiBaseDatabase = getLiquiBaseDatabase();
if (liquiBaseDatabase != null) {
try {
// create the changeSet filters
List<ChangeSetFilter> changeSetFilters = new ArrayList<ChangeSetFilter>();
InstallationStatus installationStatus = this.installationValidationService.getInstallationStatus();
// ReleaseDateChangeSetFilter - only accepts changeSets witch are released after
filter.add(new ReleaseDateChangeSetFilter(installationStatus.getFinishedOn()));
// some other filters
try {
filter.add(new ShouldRunChangeSetFilter(liquiBaseDatabase));
}
catch (DatabaseException e) {
logger.warn("Init of ShouldRunChangeSetFilter failed because of:", e);
}
filter.add(new ContextChangeSetFilter("production"));
filter.add(new DbmsChangeSetFilter(liquiBaseDatabase));
ChangeLogParameters parameters = new ChangeLogParameters(liquiBaseDatabase);
// parse the changelog file
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(changelogFileName, resourceAccessor);
DatabaseChangeLog databaseChangeLog = parser.parse(changelogFileName, parameters, resourceAccessor);
Iterator<ChangeSet> changeSetIterator = databaseChangeLog.getChangeSets().iterator();
while (changeSetIterator.hasNext()) {
ChangeSet changeSet = changeSetIterator.next();
boolean removeChangeSet = false;
// ### ChangeSetFilter ###
if (changeSetFilters != null) {
for (ChangeSetFilter filter : changeSetFilters) {
if (!filter.accepts(changeSet)) {
logger.debug("ChangeSetFilter {} does not accept changeset!", filter);
removeChangeSet = true;
break;
}
}// for (filters)
}
if (removeChangeSet) {
changeSetIterator.remove();
}
} //while
return databaseChangeLog;
} catch (LiquibaseException e) {
logger.error("", e);
}
}
|
Files