use of liquibase.change.core.TagDatabaseChange in project liquibase by liquibase.
the class OfflineChangeLogHistoryService method appendChangeSet.
protected void appendChangeSet(ChangeSet changeSet, ChangeSet.ExecType execType) throws DatabaseException {
File oldFile = this.changeLogFile;
File newFile = new File(oldFile.getParentFile(), oldFile.getName() + ".new");
try (Reader reader = new InputStreamReader(new FileInputStream(oldFile), GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue());
Writer writer = new OutputStreamWriter(new FileOutputStream(newFile), GlobalConfiguration.OUTPUT_FILE_ENCODING.getCurrentValue());
CSVReader csvReader = new CSVReader(reader);
CSVWriter csvWriter = new CSVWriter(writer)) {
String[] line;
while ((line = csvReader.readNext()) != null) {
csvWriter.writeNext(line);
}
String tag = "";
for (Change change : changeSet.getChanges()) {
if (change instanceof TagDatabaseChange) {
TagDatabaseChange tagChange = (TagDatabaseChange) change;
tag = tagChange.getTag();
}
}
String[] newLine = new String[Columns.values().length];
newLine[Columns.ID.ordinal()] = changeSet.getId();
newLine[Columns.AUTHOR.ordinal()] = changeSet.getAuthor();
newLine[Columns.FILENAME.ordinal()] = changeSet.getFilePath();
newLine[Columns.DATEEXECUTED.ordinal()] = new ISODateFormat().format(new java.sql.Timestamp(new Date().getTime()));
newLine[Columns.ORDEREXECUTED.ordinal()] = String.valueOf(getNextSequenceValue());
newLine[Columns.EXECTYPE.ordinal()] = execType.value;
newLine[Columns.MD5SUM.ordinal()] = changeSet.generateCheckSum().toString();
newLine[Columns.DESCRIPTION.ordinal()] = changeSet.getDescription();
newLine[Columns.COMMENTS.ordinal()] = changeSet.getComments();
newLine[Columns.TAG.ordinal()] = tag;
newLine[Columns.LIQUIBASE.ordinal()] = LiquibaseUtil.getBuildVersion();
newLine[Columns.CONTEXTS.ordinal()] = (changeSet.getContexts() == null) ? null : changeSet.getContexts().toString();
newLine[Columns.LABELS.ordinal()] = (changeSet.getLabels() == null) ? null : changeSet.getLabels().toString();
newLine[Columns.DEPLOYMENT_ID.ordinal()] = getDeploymentId();
csvWriter.writeNext(newLine);
} catch (Exception e) {
throw new DatabaseException(e);
}
oldFile.delete();
newFile.renameTo(oldFile);
}
use of liquibase.change.core.TagDatabaseChange in project liquibase by liquibase.
the class MarkChangeSetRanGenerator method generateSql.
@Override
public Sql[] generateSql(MarkChangeSetRanStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String dateValue = database.getCurrentDateTimeFunction();
ChangeSet changeSet = statement.getChangeSet();
SqlStatement runStatement;
// use LEGACY quoting since we're dealing with system objects
ObjectQuotingStrategy currentStrategy = database.getObjectQuotingStrategy();
database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY);
try {
try {
if (statement.getExecType().equals(ChangeSet.ExecType.FAILED) || statement.getExecType().equals(ChangeSet.ExecType.SKIPPED)) {
// don't mark
return new Sql[0];
}
String tag = null;
for (Change change : changeSet.getChanges()) {
if (change instanceof TagDatabaseChange) {
TagDatabaseChange tagChange = (TagDatabaseChange) change;
tag = tagChange.getTag();
}
}
if (statement.getExecType().ranBefore) {
runStatement = new UpdateStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()).addNewColumnValue("DATEEXECUTED", new DatabaseFunction(dateValue)).addNewColumnValue("ORDEREXECUTED", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getNextSequenceValue()).addNewColumnValue("MD5SUM", changeSet.generateCheckSum().toString()).addNewColumnValue("EXECTYPE", statement.getExecType().value).addNewColumnValue("DEPLOYMENT_ID", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getDeploymentId()).addNewColumnValue(COMMENTS, getCommentsColumn(changeSet)).addNewColumnValue(CONTEXTS, getContextsColumn(changeSet)).addNewColumnValue(LABELS, getLabelsColumn(changeSet)).setWhereClause(database.escapeObjectName("ID", LiquibaseColumn.class) + " = ? " + "AND " + database.escapeObjectName("AUTHOR", LiquibaseColumn.class) + " = ? " + "AND " + database.escapeObjectName("FILENAME", LiquibaseColumn.class) + " = ?").addWhereParameters(changeSet.getId(), changeSet.getAuthor(), changeSet.getFilePath());
if (tag != null) {
((UpdateStatement) runStatement).addNewColumnValue("TAG", tag);
}
} 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, getCommentsColumn(changeSet)).addColumnValue("EXECTYPE", statement.getExecType().value).addColumnValue(CONTEXTS, getContextsColumn(changeSet)).addColumnValue(LABELS, getLabelsColumn(changeSet)).addColumnValue("LIQUIBASE", StringUtil.limitSize(LiquibaseUtil.getBuildVersion().replaceAll("SNAPSHOT", "SNP").replaceAll("beta", "b").replaceAll("alpha", "b"), 20)).addColumnValue("DEPLOYMENT_ID", ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getDeploymentId());
if (tag != null) {
((InsertStatement) runStatement).addColumnValue("TAG", tag);
}
}
} catch (LiquibaseException e) {
throw new UnexpectedLiquibaseException(e);
}
return SqlGeneratorFactory.getInstance().generateSql(runStatement, database);
} finally {
database.setObjectQuotingStrategy(currentStrategy);
}
}
Aggregations