diff --git a/core/src/main/java/google/registry/tools/RegistryCli.java b/core/src/main/java/google/registry/tools/RegistryCli.java index 78b741b76..00668026a 100644 --- a/core/src/main/java/google/registry/tools/RegistryCli.java +++ b/core/src/main/java/google/registry/tools/RegistryCli.java @@ -256,20 +256,24 @@ final class RegistryCli implements AutoCloseable, CommandRunner { options, new ByteArrayInputStream(component.googleCredentialJson().getBytes(UTF_8))); } installer.install(options); + + // Database setup -- we also only ever do this if "installer" is null, just so that it's + // only done once. + + // Ensure that all entity classes are loaded before command code runs. + ObjectifyService.initOfy(); + // Make sure we start the command with a clean cache, so that any previous command won't + // interfere with this one. + ofyTm().clearSessionCache(); + + // Enable Cloud SQL for command that needs remote API as they will very likely use + // Cloud SQL after the database migration. Note that the DB password is stored in Datastore + // and it is already initialized above. + TransactionManagerFactory.setJpaTm( + () -> component.nomulusToolJpaTransactionManager().get()); + TransactionManagerFactory.setReplicaJpaTm( + () -> component.nomulusToolReplicaJpaTransactionManager().get()); } - - // Ensure that all entity classes are loaded before command code runs. - ObjectifyService.initOfy(); - // Make sure we start the command with a clean cache, so that any previous command won't - // interfere with this one. - ofyTm().clearSessionCache(); - - // Enable Cloud SQL for command that needs remote API as they will very likely use - // Cloud SQL after the database migration. Note that the DB password is stored in Datastore - // and it is already initialized above. - TransactionManagerFactory.setJpaTm(() -> component.nomulusToolJpaTransactionManager().get()); - TransactionManagerFactory.setReplicaJpaTm( - () -> component.nomulusToolReplicaJpaTransactionManager().get()); } command.run();