Skip to content

Commit

Permalink
migration: Pass migrations to Migrator in constructor
Browse files Browse the repository at this point in the history
The migrations are hard-coded in the Migrator making it impossible to
add test where some migrations fail.
  • Loading branch information
alvasw committed Nov 4, 2024
1 parent a726329 commit da6178d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import bisq.common.application.ApplicationVersion;
import bisq.common.application.Service;
import bisq.common.platform.Version;
import bisq.evolution.migration.migrations.Migration;
import bisq.evolution.migration.migrations.MigrationsForV2_1_2;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class MigrationService implements Service {
Expand All @@ -26,7 +29,8 @@ public CompletableFuture<Boolean> initialize() {
Version appVersion = ApplicationVersion.getVersion();

if (dataDirVersion.below(appVersion)) {
Migrator migrator = new Migrator(appVersion, dataDir);
List<Migration> allMigrations = List.of(new MigrationsForV2_1_2());
Migrator migrator = new Migrator(appVersion, dataDir, allMigrations);
migrator.migrate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import bisq.common.platform.Version;
import bisq.evolution.migration.migrations.Migration;
import bisq.evolution.migration.migrations.MigrationFailedException;
import bisq.evolution.migration.migrations.MigrationsForV2_1_2;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
Expand All @@ -18,10 +17,10 @@ public class Migrator {
private final Path dataDir;
private final List<Migration> allMigrations;

public Migrator(Version appVersion, Path dataDir) {
public Migrator(Version appVersion, Path dataDir, List<Migration> allMigrations) {
this.appVersion = appVersion;
this.dataDir = dataDir;
this.allMigrations = List.of(new MigrationsForV2_1_2());
this.allMigrations = allMigrations;
}

public void migrate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;

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

Expand All @@ -19,7 +20,7 @@ void migrationSuccess(@TempDir Path dataDir) throws IOException {
Files.writeString(versionFilePath, dataDirVersion.toString());

Version appVersion = ApplicationVersion.getVersion();
Migrator migrator = new Migrator(appVersion, dataDir);
Migrator migrator = new Migrator(appVersion, dataDir, Collections.emptyList());

migrator.migrate();

Expand Down

0 comments on commit da6178d

Please sign in to comment.