From 3ea3e9faeab8f1dd8197cda2a66c537f8c7de0f8 Mon Sep 17 00:00:00 2001 From: Alex Brackx Date: Fri, 4 Oct 2024 09:34:38 -0600 Subject: [PATCH 1/3] [DAT-18785] Override getDatabaseProductVersion() to find actual Mongo version --- .../ext/mongodb/database/MongoLiquibaseDatabase.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java b/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java index 495dcc10..2c22113c 100644 --- a/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java +++ b/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java @@ -33,6 +33,7 @@ import liquibase.nosql.database.AbstractNoSqlDatabase; import lombok.NoArgsConstructor; import lombok.Setter; +import org.bson.Document; import static liquibase.nosql.executor.NoSqlExecutor.EXECUTOR_NAME; @@ -74,6 +75,12 @@ public String getDatabaseProductName() { return MONGODB_PRODUCT_NAME; } + @Override + public String getDatabaseProductVersion() { + Document document = getMongoDatabase().runCommand(new Document("buildInfo",1)); + return document.getString("version"); + } + /** * Returns an all-lower-case short name of the product. Used for end-user selecting of database type * such as the DBMS precondition. From 1881378b913cec199c52340beb20857eddf5b509 Mon Sep 17 00:00:00 2001 From: Alex Brackx Date: Fri, 4 Oct 2024 09:44:08 -0600 Subject: [PATCH 2/3] [DAT-18785] Handle null case --- .../liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java b/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java index 2c22113c..75d7eeb8 100644 --- a/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java +++ b/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java @@ -78,7 +78,7 @@ public String getDatabaseProductName() { @Override public String getDatabaseProductVersion() { Document document = getMongoDatabase().runCommand(new Document("buildInfo",1)); - return document.getString("version"); + return document.getString("version") != null ? document.getString("version") : "Unknown"; } /** From f81d6a72af246ed112254c88d65fb79438550863 Mon Sep 17 00:00:00 2001 From: Alex Brackx Date: Fri, 4 Oct 2024 10:01:27 -0600 Subject: [PATCH 3/3] [DAT-18785] Fix test setup, handle case when connection isn't established. --- .../ext/mongodb/database/MongoLiquibaseDatabase.java | 11 +++++++++-- .../ext/mongodb/change/AbstractMongoChangeTest.java | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java b/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java index 75d7eeb8..5f2565dd 100644 --- a/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java +++ b/src/main/java/liquibase/ext/mongodb/database/MongoLiquibaseDatabase.java @@ -77,8 +77,15 @@ public String getDatabaseProductName() { @Override public String getDatabaseProductVersion() { - Document document = getMongoDatabase().runCommand(new Document("buildInfo",1)); - return document.getString("version") != null ? document.getString("version") : "Unknown"; + String unknownVersion = "Unknown"; + try { + Document document = getMongoDatabase().runCommand(new Document("buildInfo", 1)); + String version = document.getString("version"); + return version != null ? version : unknownVersion; + } catch (Exception unableToDetermineVersion) { + Scope.getCurrentScope().getLog(getClass()).warning("Unable to determine mongo database version!", unableToDetermineVersion); + return unknownVersion; + } } /** diff --git a/src/test/java/liquibase/ext/mongodb/change/AbstractMongoChangeTest.java b/src/test/java/liquibase/ext/mongodb/change/AbstractMongoChangeTest.java index 57f61bce..e56c9bd6 100644 --- a/src/test/java/liquibase/ext/mongodb/change/AbstractMongoChangeTest.java +++ b/src/test/java/liquibase/ext/mongodb/change/AbstractMongoChangeTest.java @@ -30,6 +30,11 @@ public abstract class AbstractMongoChangeTest { @BeforeEach void setUp() { - database = new MongoLiquibaseDatabase(); + database = new MongoLiquibaseDatabase() { + @Override + public String getDatabaseProductVersion() { + return "test"; + } + }; } }