Skip to content

Commit

Permalink
Merge branch 'main' into LIQU-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jandroav authored Aug 27, 2024
2 parents f1833a6 + 056215d commit f0e8f22
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 38 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@ name: Build and Test

on:
workflow_dispatch:
pull_request:
pull_request_target:
types:
- opened
- reopened
- synchronize

permissions:
contents: write
pull-requests: write

jobs:

authorize:
environment: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository && 'external' || 'internal' }}
runs-on: ubuntu-latest
steps:
- run: true

build-test:
needs: authorize
uses: liquibase/build-logic/.github/workflows/[email protected]
secrets: inherit

Expand Down
49 changes: 49 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
Liquibase MongoDB Extension Changelog
===========================================
#### 4.29.1

### Changes

## Security Driver and Other Updates
(#549) build(deps): bump org.mongodb:mongodb-driver-sync from 5.1.2 to 5.1.3 @dependabot
(#547) build(deps-dev): bump org.slf4j:slf4j-simple from 2.0.13 to 2.0.14 @dependabot
(#548) build(deps-dev): bump org.slf4j:slf4j-api from 2.0.13 to 2.0.14 @dependabot

**Full Changelog**: liquibase-mongodb-v4.29.0...liquibase-mongodb-4.29.1

#### v4.29.0

### Changes
(#540) build(deps): bump org.mongodb:mongodb-driver-sync from 5.1.0 to 5.1.1 @dependabot
(#539) build(deps): bump liquibase/build-logic from 0.7.7 to 0.7.8 @dependabot

## Bug Fixes
(#543) [DAT-17886] fix dependency causing incorrect result for Pro 'connect' command @KushnirykOleh

## Security Driver and Other Updates
(#542) build(deps): bump org.mongodb:mongodb-driver-sync from 5.1.1 to 5.1.2 @dependabot

**Full Changelog**: liquibase-mongodb-v4.28.0...liquibase-mongodb-4.29.0

#### v4.28.0

### Changes
(#490) DAT-15853 DevOps :: Deprecate Snyk and replace with GHAS @jandroav
(#467) DAT-16149 DevOps :: Extensions Release Failing @jandroav
(#464) Update codeql.yml @jandroav
(#463) Delete .github/workflows/snyk-nightly.yml @jandroav
(#460) DAT-16080 DevOps :: Extension Nightly Builds Failing @jandroav

## New Features
(#517) [DAT-16600] Implement method to send ping signal to DB server for connect command @vitaliimak
(#534) [DAT-15397] Move release notes into separate file @vitaliimak
(#518) DAT-17414 upgrade docker compose to v2 @jnewton03
(#503) [DAT-15502] Add version matrix to integration and harness tests @vitaliimak
(#504) DAT-15502. added the compoud wildcard index(new MongoDB 7 feature) to createIndex test @PavloTytarchuk
(#502) [DAT-16074] Implement user friendly message for if required dependencies are not available @vitaliimak
(#510) DAT-15503. added mongodb atlas 7 to the test.yml @PavloTytarchuk
(#437) DAT 15505 Liquibase Extensions Parent POM @jandroav

## Bug Fixes
(#538) [DAT-17036] Fix incorrect error @vitaliimak
(#522) [DAT-17365] Release lock even if update fails on timeout @vitaliimak

**Full Changelog**: liquibase-mongodb-v4.24.0...liquibase-mongodb-4.28.0

#### 4.24.0
* Support for Liquibase 4.24.0
Expand Down
26 changes: 7 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-parent-pom</artifactId>
<version>0.3.6</version> <!-- Replace with the desired version -->
<version>0.4.2</version> <!-- Replace with the desired version -->
</parent>

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<packaging>jar</packaging>
<version>4.29.0-SNAPSHOT</version>
<version>4.30.0-SNAPSHOT</version>
<name>Liquibase MongoDB Extension</name>
<description>Liquibase Extension for MongoDB</description>
<url>http://www.liquibase.org</url>
Expand All @@ -23,11 +23,11 @@
</developers>

<properties>
<liquibase.version>4.28.0</liquibase.version>
<liquibase.version>4.29.1</liquibase.version>
<jupiter.surefire.version>1.3.2</jupiter.surefire.version>
<mockito-core.version>4.11.0</mockito-core.version>
<mockito-junit-jupiter.version>4.8.0</mockito-junit-jupiter.version>
<mongodb-driver.version>5.1.2</mongodb-driver.version>
<mongodb-driver.version>5.1.3</mongodb-driver.version>
<license.licenseName>mastercard_apache_license</license.licenseName>
<license.licenseResolver>${project.baseUri}/src/license</license.licenseResolver>
<license.inceptionYear>2019</license.inceptionYear>
Expand All @@ -36,6 +36,7 @@
<license-maven-plugin.version>2.0.0</license-maven-plugin.version>
<jackson-core.version>2.15.3</jackson-core.version>
<db.connection.uri>mongodb://localhost:27017/test_db?socketTimeoutMS=100&amp;connectTimeoutMS=100&amp;serverSelectionTimeoutMS=100</db.connection.uri>
<liquibase-test-harness.version>1.0.10</liquibase-test-harness.version>
</properties>

<scm>
Expand All @@ -52,30 +53,17 @@
<version>${mongodb-driver.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.athaydes</groupId>
<artifactId>spock-reports</artifactId>
<version>2.3.2-groovy-3.0</version>
<scope>test</scope>
<!-- this avoids affecting your version of Groovy/Spock -->
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- // if you don't already have slf4j-api and an implementation of it in the classpath, add this! -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ public Boolean getSupportsValidator() {
@Override
public void checkDatabaseConnection() throws DatabaseException {
MongoConnection.showErrorMessageIfSomeRequiredDependenciesAreNotPresent(true);
MongoLiquibaseDatabaseUtil.sendPingSignal(getConnection());
MongoLiquibaseDatabaseUtil.checkDatabaseAccessibility((MongoConnection) getConnection());
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package liquibase.ext.mongodb.database;

import com.mongodb.MongoException;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import liquibase.database.DatabaseConnection;
import liquibase.exception.DatabaseException;
import org.bson.BsonDocument;
import org.bson.BsonInt64;
import org.bson.conversions.Bson;

import static liquibase.ext.mongodb.database.MongoLiquibaseDatabase.ADMIN_DATABASE_NAME;

public class MongoLiquibaseDatabaseUtil {
private MongoLiquibaseDatabaseUtil() {
}

public static void sendPingSignal(DatabaseConnection connection) throws DatabaseException {
public static void checkDatabaseAccessibility(MongoConnection connection) throws DatabaseException {
try {
if (connection instanceof MongoConnection) {
MongoClient mongoClient = ((MongoConnection) connection).getMongoClient();
Bson command = new BsonDocument("ping", new BsonInt64(1));
MongoDatabase adminDb = mongoClient.getDatabase(ADMIN_DATABASE_NAME);
adminDb.runCommand(command);
String urlDatabaseName = connection.getConnectionString().getDatabase();
for (String dbName : connection.getMongoClient().listDatabaseNames()) {
if (dbName.equals(urlDatabaseName)) {
return;
}
}
throw new DatabaseException();
} catch (MongoException e) {
throw new DatabaseException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
package liquibase.ext.mongodb.database;

import com.mongodb.ConnectionString;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoIterable;
import liquibase.CatalogAndSchema;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.DatabaseFactory;
import liquibase.database.ObjectQuotingStrategy;
import liquibase.ext.mongodb.configuration.MongoConfiguration;
import liquibase.exception.DatabaseException;
import lombok.SneakyThrows;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static java.lang.Boolean.FALSE;
import static liquibase.servicelocator.PrioritizedService.PRIORITY_DATABASE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
class MongoLiquibaseDatabaseTest {

@Mock
protected MongoConnection connectionMock;

@Mock
protected MongoClient clientMock;

@Mock
protected MongoIterable<String> iterableMock;

@Mock
protected MongoCursor<String> mongoCursor;

protected MongoLiquibaseDatabase database;

@SneakyThrows
Expand Down Expand Up @@ -121,4 +141,18 @@ void getDefaultSchema() {
.containsExactly("catalog1", "catalog1");
}

@SneakyThrows
@Test
void checkDatabaseConnection() {
database.setConnection(connectionMock);
ConnectionString connectionString = new ConnectionString("mongodb://lbuser:LiquibasePass1@localhost:27017/lbcat");
when(connectionMock.getConnectionString()).thenReturn(connectionString);
when(connectionMock.getMongoClient()).thenReturn(clientMock);
when(clientMock.listDatabaseNames()).thenReturn(iterableMock);
when(iterableMock.iterator()).thenReturn(mongoCursor);
when(mongoCursor.hasNext()).thenReturn(false);

assertThatExceptionOfType(DatabaseException.class)
.isThrownBy(() -> database.checkDatabaseConnection());
}
}

0 comments on commit f0e8f22

Please sign in to comment.