Skip to content

Commit

Permalink
Merge pull request #570 from liquibase/DAT-18785
Browse files Browse the repository at this point in the history
Override getDatabaseProductVersion() to find actual Mongo version (DAT-18785)
  • Loading branch information
abrackx authored Oct 7, 2024
2 parents 1d324b8 + f81d6a7 commit f6123ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -74,6 +75,19 @@ public String getDatabaseProductName() {
return MONGODB_PRODUCT_NAME;
}

@Override
public String getDatabaseProductVersion() {
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;
}
}

/**
* Returns an all-lower-case short name of the product. Used for end-user selecting of database type
* such as the DBMS precondition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public abstract class AbstractMongoChangeTest {

@BeforeEach
void setUp() {
database = new MongoLiquibaseDatabase();
database = new MongoLiquibaseDatabase() {
@Override
public String getDatabaseProductVersion() {
return "test";
}
};
}
}

0 comments on commit f6123ed

Please sign in to comment.