Skip to content

Commit

Permalink
ApplicationService: Apply migrations before starting services
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Oct 20, 2024
1 parent c216cca commit ff2dca8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.application;

import bisq.application.migration.MigrationService;
import bisq.common.application.ApplicationVersion;
import bisq.common.application.DevMode;
import bisq.common.application.OptionUtils;
Expand Down Expand Up @@ -124,6 +125,7 @@ public Config(Path baseDir,
protected final Config config;
@Getter
protected final PersistenceService persistenceService;
private final MigrationService migrationService;
@SuppressWarnings("FieldCanBeLocal") // Pin it so that it does not get GC'ed
private final MemoryReport memoryReport;
private FileLock instanceLock;
Expand Down Expand Up @@ -185,6 +187,7 @@ public ApplicationService(String configFileName, String[] args) {

String absoluteDataDirPath = dataDir.toAbsolutePath().toString();
persistenceService = new PersistenceService(absoluteDataDirPath);
migrationService = new MigrationService(dataDir);
}

private void checkInstanceLock() {
Expand All @@ -207,7 +210,9 @@ public CompletableFuture<Boolean> readAllPersisted() {
return persistenceService.readAllPersisted();
}

public abstract CompletableFuture<Boolean> initialize();
public CompletableFuture<Boolean> initialize() {
return migrationService.runMigrations();
}

public abstract CompletableFuture<Boolean> shutdown();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ public DesktopApplicationService(String[] args, ShutDownHandler shutDownHandler)

@Override
public CompletableFuture<Boolean> initialize() {
return securityService.initialize()
return super.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> {
setState(State.INITIALIZE_NETWORK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public OracleNodeApplicationService(String[] args) {

@Override
public CompletableFuture<Boolean> initialize() {
return securityService.initialize()
return super.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> networkService.initialize())
.thenCompose(result -> identityService.initialize())
.thenCompose(result -> bondedRolesService.initialize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public RestApiApplicationService(String[] args) {

@Override
public CompletableFuture<Boolean> initialize() {
return securityService.initialize()
return super.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> {
setState(State.INITIALIZE_NETWORK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public SeedNodeApplicationService(String[] args) {

@Override
public CompletableFuture<Boolean> initialize() {
return securityService.initialize()
return super.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> networkService.initialize())
.thenCompose(result -> identityService.initialize())
.thenCompose(result -> bondedRolesService.initialize())
Expand Down

0 comments on commit ff2dca8

Please sign in to comment.