RED-2171: Fixed rollback in migration because of exit 0

This commit is contained in:
deiflaender 2021-11-25 10:30:36 +01:00
parent ab2a66eab0
commit 2a1a65b903
2 changed files with 35 additions and 14 deletions

View File

@ -162,20 +162,6 @@ public class MigrationService {
private final StorageService storageService;
private final FileManagementServiceSettings settings;
private final ApplicationContext ctx;
@Transactional
@EventListener(ApplicationReadyEvent.class)
public void runMigration() {
if (settings.isMigrateOnly()) {
migrate();
System.exit(SpringApplication.exit(ctx, () -> 0));
}
}
@SneakyThrows
@Transactional

View File

@ -0,0 +1,35 @@
package com.iqser.red.service.peristence.v1.server.migration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
public class MigrationStarterService {
// This is a seperate class because exit 0 causes rollback if the method is @Transactional.
private final MigrationService migrationService;
private final FileManagementServiceSettings settings;
private final ApplicationContext ctx;
@EventListener(ApplicationReadyEvent.class)
public void runMigration() {
if (settings.isMigrateOnly()) {
migrationService.migrate();
System.exit(SpringApplication.exit(ctx, () -> 0));
}
}
}