forked from bisq-network/bisq2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: Write new data directory version if all migrations succeed
Migrations are applied if the app version number is higher than the data directory version number. Currently, the only existing migration writes the new version number to the data directory after applying its migration. Moving the data directory version write to the Migrator makes the code future-proof when we have multiple migrations.
- Loading branch information
Showing
4 changed files
with
54 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
application/src/test/java/bisq/application/migration/MigratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package bisq.application.migration; | ||
|
||
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 MigratorTest { | ||
@Test | ||
void migrationSuccess(@TempDir Path dataDir) throws IOException { | ||
Path versionFilePath = dataDir.resolve("version"); | ||
Version dataDirVersion = new Version("2.1.0"); | ||
Files.writeString(versionFilePath, dataDirVersion.toString()); | ||
|
||
Version appVersion = ApplicationVersion.getVersion(); | ||
Migrator migrator = new Migrator(appVersion, dataDir); | ||
|
||
migrator.migrate(); | ||
|
||
String readVersion = Files.readString(dataDir.resolve("version")); | ||
assertThat(readVersion).isEqualTo(appVersion.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters