From d4eebd0d0521b348d611647a9163c69b02ccf40b Mon Sep 17 00:00:00 2001 From: Mazen Khalil Date: Wed, 1 Feb 2023 12:50:31 +0100 Subject: [PATCH] Avoid creating 3 Liquibase instances for startup operations --- .../runtime/LiquibaseMongodbRecorder.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbRecorder.java b/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbRecorder.java index e27c2caaffeba..7b6315c66961c 100644 --- a/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbRecorder.java +++ b/extensions/liquibase-mongodb/runtime/src/main/java/io/quarkus/liquibase/mongodb/runtime/LiquibaseMongodbRecorder.java @@ -47,18 +47,21 @@ public void doStartActions() { for (InstanceHandle liquibaseFactoryHandle : liquibaseFactoryInstance.handles()) { try { LiquibaseMongodbFactory liquibaseFactory = liquibaseFactoryHandle.get(); - if (liquibaseFactory.getConfiguration().cleanAtStart) { - try (Liquibase liquibase = liquibaseFactory.createLiquibase()) { + + if (!liquibaseFactory.getConfiguration().cleanAtStart + && !liquibaseFactory.getConfiguration().migrateAtStart) { + // Don't initialize if no clean or migration required at start + return; + } + + try (Liquibase liquibase = liquibaseFactory.createLiquibase()) { + if (liquibaseFactory.getConfiguration().cleanAtStart) { liquibase.dropAll(); } - } - if (liquibaseFactory.getConfiguration().migrateAtStart) { - if (liquibaseFactory.getConfiguration().validateOnMigrate) { - try (Liquibase liquibase = liquibaseFactory.createLiquibase()) { + if (liquibaseFactory.getConfiguration().migrateAtStart) { + if (liquibaseFactory.getConfiguration().validateOnMigrate) { liquibase.validate(); } - } - try (Liquibase liquibase = liquibaseFactory.createLiquibase()) { liquibase.update(liquibaseFactory.createContexts(), liquibaseFactory.createLabels()); } }