Skip to content

Commit

Permalink
Implement migration for v2.1.2
Browse files Browse the repository at this point in the history
This migration writes the current version number to the data directory.
The remaining migrations depend on another open PR and will follow soon.
  • Loading branch information
alvasw committed Oct 20, 2024
1 parent 9d8187d commit c216cca
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package bisq.application.migration;

import bisq.application.migration.migrations.Migration;
import bisq.application.migration.migrations.MigrationsForV2_1_2;
import bisq.common.platform.Version;
import lombok.extern.slf4j.Slf4j;

import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

@Slf4j
Expand All @@ -17,7 +17,7 @@ public class Migrator {
public Migrator(Version appVersion, Path dataDir) {
this.appVersion = appVersion;
this.dataDir = dataDir;
this.allMigrations = Collections.emptyList();
this.allMigrations = List.of(new MigrationsForV2_1_2());
}

public void migrate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package bisq.application.migration.migrations;

public class MigrationFailedException extends RuntimeException {
public MigrationFailedException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package bisq.application.migration.migrations;

import bisq.common.application.ApplicationVersion;
import bisq.common.platform.Version;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class MigrationsForV2_1_2 implements Migration {

@Override
public void run(Path dataDir) {
try {
Path versionFilePath = dataDir.resolve("version");
Files.writeString(versionFilePath, ApplicationVersion.getVersion().toString());
} catch (IOException e) {
throw new MigrationFailedException(e);
}
}

@Override
public Version getVersion() {
return new Version("2.1.2");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package bisq.application.migration.migrations;

import bisq.common.application.ApplicationVersion;
import bisq.common.platform.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;

public class MigrationsForV2_1_2Tests {
private final MigrationsForV2_1_2 migrationsForV212 = new MigrationsForV2_1_2();

@Test
void migrationTest(@TempDir Path dataDir) throws IOException {
Version version = migrationsForV212.getVersion();
Version expectedVersion = new Version("2.1.2");
assertThat(version).isEqualTo(expectedVersion);

migrationsForV212.run(dataDir);
String readVersion = Files.readString(dataDir.resolve("version"));
assertThat(readVersion)
.isEqualTo(ApplicationVersion.getVersion().toString());
}
}

0 comments on commit c216cca

Please sign in to comment.