Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
xtermi2 committed May 21, 2024
2 parents 6738110 + 16845d0 commit acdb363
Show file tree
Hide file tree
Showing 66 changed files with 333 additions and 2,262 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/maven-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build-with-jdk:
strategy:
matrix:
java: [ 8, 11, 17, 21 ]
java: [ 17, 21 ]
fail-fast: false
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -109,12 +109,12 @@ jobs:
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Set up JDK 8
- name: Set up JDK 17
# with JDK 11 the maven-javadoc-plugin > 3.0.1 fails with "cannot find symbol org.elasticsearch.*"
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8
java-version: 17
- name: Release to maven central
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
Expand All @@ -140,12 +140,12 @@ jobs:
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Set up JDK 8
- name: Set up JDK 17
# with JDK 11 the maven-javadoc-plugin > 3.0.1 fails with "cannot find symbol org.elasticsearch.*"
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8
java-version: 17
- name: Release to maven central
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 8
- name: Set up JDK 17
# build with JDK 8 because of issue https://github.com/trautonen/coveralls-maven-plugin/issues/112
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 8
java-version: 17
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Build and test with Maven
run: $MVN_CMD install
- name: upload test results
uses: actions/upload-artifact@v3 # upload test results
uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: test-results
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Successful executed migration scripts will not be executed again!

## 2 Features

- tested on Java 8, 11, 17, and 21
- runs on Spring-Boot 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1 and 3.2 (and of course without Spring-Boot)
- tested on Java 17 and 21
- runs on Spring-Boot 3.x (and of course without Spring-Boot)
- runs on Elasticsearch version 7.5.x - 8.13.x
- runs on Opensearch version 1.x and 2.x
- highly configurable (e.g. location(s) of your migration files, migration files format pattern)
Expand All @@ -33,6 +33,7 @@ Successful executed migration scripts will not be executed again!

| Compatibility | Spring Boot | Elasticsearch | Opensearch |
|----------------------------------|--------------------------------------------------|----------------------|------------|
| elasticsearch-evolution >= 0.6.0 | 3.x | 7.5.x - 8.13.x | 1.x - 2.x |
| elasticsearch-evolution >= 0.4.2 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 | 7.5.x - 8.13.x | 1.x - 2.x |
| elasticsearch-evolution >= 0.4.0 | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7 | 7.5.x - 8.6.x | 1.x - 2.x |
| elasticsearch-evolution 0.3.x | 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7 | 7.5.x - 7.17.x | |
Expand All @@ -48,7 +49,7 @@ First add the latest version of Elasticsearch-Evolution spring boot starter as a
<dependency>
<groupId>com.senacor.elasticsearch.evolution</groupId>
<artifactId>spring-boot-starter-elasticsearch-evolution</artifactId>
<version>0.5.2</version>
<version>0.6.0</version>
</dependency>
```

Expand All @@ -72,7 +73,7 @@ First add the latest version of Elasticsearch-Evolution core as a dependency:
<dependency>
<groupId>com.senacor.elasticsearch.evolution</groupId>
<artifactId>elasticsearch-evolution-core</artifactId>
<version>0.5.2</version>
<version>0.6.0</version>
</dependency>
```

Expand Down Expand Up @@ -192,6 +193,8 @@ Elasticsearch-Evolution can be configured to your needs:
- **baselineVersion** (default=1.0): Version to use as a baseline. versions lower than it will not be applied.
- **lineSeparator** (default=\n): Line separator, used only temporary between reading raw migration file line-by-line and parsing it later. Only needed for backward compatibility / checksum stability! Should be one of `\n`, `\r` or `\r\n`
- **outOfOrder** (default=false): Allows migrations to be run "out of order". If you already have versions 1.0 and 3.0 applied, and now a version 2.0 is found, it will be applied too instead of being rejected.
- **trimTrailingNewlineInMigrations** (default=false): Whether to remove a trailing newline in migration scripts. Only
needed for backward compatibility / checksum stability!

### 5.1 Spring Boot

Expand Down Expand Up @@ -219,14 +222,6 @@ spring.elasticsearch.username=my-user-name
spring.elasticsearch.password=my-secret-pw
```

##### 5.1.1.2 spring boot < 2.7
NOTE: these config properties are deprecated since spring boot 2.6 and may be removed in 2.7! See spring-boot 2.6 [release notes](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#elasticsearch-property-consolidation).
```properties
spring.elasticsearch.rest.uris[0]=https://example.com:9200
spring.elasticsearch.rest.username=my-user-name
spring.elasticsearch.rest.password=my-secret-pw
```

#### 5.1.2 Customize Elasticsearch-Evolutions AutoConfiguration

##### 5.1.2.1 Custom RestClient
Expand Down Expand Up @@ -286,6 +281,12 @@ ElasticsearchEvolution.configure()

## 6 changelog

### v0.6.0

- Added option to trim a trailing newline in migration scripts (fixes [#298](https://github.com/senacor/elasticsearch-evolution/issues/298)). NOTE: This option is only needed for backward compatibility / checksum stability!
- The minimum supported Java version is now 17.
- Drop spring boot 2 compatibility. Further versions may run on spring boot 2, but it is not tested anymore.

### v0.5.2

- bugfix ([#293](https://github.com/senacor/elasticsearch-evolution/issues/293)): trailing newlines will no longer be removed from migration scripts.
Expand Down
7 changes: 6 additions & 1 deletion elasticsearch-evolution-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.senacor.elasticsearch.evolution</groupId>
<artifactId>elasticsearch-evolution-parent</artifactId>
<version>0.5.2</version>
<version>0.6.0</version>
<relativePath>../</relativePath>
</parent>
<artifactId>elasticsearch-evolution-core</artifactId>
Expand Down Expand Up @@ -66,6 +66,11 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public int migrate() throws MigrationException {
logger.info("reading migration scripts...");
Collection<RawMigrationScript> rawMigrationScripts = migrationScriptReader.read();
if (rawMigrationScripts.size() > getConfig().getHistoryMaxQuerySize()) {
throw new MigrationException(String.format("configured historyMaxQuerySize of '%s' is to low for the number of migration scripts of '%s'",
throw new MigrationException("configured historyMaxQuerySize of '%s' is to low for the number of migration scripts of '%s'".formatted(
getConfig().getHistoryMaxQuerySize(), rawMigrationScripts.size()));
}

Expand Down Expand Up @@ -151,7 +151,8 @@ protected MigrationScriptReader createMigrationScriptReader() {
getConfig().getEncoding(),
getConfig().getEsMigrationPrefix(),
getConfig().getEsMigrationSuffixes(),
getConfig().getLineSeparator());
getConfig().getLineSeparator(),
getConfig().isTrimTrailingNewlineInMigrations());
}

protected HistoryRepository createHistoryRepository() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public class ElasticsearchEvolutionConfig {

/**
* Line separator, used only temporary between reading raw migration file line-by-line and parsing it later.
* Only needed for backward compatibility / checksum stability!
* <p>
* NOTE: Only needed for backward compatibility / checksum stability!
* <p>
* Should be one of
* - '\n' (LF - Linux/Unix/OS X)
Expand Down Expand Up @@ -103,6 +104,13 @@ public class ElasticsearchEvolutionConfig {
*/
private boolean validateOnMigrate = true;

/**
* Whether to remove a trailing newline in migration scripts.
* <p>
* NOTE: This is only needed for backward compatibility / checksum stability!
*/
private boolean trimTrailingNewlineInMigrations = false;

/**
* version to use as a baseline.
* The baseline version will be the first one applied, the versions below will be ignored.
Expand Down Expand Up @@ -295,6 +303,15 @@ public ElasticsearchEvolutionConfig setValidateOnMigrate(boolean validateOnMigra
return this;
}

public boolean isTrimTrailingNewlineInMigrations() {
return trimTrailingNewlineInMigrations;
}

public ElasticsearchEvolutionConfig setTrimTrailingNewlineInMigrations(boolean trimTrailingNewlineInMigrations) {
this.trimTrailingNewlineInMigrations = trimTrailingNewlineInMigrations;
return this;
}

public String getBaselineVersion() {
return baselineVersion;
}
Expand Down Expand Up @@ -330,6 +347,7 @@ public String toString() {
", historyIndex='" + historyIndex + '\'' +
", historyMaxQuerySize=" + historyMaxQuerySize +
", validateOnMigrate=" + validateOnMigrate +
", trimTrailingNewlineInMigrations=" + trimTrailingNewlineInMigrations +
", baselineVersion='" + baselineVersion + '\'' +
", outOfOrder='" + outOfOrder + '\'' +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void saveOrUpdate(MigrationScriptProtocol migrationScriptProtocol) throws
}
validateHttpStatusIs2xx(res, "saveOrUpdate");
} catch (IOException e) {
throw new MigrationException(String.format("saveOrUpdate of '%s' failed!", migrationScriptProtocol), e);
throw new MigrationException("saveOrUpdate of '%s' failed!".formatted(migrationScriptProtocol), e);
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ private void validateHttpStatusIs2xx(Response response, String description) thro

void validateHttpStatusIs2xx(int statusCode, String description) throws MigrationException {
if (isNotStatusCode2xx(statusCode)) {
throw new MigrationException(String.format("%s - response status is not OK: %s", description, statusCode));
throw new MigrationException("%s - response status is not OK: %s".formatted(description, statusCode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ ExecutionResult executeScript(ParsedMigrationScript scriptToExecute) {
if (statusCode >= 200 && statusCode < 300) {
success = true;
} else {
error = Optional.of(new MigrationException(String.format(
"execution of script '%s' failed with HTTP status %s: %s",
error = Optional.of(new MigrationException(
"execution of script '%s' failed with HTTP status %s: %s".formatted(
scriptToExecute.getFileNameInfo(),
statusCode,
response.toString())));
}
} catch (RuntimeException | IOException e) {
error = Optional.of(new MigrationException(String.format("execution of script '%s' failed", scriptToExecute.getFileNameInfo()), e));
error = Optional.of(new MigrationException("execution of script '%s' failed".formatted(scriptToExecute.getFileNameInfo()), e));
}

return new ExecutionResult(
Expand Down Expand Up @@ -199,10 +199,12 @@ List<ParsedMigrationScript> getPendingScriptsToBeExecuted(Collection<ParsedMigra
for (MigrationScriptProtocol protocol : history) {
final ParsedMigrationScript parsedMigrationScript = scriptsInFilesystemMap.get(protocol.getVersion());
if (null == parsedMigrationScript) {
logger.warn("there are less migration scripts than already executed history entries! " +
"You should never delete migration scripts you have already executed. " +
"Or maybe you have to cleanup the Elasticsearch-Evolution history index manually! " +
"Already executed history version {} is not present in migration files", protocol.getVersion());
logger.warn("""
there are less migration scripts than already executed history entries! \
You should never delete migration scripts you have already executed. \
Or maybe you have to cleanup the Elasticsearch-Evolution history index manually! \
Already executed history version {} is not present in migration files\
""", protocol.getVersion());
} else {
validateOnMigrateIfEnabled(protocol, parsedMigrationScript);

Expand All @@ -217,19 +219,23 @@ List<ParsedMigrationScript> getPendingScriptsToBeExecuted(Collection<ParsedMigra
// do some checks
MigrationScriptProtocol protocol = history.get(i);
if (orderedScripts.size() <= i) {
logger.warn("there are less migration scripts than already executed history entries! " +
"You should never delete migration scripts you have already executed. " +
"Or maybe you have to cleanup the Elasticsearch-Evolution history index manually! " +
"history version at position {} is {}", i, protocol.getVersion());
logger.warn("""
there are less migration scripts than already executed history entries! \
You should never delete migration scripts you have already executed. \
Or maybe you have to cleanup the Elasticsearch-Evolution history index manually! \
history version at position {} is {}\
""", i, protocol.getVersion());
break;
}
ParsedMigrationScript parsedMigrationScript = orderedScripts.get(i);
if (!protocol.getVersion().equals(parsedMigrationScript.getFileNameInfo().getVersion())) {
throw new MigrationException(String.format(
"The logged execution in the Elasticsearch-Evolution history index at position %s " +
"is version %s and in the same position in the given migration scripts is version %s! " +
"Out of order execution is not supported. Or maybe you have added new migration scripts " +
"in between or have to cleanup the Elasticsearch-Evolution history index manually",
throw new MigrationException((
"""
The logged execution in the Elasticsearch-Evolution history index at position %s \
is version %s and in the same position in the given migration scripts is version %s! \
Out of order execution is not supported. Or maybe you have added new migration scripts \
in between or have to cleanup the Elasticsearch-Evolution history index manually\
""").formatted(
i, protocol.getVersion(), parsedMigrationScript.getFileNameInfo().getVersion()));
}
validateOnMigrateIfEnabled(protocol, parsedMigrationScript);
Expand All @@ -246,10 +252,12 @@ List<ParsedMigrationScript> getPendingScriptsToBeExecuted(Collection<ParsedMigra
private void validateOnMigrateIfEnabled(MigrationScriptProtocol protocol, ParsedMigrationScript parsedMigrationScript) {
// failed scripts can be edited and retried, but successfully executed scripts may not be modified afterward
if (validateOnMigrate && protocol.isSuccess() && protocol.getChecksum() != parsedMigrationScript.getChecksum()) {
throw new MigrationException(String.format(
"The logged execution for the migration script version %s (%s) " +
"has a different checksum from the given migration script! " +
"Modifying already-executed scripts is not supported.",
throw new MigrationException((
"""
The logged execution for the migration script version %s (%s) \
has a different checksum from the given migration script! \
Modifying already-executed scripts is not supported.\
""").formatted(
protocol.getVersion(), protocol.getScriptName()));
}
}
Expand Down
Loading

0 comments on commit acdb363

Please sign in to comment.