Skip to content

Commit

Permalink
Fixed flyway#1893: flyway schema version table creation fails after S…
Browse files Browse the repository at this point in the history
…QL callback execution
  • Loading branch information
Axel Fontaine committed Jan 16, 2018
1 parent 5e3703a commit a71e6ed
Show file tree
Hide file tree
Showing 34 changed files with 508 additions and 629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import org.flywaydb.core.api.logging.Log;
import org.flywaydb.core.api.logging.LogFactory;
import org.flywaydb.core.internal.database.Database;
import org.flywaydb.core.internal.util.jdbc.JdbcTemplate;
import org.flywaydb.core.internal.database.SqlScript;
import org.flywaydb.core.internal.util.Location;
import org.flywaydb.core.internal.util.Locations;
import org.flywaydb.core.internal.util.PlaceholderReplacer;
import org.flywaydb.core.internal.util.jdbc.JdbcTemplate;
import org.flywaydb.core.internal.util.scanner.LoadableResource;
import org.flywaydb.core.internal.util.scanner.Scanner;

Expand Down Expand Up @@ -75,7 +75,7 @@ public class SqlScriptFlywayCallback implements FlywayCallback {
/**
* Creates a new instance.
*
* @param database The database-specific support.
* @param database The database-specific support.
* @param scanner The Scanner for loading migrations on the classpath.
* @param locations The locations where migrations are located.
* @param placeholderReplacer The placeholder replacer to apply to sql migration scripts.
Expand Down Expand Up @@ -106,7 +106,8 @@ public SqlScriptFlywayCallback(Database database, Scanner scanner, Locations loc
"-> " + existing.getResource().getLocationOnDisk() + "\n" +
"-> " + resource.getLocationOnDisk());
}
scripts.put(key, database.createSqlScript(resource, placeholderReplacer, configuration.getEncoding(),
scripts.put(key, database.createSqlScript(resource,
placeholderReplacer.replacePlaceholders(resource.loadAsString(configuration.getEncoding())),
configuration.isMixed()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.flywaydb.core.internal.util.Pair;
import org.flywaydb.core.internal.util.PlaceholderReplacer;
import org.flywaydb.core.internal.util.jdbc.JdbcUtils;
import org.flywaydb.core.internal.util.scanner.LoadableResource;
import org.flywaydb.core.internal.util.scanner.Resource;
import org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource;

import java.io.Closeable;
Expand Down Expand Up @@ -137,25 +137,43 @@ protected final void recommendFlywayUpgrade(String database, String version) {
/**
* Creates a new SqlScript for this specific database.
*
* @param resource The resource containing the SQL script.
* @param sqlScriptSource The sql script as a text block with all placeholders already replaced.
* @param mixed Whether to allow mixing transactional and non-transactional statements within the same migration.
* @return The new SqlScript.
*/
public abstract SqlScript createSqlScript(String sqlScriptSource);
public final SqlScript createSqlScript(Resource resource, String sqlScriptSource, boolean mixed



) {





return doCreateSqlScript(resource, sqlScriptSource, mixed



);
}

/**
* Creates a new SqlScript for this specific database.
*
* @param sqlScriptResource The resource containing the statements.
* @param placeholderReplacer The placeholder replacer.
* @param encoding The encoding to use.
* @param mixed Whether to allow mixing transactional and non-transactional statements within the same migration.
* @param resource The resource containing the SQL script.
* @param sqlScriptSource The sql script as a text block with all placeholders already replaced.
* @param mixed Whether to allow mixing transactional and non-transactional statements within the same migration.
* @return The new SqlScript.
*/
public abstract SqlScript createSqlScript(LoadableResource sqlScriptResource, PlaceholderReplacer placeholderReplacer,
String encoding, boolean mixed
protected abstract SqlScript doCreateSqlScript(Resource resource, String sqlScriptSource, boolean mixed



Expand Down Expand Up @@ -320,6 +338,7 @@ public final String getCreateScript(Table table) {
Map<String, String> placeholders = new HashMap<>();
placeholders.put("schema", table.getSchema().getName());
placeholders.put("table", table.getName());
placeholders.put("table_quoted", table.toString());
return new PlaceholderReplacer(placeholders, "${", "}").replacePlaceholders(source);
}

Expand Down
Loading

0 comments on commit a71e6ed

Please sign in to comment.