Skip to content

Commit

Permalink
Fix #2620 Empty-string descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
juliahayward committed Jan 15, 2020
1 parent 6e35dbc commit 0b8e932
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
Expand Up @@ -116,6 +116,12 @@ public String getRawCreateScript(Table table, boolean baseline) {
"CREATE INDEX \"" + table.getSchema().getName() + "\".\"" + table.getName() + "_s_idx\" ON " + table + " (\"success\");\n";
}

@Override
public boolean supportsEmptyMigrationDescription() {
// Oracle will convert the empty string to NULL implicitly, and throw an exception as the column is NOT NULL
return false;
}

@Override
protected String doGetCurrentUser() throws SQLException {
return getMainConnection().getJdbcTemplate().queryForString("SELECT USER FROM DUAL");
Expand Down
Expand Up @@ -89,6 +89,13 @@ public String getRawCreateScript(Table table, boolean baseline) {
"go\n";
}

@Override
public boolean supportsEmptyMigrationDescription() {
// Sybase will convert the empty string to a single space implicitly, which won't error on updating the
// history table but will subsequently fail validation of the history table against the file name.
return false;
}

@Override
public Delimiter getDefaultDelimiter() {
return Delimiter.GO;
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.flywaydb.core.api.resolver.ResolvedMigration;
import org.flywaydb.core.internal.resolver.ResolvedMigrationImpl;
import org.flywaydb.core.internal.schemahistory.AppliedMigration;
import org.flywaydb.core.internal.schemahistory.SchemaHistory;
import org.flywaydb.core.internal.util.AbbreviationUtils;

import java.util.Date;
Expand Down Expand Up @@ -319,8 +320,7 @@ public String validate() {
appliedMigration.getChecksum(), resolvedMigration.getChecksum());
}
}
if (!AbbreviationUtils.abbreviateDescription(resolvedMigration.getDescription())
.equals(appliedMigration.getDescription())) {
if (descriptionMismatch(resolvedMigration, appliedMigration)) {
return createMismatchMessage("description", migrationIdentifier,
appliedMigration.getDescription(), resolvedMigration.getDescription());
}
Expand All @@ -337,6 +337,16 @@ public String validate() {
return null;
}

private boolean descriptionMismatch(ResolvedMigration resolvedMigration, AppliedMigration appliedMigration) {
// For some databases, we can't put an empty description into the history table
if (SchemaHistory.NO_DESCRIPTION_MARKER.equals(appliedMigration.getDescription())) {
return !"".equals(resolvedMigration.getDescription());
}
// The default
return (!AbbreviationUtils.abbreviateDescription(resolvedMigration.getDescription())
.equals(appliedMigration.getDescription()));
}

/**
* Creates a message for a mismatch.
*
Expand Down
Expand Up @@ -155,6 +155,10 @@ protected void doAddAppliedMigration(int installedRank, MigrationVersion version
try {
String versionStr = version == null ? null : version.toString();

if (!database.supportsEmptyMigrationDescription() && "".equals(description)) {
description = NO_DESCRIPTION_MARKER;
}

jdbcTemplate.update(database.getInsertStatement(table),
installedRank, versionStr, description, type.name(), script, checksum, database.getInstalledBy(),
executionTime, success);
Expand Down
Expand Up @@ -30,6 +30,8 @@
* The schema history used to track all applied migrations.
*/
public abstract class SchemaHistory {
public static final String NO_DESCRIPTION_MARKER = "<< no description >>";

/**
* The schema history table used by Flyway.
* Non-final due to the table name fallback mechanism. Will be made final in Flyway 6.0.
Expand Down

0 comments on commit 0b8e932

Please sign in to comment.