@Override
public Sql[] generateSql(MarkChangeSetRanStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String dateValue = database.getCurrentDateTimeFunction();
ChangeSet changeSet = statement.getChangeSet();
SqlStatement runStatement;
try {
if (statement.getExecType().equals(ChangeSet.ExecType.FAILED) || statement.getExecType().equals(ChangeSet.ExecType.SKIPPED)) {
return new Sql[0]; //don't mark
} else if (statement.getExecType().ranBefore) {
runStatement = new UpdateStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName())
.addNewColumnValue("DATEEXECUTED", new DatabaseFunction(dateValue))
.addNewColumnValue("MD5SUM", changeSet.generateCheckSum().toString())
.addNewColumnValue("EXECTYPE", statement.getExecType().value)
.setWhereClause("ID=? AND AUTHOR=? AND FILENAME=?")
.addWhereParameters(changeSet.getId(), changeSet.getAuthor(), changeSet.getFilePath());
} else {
runStatement = new InsertStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName())
.addColumnValue("ID", changeSet.getId())
.addColumnValue("AUTHOR", changeSet.getAuthor())
.addColumnValue("FILENAME", changeSet.getFilePath())
.addColumnValue("DATEEXECUTED", new DatabaseFunction(dateValue))
.addColumnValue("ORDEREXECUTED", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getNextSequenceValue())
.addColumnValue("MD5SUM", changeSet.generateCheckSum().toString())
.addColumnValue("DESCRIPTION", limitSize(changeSet.getDescription()))
.addColumnValue("COMMENTS", limitSize(StringUtils.trimToEmpty(changeSet.getComments())))
.addColumnValue("EXECTYPE", statement.getExecType().value)
.addColumnValue("LIQUIBASE", LiquibaseUtil.getBuildVersion().replaceAll("SNAPSHOT", "SNP"));
String tag = null;
List<Change> changes = changeSet.getChanges();
if (changes != null && changes.size() == 1) {
Change change = changes.get(0);
if (change instanceof TagDatabaseChange) {
TagDatabaseChange tagChange = (TagDatabaseChange) change;
tag = tagChange.getTag();