Merge pull request #1463 from Athou/renovate/com.manticore-projects.tools-h2migrationtool-1.x

Update dependency com.manticore-projects.tools:h2migrationtool to v1.6
This commit is contained in:
Jérémie Panzer
2024-06-28 07:21:29 +02:00
committed by GitHub
2 changed files with 7 additions and 4 deletions

View File

@@ -403,7 +403,7 @@
<dependency>
<groupId>com.manticore-projects.tools</groupId>
<artifactId>h2migrationtool</artifactId>
<version>1.4</version>
<version>1.6</version>
</dependency>
<dependency>

View File

@@ -17,6 +17,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class H2MigrationService {
private static final String H2_FILE_SUFFIX = ".mv.db";
public void migrateIfNeeded(Path path, String user, String password) {
if (Files.notExists(path)) {
return;
@@ -54,9 +56,10 @@ public class H2MigrationService {
private void migrate(Path path, String user, String password, String fromVersion, String toVersion) throws Exception {
log.info("migrating H2 database at {} from format {} to format {}", path, fromVersion, toVersion);
Path scriptPath = path.resolveSibling("script-" + System.currentTimeMillis() + ".sql");
Path newVersionPath = path.resolveSibling(path.getFileName() + "." + getPatchVersion(toVersion) + ".mv.db");
Path oldVersionBackupPath = path.resolveSibling(path.getFileName() + "." + getPatchVersion(fromVersion) + ".backup");
Path scriptPath = path.resolveSibling("script-%d.sql".formatted(System.currentTimeMillis()));
Path newVersionPath = path.resolveSibling("%s.%s%s".formatted(StringUtils.removeEnd(path.getFileName().toString(), H2_FILE_SUFFIX),
getPatchVersion(toVersion), H2_FILE_SUFFIX));
Path oldVersionBackupPath = path.resolveSibling("%s.%s.backup".formatted(path.getFileName(), getPatchVersion(fromVersion)));
Files.deleteIfExists(scriptPath);
Files.deleteIfExists(newVersionPath);