public boolean isSameAs(ChangeSet changeSet) { return this.getChangeLog() .replace('\\', '/') .equalsIgnoreCase(changeSet.getFilePath().replace('\\', '/')) && this.getId().equalsIgnoreCase(changeSet.getId()) && this.getAuthor().equalsIgnoreCase(changeSet.getAuthor()); }
public RanChangeSet(ChangeSet changeSet, ChangeSet.ExecType execType) { this( changeSet.getFilePath(), changeSet.getId(), changeSet.getAuthor(), changeSet.generateCheckSum(), new Date(), null, execType, changeSet.getDescription()); }
/** Returns the run status for the given ChangeSet */ @Override public ChangeSet.RunStatus getRunStatus(ChangeSet changeSet) throws DatabaseException, DatabaseHistoryException { if (!hasDatabaseChangeLogTable()) { return ChangeSet.RunStatus.NOT_RAN; } RanChangeSet foundRan = getRanChangeSet(changeSet); if (foundRan == null) { return ChangeSet.RunStatus.NOT_RAN; } else { if (foundRan.getLastCheckSum() == null) { try { LogFactory.getLogger().info("Updating NULL md5sum for " + changeSet.toString()); ExecutorService.getInstance() .getExecutor(this) .execute( new RawSqlStatement( "UPDATE " + escapeTableName( getLiquibaseSchemaName(), getDatabaseChangeLogTableName()) + " SET MD5SUM='" + changeSet.generateCheckSum().toString() + "' WHERE ID='" + changeSet.getId() + "' AND AUTHOR='" + changeSet.getAuthor() + "' AND FILENAME='" + changeSet.getFilePath() + "'")); this.commit(); } catch (DatabaseException e) { throw new DatabaseException(e); } return ChangeSet.RunStatus.ALREADY_RAN; } else { if (foundRan.getLastCheckSum().equals(changeSet.generateCheckSum())) { return ChangeSet.RunStatus.ALREADY_RAN; } else { if (changeSet.shouldRunOnChange()) { return ChangeSet.RunStatus.RUN_AGAIN; } else { return ChangeSet.RunStatus.INVALID_MD5SUM; // throw new DatabaseHistoryException("MD5 Check for " + changeSet.toString() + " // failed"); } } } } }
@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( database.escapeStringForDatabase( 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(); } } if (tag != null) { ((InsertStatement) runStatement).addColumnValue("TAG", tag); } } } catch (LiquibaseException e) { throw new UnexpectedLiquibaseException(e); } return SqlGeneratorFactory.getInstance().generateSql(runStatement, database); }