-
Notifications
You must be signed in to change notification settings - Fork 34
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
Integration with spring boot #212
Comments
Hello @dzasti, It should be possible to use Spring Liquibase with Cassandra as I successfully ran it with the example below. First of all, I used a slightly modified version of The dependencies to include in your POM file are: <!-- Using Spring Boot 3.1.4 and Java 17 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<!-- Include cassandra-jdbc-wrapper if you don't use Simba JDBC, otherwise include a dependency to Simba driver -->
<dependency>
<groupId>com.ing.data</groupId>
<artifactId>cassandra-jdbc-wrapper</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-cassandra</artifactId>
<!-- Use here a version modified to use cassandra-jdbc-wrapper instead of Simba if necessary-->
<version>4.23.2</version>
</dependency>
<!-- Required to avoid runtime exceptions due to a conflict of version between Spring Boot dependencies and cassandra-jdbc-wrapper -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>4.17.0</version>
</dependency>
</dependencies>
</dependencyManagement> Assuming you have a Cassandra instance running on localhost, port 9042, with a keyspace named In your application.properties file, you should have this: # Liquibase configuration
spring.liquibase.url=jdbc:cassandra://localhost:9042/test_keyspace?localdatacenter=datacenter1&user=cassandra&password=cassandra&compliancemode=Liquibase
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
spring.liquibase.driver-class-name=com.ing.data.cassandra.jdbc.CassandraDriver
# Spring datasource configuration
spring.datasource.name=cassandra_datasource
spring.datasource.url=jdbc:cassandra://localhost:9042/test_keyspace?localdatacenter=datacenter1&user=cassandra&password=cassandra
spring.datasource.driver-class-name=com.ing.data.cassandra.jdbc.CassandraDriver
spring.datasource.hikari.minimum-idle=1 In your project resources, you should have the following files:
databaseChangeLog:
- include:
file: classpath:/db/changelog/init.sql
USE test_keyspace;
CREATE TABLE IF NOT EXISTS tbl_test (
keyname text PRIMARY KEY,
bool_col boolean,
int_col int);
INSERT INTO tbl_test(keyname, bool_col, int_col) VALUES ('key1', true, 1) IF NOT EXISTS;
INSERT INTO tbl_test(keyname, bool_col, int_col) VALUES ('key2', false, 2) IF NOT EXISTS; Finally, your Spring Boot application: @SpringBootApplication
public class SpringLiquibaseCassandraApplication {
@Autowired
JdbcTemplate jdbcTemplate;
@EventListener(ApplicationReadyEvent.class)
public void checkData() throws SQLException {
jdbcTemplate.query("SELECT * FROM tbl_test", rs -> {
System.out.println("------------------------------------");
System.out.println("keyname: " + rs.getString(1));
System.out.println("bool_col: " + rs.getBoolean(2));
System.out.println("int_col: " + rs.getInt(3));
});
}
public static void main(String[] args) {
SpringApplication.run(SpringLiquibaseCassandraApplication.class, args);
}
} Running your application, the output should be the following, proving the Liquibase changes have been executed successfully:
|
as like we are connecting sql db from spring boot using liquibase it is possible to connect aws keyspace using liquibase without jdbc |
@shubha11m Liquibase is based on JDBC, so it's not possible to use it without JDBC. But it should not really be a problem. |
HI @maximevw thankyou for you response so as previously the snip of code is there to connect keyspace with spring boot is it whole code or do we need to add cql config file and other than that and are we not able to put our changes into xml file rather then .sql i had applied all changes #212 (comment) |
Hi @shubha11m The example given in this issue is just an example among a lot of possible configurations, so, obviously you can adapt it according to your needs. If you prefer use xml changelog, you can. A lot of documentation about running Liquibase with SpringBoot is available here and in the linked pages. Maybe try to specify the changelog location in the application.properties file: spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml # Adapt the path to match your changelog file. Also, ensure the dependencies are up-to-date (those mentioned in this example are old and may contain some bugs): <dependency>
<groupId>com.ing.data</groupId>
<artifactId>cassandra-jdbc-wrapper</artifactId>
<version>4.12.0</version>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-cassandra</artifactId>
<version>4.28.0</version>
</dependency> |
Hi @maximevw, I have tried with the versions you suggested, scripts appears as executed in |
Hello @nicobte |
@maximevw i have a question about usage of cassandra-jdbc-wrapper:4.12.0 in last release of liquibase-cassandra (4.28). Seems, like in LockServiceCassandra there are multiple checks for updatedRows count. but with debugging i've realized, that in cassandra-jdbc-wrapper DefaultOptionSet always returns 0 in getSQLUpdateResponse() method. so it's impossible to get correct updated rows count for LockServiceCassandra |
Hello @Danil9966 Cassandra database is not able to return the number of updated rows, that's why you meet this behaviour, but when running with Liquibase, your JDBC URL should always have the query parameter |
@maximevw thank you! Is there a proper way to set this query parameter from configs or java code? CassandraDataSource (4.12.0 version) doesn't have complienceMode parameter |
@Danil9966 Indeed, Alternatively, using Java code, you have to use the final String url = "jdbc:cassandra://localhost:9042/keyspace?localdatacenter=DC1&compliancemode=Liquibase";
final Connection connection = DriverManager.getConnection(url); |
Thanks @maximevw. I managed to solve it. I was wrong using the changelogSync function. I made a custom Liquibase implementation, so I excluded auto configuration by Here is what I made, hopefully it can help someone else: Dependencies:
db.changelog-master.yaml
create_table.yaml
db/changelog/insert_values.yaml"
|
Hello, is there a possibility to run liquibase cassandra extension via spring boot? Can’t find any example online. Also I’ve done some research: spring-projects/spring-boot#29991 (comment) , #4 (comment). Seems confusing, could someone show me an example, if its possible ?
thanks
The text was updated successfully, but these errors were encountered: