Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example for couchbase driver with spring boot 3 and JDK 17 #54

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion couchbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<modules>
<module>standalone-couchbase</module>
<module>springboot-quickstart-couchbase</module>
<module>springboot3-quickstart-couchbase</module>
</modules>

<properties>
Expand All @@ -30,7 +31,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- MONGOCK versions -->
<couchbase-java-client.version>3.4.3</couchbase-java-client.version>
<couchbase-java-client.version>3.5.1</couchbase-java-client.version>
<reactor-core.version>3.5.0</reactor-core.version>
</properties>

Expand Down
25 changes: 25 additions & 0 deletions couchbase/springboot3-quickstart-couchbase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Mongock Example for: springboot + spring data couchbase

## Table of content
- [Requirements](#requirements)
- [Scope](#scope)
- [CLI](#cli)

## Requirements
- Java 17
- Maven 3.x
- Docker Compose

## Scope
- Quick guide on how to use Mongock with Springboot with autoconfiguration

## Set up
### Couchbase locally
- Run `docker-compose up`
- Check Couchbase is running fine with logging into web UI at http://localhost:8091/ui/index.html Credentials are Administrator/password

### Run the migration spring boot app

1. Execute `mvn clean package` inside your application folder.
2. Execute `java -jar YOUR_PROJECT_FOLDER/target/springboot-quickstart-couchbase-5.x.x-SNAPSHOT.jar`

65 changes: 65 additions & 0 deletions couchbase/springboot3-quickstart-couchbase/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: '3.3'
services:
couchbase:
ports:
- '8091-8096:8091-8096'
- '11210-11211:11210-11211'
image: couchbase
volumes:
- .docker-data/couchbase:/opt/couchbase/var
healthcheck:
test: [ "CMD", "curl", "-f", "http://couchbase:8091" ]
interval: 5s
timeout: 2s
retries: 6
networks:
- example-app-network

couchbase-cluster-setup:
image: alpine/httpie
container_name: couchbase-cluster-setup
depends_on:
couchbase:
condition: service_healthy
command: "-vv --ignore-stdin -f POST http://couchbase:8091/clusterInit password=password username=Administrator sendStats=false clusterName=sps services=kv,n1ql,index port=SAME"
networks:
- example-app-network

couchbase-indexes-setup:
image: alpine/httpie
container_name: couchbase-indexes-setup
depends_on:
- couchbase-cluster-setup
command: "-vv --ignore-stdin -a Administrator:password -f POST http://couchbase:8091/settings/indexes indexerThreads=4 numReplica=0 redistributeIndexes=false maxRollbackPoints=2 storageMode=plasma enablePageBloomFilter=false"
networks:
- example-app-network

couchbase-bucket-setup:
image: alpine/httpie
container_name: couchbase-bucket-setup
depends_on:
- couchbase-cluster-setup
command: "-vv --ignore-stdin -a Administrator:password -f POST http://couchbase:8091/pools/default/buckets name=bucket bucketType=couchbase ramQuota=256"
networks:
- example-app-network

couchbase-scope-setup:
image: alpine/httpie
container_name: couchbase-scope-setup
depends_on:
- couchbase-bucket-setup
command: "-vv --ignore-stdin -a Administrator:password -f POST http://couchbase:8091/pools/default/buckets/bucket/scopes name=examplescope"
networks:
- example-app-network

couchbase-collection-setup:
image: alpine/httpie
container_name: couchbase-collection-setup
depends_on:
- couchbase-scope-setup
command: "-vv --ignore-stdin -a Administrator:password -f POST http://couchbase:8091/pools/default/buckets/bucket/scopes/examplescope/collections name=examplecollection maxTTL=0"
networks:
- example-app-network

networks:
example-app-network:
98 changes: 98 additions & 0 deletions couchbase/springboot3-quickstart-couchbase/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<properties>
<java.version>17</java.version>

<maven.compiler.version>2.4</maven.compiler.version>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>

<spring-boot.version>3.1.7</spring-boot.version>
<couchbase-java-client.version>3.5.1</couchbase-java-client.version>
<slf4j.version>2.0.10</slf4j.version>
</properties>

<parent>
<groupId>io.mongock.examples</groupId>
<artifactId>couchbase</artifactId>
<version>5.3.6-SNAPSHOT</version>
</parent>

<name>springboot3-quickstart-couchbase</name>
<description>Mongock example: Quick start with Springboot3 and springdata Couchbase</description>
<artifactId>springboot3-quickstart-couchbase</artifactId>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- MONGOCK RUNNER -->
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-springboot-v3</artifactId>
</dependency>

<!-- MONGOCK DRIVER -->
<dependency>
<groupId>io.mongock</groupId>
<artifactId>couchbase-springboot-v3-driver</artifactId>
<version>5.3.6-SNAPSHOT</version>
</dependency>

<!-- SPRING BOOT -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
</dependency>

<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>${couchbase-java-client.version}</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>${reactor-core.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>io.mongock.examples.couchbase.springboot.QuickStartApp</mainClass>
</configuration>

<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.mongock.examples.couchbase.springboot;

import io.mongock.driver.api.entry.ChangeEntryService;
import io.mongock.driver.couchbase.driver.CouchbaseDriver;
import io.mongock.runner.springboot.EnableMongock;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
* Using @EnableMongock with minimal configuration only requires changeLog package to scan
* in property file
*/
@EnableMongock
@SpringBootApplication
public class QuickStartApp {

public static void main(String[] args) {
SpringApplication.run(QuickStartApp.class, args);
}

@Bean
ChangeEntryService changeEntryService(CouchbaseDriver couchbaseDriver){
return couchbaseDriver.getChangeEntryService();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.mongock.examples.couchbase.springboot.migration;

import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.DropQueryIndexOptions;
import io.mongock.api.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.couchbase.CouchbaseClientFactory;

import java.util.Arrays;

@ChangeUnit(id = "client-initializer", order = "1", author = "mongock")
public class ClientInitializerChangeUnit {

private static final Logger logger = LoggerFactory.getLogger(ClientInitializerChangeUnit.class);

@BeforeExecution
public void beforeExecution(CouchbaseClientFactory clientFactory) {
logger.debug("beforeExecution with bucket {}", clientFactory.getBucket().name() );
}

@RollbackBeforeExecution
public void rollbackBeforeExecution(CouchbaseClientFactory clientFactory) {
logger.debug("rollbackBeforeExecution with bucket {}", clientFactory.getBucket().name() );
}
@Execution
public void execution(Cluster cluster) {
cluster.queryIndexes().createIndex("bucket", "idx_example_index", Arrays.asList("field1, field2"));
}

@RollbackExecution
public void rollbackExecution(Cluster cluster) {
cluster.queryIndexes().dropIndex("bucket", "idx_example_index", DropQueryIndexOptions.dropQueryIndexOptions().ignoreIfNotExists(true));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
spring:
data:
couchbase:
bucket-name: bucket
couchbase:
connection-string: couchbase://localhost:11210
username: Administrator
password: password

mongock:
enabled: true
index-creation: true
couchbase:
collection: examplecollection
scope: examplescope
migration-scan-package: io.mongock.examples.couchbase.springboot.migration