Skip to content

Commit

Permalink
Bump version to flyway-9.10.0
Browse files Browse the repository at this point in the history
Please see the GH release for the release notes

add executeInTransaction as a global configuration parameter

fix npe when using working directory and jar dirs in configuration
  • Loading branch information
rg-buildmonkey committed Dec 8, 2022
1 parent a0d26ea commit 9e8910a
Show file tree
Hide file tree
Showing 28 changed files with 197 additions and 87 deletions.
Expand Up @@ -23,6 +23,7 @@ subtitle: placeholder page
- [dryRunOutput](Configuration/Parameters/Dry Run Output) {% include teams.html %}
- [encoding](Configuration/parameters/encoding)
- [errorOverrides](Configuration/parameters/errorOverrides) {% include teams.html %}
- [executeInTransaction](Configuration/parameters/Execute In Transaction)
- [group](Configuration/parameters/group)
- [installedBy](Configuration/Parameters/Installed By)
- [jarDirs](Configuration/Parameters/Jar Dirs)
Expand Down
@@ -0,0 +1,42 @@
---
pill: executeInTransaction
subtitle: flyway.executeInTransaction
---

# Execute In Transaction

## Description
Whether Flyway should execute SQL within a transaction. <br/>

## Default
true

## Usage

### Commandline
```powershell
./flyway -executeInTransaction="false" migrate
```

### Configuration File
```properties
flyway.executeInTransaction=false
```

### Environment Variable
```properties
FLYWAY_EXECUTE_IN_TRANSACTION=false
```

### API
```java
Flyway.configure()
.executeInTransaction(false)
.load()
```

### Gradle
Not available

### Maven
Not available
Expand Up @@ -18,6 +18,21 @@
<div class="col-md-9">

<div class="release">
<h2 id="9.10.0">Flyway 9.10.0 (2022-12-08)</h2>

<h3>Bug fixes</h3>
<ul>
<li>Fix NPE that results when configuring either 'workingDirectory' or 'jarDirs'</li>
</ul>

<h3>New features</h3>
<ul>
<li>Adds a new configuration parameter ('flyway.executeInTransaction') which determines whether SQL execution in a transaction is enabled.</li>
</ul>

</div>

<div class="release">
<h2 id="9.9.0">Flyway 9.9.0 (2022-12-07)</h2>

<h3>Bug fixes</h3>
Expand Down
2 changes: 1 addition & 1 deletion documentation/_config.yml
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

flywayVersion: 9.9.0
flywayVersion: 9.10.0
enterpriseUrl: https://download.red-gate.com/maven/release/org/flywaydb/enterprise
kramdown:
smart_quotes: ["apos", "apos", "quot", "quot"]
Expand Down
4 changes: 2 additions & 2 deletions flyway-commandline/pom.xml
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-parent</artifactId>
<version>9.9.0</version>
<version>9.10.0</version>
</parent>
<artifactId>flyway-commandline</artifactId>
<packaging>jar</packaging>
Expand All @@ -31,7 +31,7 @@


<flyway-gcp-bigquery.version>${project.version}</flyway-gcp-bigquery.version>
<flyway-gcp-spanner.version>9.9.0-beta</flyway-gcp-spanner.version>
<flyway-gcp-spanner.version>9.10.0-beta</flyway-gcp-spanner.version>
<flyway-sqlserver.version>${project.version}</flyway-sqlserver.version>
<flyway-mysql.version>${project.version}</flyway-mysql.version>
<flyway-firebird.version>${project.version}</flyway-firebird.version>
Expand Down
3 changes: 3 additions & 0 deletions flyway-commandline/src/main/assembly/flyway.conf
Expand Up @@ -185,6 +185,9 @@ flyway.locations=filesystem:sql
# Flyway Teams only
# flyway.batch=

# Whether SQL should be executed in a transaction (default: true).
# flyway.executionInTransaction=

# Encoding of SQL migrations (default: UTF-8). Caution: changing the encoding after migrations have been run
# will invalidate the calculated checksums and require a `flyway repair`.
# flyway.encoding=
Expand Down
Expand Up @@ -206,11 +206,14 @@ private static Configuration getConfiguration(CommandLineArguments commandLineAr

File jarDir = new File(workingDirectory, "jars");
if (jarDir.exists()) {

jarDirs = StringUtils.tokenizeToStringCollection(commandLineArguments.getConfiguration().get(ConfigUtils.JAR_DIRS).replace(File.pathSeparator, ","), ",");
jarDirs.add(jarDir.getAbsolutePath());
}

String configuredJarDirs = commandLineArguments.getConfiguration().get(ConfigUtils.JAR_DIRS);
if (StringUtils.hasText(configuredJarDirs)) {
jarDirs.addAll(StringUtils.tokenizeToStringCollection(configuredJarDirs.replace(File.pathSeparator, ","), ","));
}

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

List<File> jarFiles = new ArrayList<>();
Expand Down Expand Up @@ -258,9 +261,13 @@ private static Configuration getLegacyConfiguration(CommandLineArguments command

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

List<File> jarFiles = new ArrayList<>();
jarFiles.addAll(getJdbcDriverJarFiles());
jarFiles.addAll(getJavaMigrationJarFiles(StringUtils.tokenizeToStringArray(config.get(ConfigUtils.JAR_DIRS).replace(File.pathSeparator, ","), ",")));
List<File> jarFiles = new ArrayList<>(getJdbcDriverJarFiles());

String jarDirs = config.get(ConfigUtils.JAR_DIRS);
if (StringUtils.hasText(jarDirs)) {
jarFiles.addAll(getJavaMigrationJarFiles(StringUtils.tokenizeToStringArray(jarDirs.replace(File.pathSeparator, ","), ",")));
}

if (!jarFiles.isEmpty()) {
classLoader = ClassUtils.addJarsOrDirectoriesToClasspath(classLoader, jarFiles);
}
Expand All @@ -279,7 +286,6 @@ private static Configuration getLegacyConfiguration(CommandLineArguments command


return new FluentConfiguration(classLoader).configuration(config);

}

private static void printError(CommandLineArguments commandLineArguments, Exception e, OperationResult errorResult) {
Expand Down Expand Up @@ -498,6 +504,7 @@ private static void printUsage() {
LOG.info(indent + "mixed Allow mixing transactional and non-transactional statements");
LOG.info(indent + "encoding Encoding of SQL migrations");
LOG.info(indent + "detectEncoding [" + "teams] Whether Flyway should try to automatically detect SQL migration file encoding");
LOG.info(indent + "executionInTransaction Whether SQL should execute within a transaction");
LOG.info(indent + "placeholderReplacement Whether placeholders should be replaced");
LOG.info(indent + "placeholders Placeholders to replace in sql migrations");
LOG.info(indent + "placeholderPrefix Prefix of every placeholder");
Expand Down
2 changes: 1 addition & 1 deletion flyway-community-db-support/pom.xml
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-parent</artifactId>
<version>9.9.0</version>
<version>9.10.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion flyway-core/pom.xml
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-parent</artifactId>
<version>9.9.0</version>
<version>9.10.0</version>
</parent>
<artifactId>flyway-core</artifactId>
<packaging>jar</packaging>
Expand Down
Expand Up @@ -63,7 +63,7 @@ public class ClassicConfiguration implements Configuration {

@Getter
@Setter
private ConfigurationModel modernConfig = new ConfigurationModel().defaults();
private ConfigurationModel modernConfig = ConfigurationModel.defaults();

@Getter
private final Map<String, ResolvedEnvironment> resolvedEnvironments = new HashMap<>();
Expand Down Expand Up @@ -417,6 +417,11 @@ public String getUndoSqlMigrationPrefix() {
return getModernFlyway().getUndoSqlMigrationPrefix();
}

@Override
public boolean isExecuteInTransaction() {
return getModernFlyway().getExecuteInTransaction();
}

@Override
public String getRepeatableSqlMigrationPrefix() {
return getModernFlyway().getRepeatableSqlMigrationPrefix();
Expand Down Expand Up @@ -803,6 +808,15 @@ public void setDetectEncoding(boolean detectEncoding) {



}

/**
* Sets whether SQL should be executed within a transaction.
*
* @param executeInTransaction {@code true} to enable execution of SQL in a transaction, {@code false} otherwise
*/
public void setExecuteInTransaction(boolean executeInTransaction) {
getModernFlyway().setExecuteInTransaction(executeInTransaction);
}

/**
Expand Down
Expand Up @@ -160,6 +160,13 @@ public interface Configuration {
*/
String getUndoSqlMigrationPrefix();

/**
* Checks whether SQL is executed in a transaction.
*
* @return Whether SQL is executed in a transaction. (default: true)
*/
boolean isExecuteInTransaction();

/**
* Retrieves the file name prefix for repeatable SQL migrations.
* Repeatable SQL migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix,
Expand Down
Expand Up @@ -314,6 +314,17 @@ public FluentConfiguration encoding(Charset encoding) {
return this;
}

/**
* Sets whether SQL should be executed within a transaction.
*
* @param executeInTransaction {@code true} to enable execution of SQL in a transaction, {@code false} otherwise
*/
public FluentConfiguration executeInTransaction(boolean executeInTransaction) {
config.setExecuteInTransaction(executeInTransaction);
return this;
}


/**
* Whether Flyway should try to automatically detect SQL migration file encoding
*
Expand Down
Expand Up @@ -54,6 +54,7 @@ public class ConfigUtils {
public static final String ENCODING = "flyway.encoding";
public static final String DETECT_ENCODING = "flyway.detectEncoding";
public static final String ERROR_OVERRIDES = "flyway.errorOverrides";
public static final String EXECUTE_IN_TRANSACTION = "flyway.executeInTransaction";
public static final String GROUP = "flyway.group";
public static final String IGNORE_MIGRATION_PATTERNS = "flyway.ignoreMigrationPatterns";
public static final String INIT_SQL = "flyway.initSql";
Expand Down Expand Up @@ -179,6 +180,9 @@ private static String convertKey(String key) {
if ("FLYWAY_ENCODING".equals(key)) {
return ENCODING;
}
if ("FLYWAY_EXECUTE_IN_TRANSACTION".equals(key)) {
return EXECUTE_IN_TRANSACTION;
}
if ("FLYWAY_DETECT_ENCODING".equals(key)) {
return DETECT_ENCODING;
}
Expand Down
Expand Up @@ -77,7 +77,7 @@ private static Map<String, Object> unflattenMap(Map<String, String> map) {
}

public static ConfigurationModel loadConfigurationFiles(List<File> files, String workingDirectory) {
ConfigurationModel defaultConfig = new ConfigurationModel().defaults();
ConfigurationModel defaultConfig = ConfigurationModel.defaults();
return files.stream()
.map(f -> TomlUtils.loadConfigurationFile(f, workingDirectory))
.reduce(defaultConfig, ConfigurationModel::merge);
Expand Down
Expand Up @@ -30,10 +30,11 @@ public class ConfigurationModel {
private Map<String, EnvironmentModel> environments = new HashMap<>();
private FlywayModel flyway = new FlywayModel();

public ConfigurationModel defaults() {
this.flyway.defaults();
this.environments.put("default", new EnvironmentModel().defaults());
return this;
public static ConfigurationModel defaults() {
ConfigurationModel model = new ConfigurationModel();
model.flyway = FlywayModel.defaults();
model.environments.put("default", EnvironmentModel.defaults());
return model;
}

public ConfigurationModel merge(ConfigurationModel otherPojo) {
Expand Down
Expand Up @@ -44,11 +44,12 @@ public class EnvironmentModel {

private Map<String, Map<String, String>> resolvers;

public EnvironmentModel defaults() {
schemas = new ArrayList<>();
connectRetries = 0;
connectRetriesInterval = 120;
return this;
public static EnvironmentModel defaults() {
EnvironmentModel model = new EnvironmentModel();
model.schemas = new ArrayList<>();
model.connectRetries = 0;
model.connectRetriesInterval = 120;
return model;
}

public EnvironmentModel merge(EnvironmentModel otherPojo) {
Expand Down

0 comments on commit 9e8910a

Please sign in to comment.