Tomas
Tomas

Reputation: 35

Liquibase with spring boot and cassandra

my team is building simple app which will run as job and initialize database of application base on java argument and profile, which swaps between postgres and cassandra database. There is no problem with postgres, but cassandra wont budge. Connection to cassandra database is sucessfull, but changelog is not applied.

We are using library/cassandra:4.1.0

Dependencies of the project:

    implementation 'org.hibernate:hibernate-core'
    implementation 'com.zaxxer:HikariCP'
    implementation 'org.springframework:spring-jdbc'
    implementation 'org.liquibase:liquibase-core'
    implementation 'org.postgresql:postgresql'


    implementation "org.springframework.data:spring-data-cassandra"
    implementation ('org.liquibase.ext:liquibase-cassandra:4.18.0'){
        exclude group: 'org.slf4j', module: 'slf4j-jdk14'
    }

    implementation 'org.yaml:snakeyaml'//TODO ?
    implementation "org.projectlombok:lombok"
    implementation "org.springframework.boot:spring-boot"
    implementation "org.springframework.boot:spring-boot-autoconfigure"
    implementation "org.springframework.cloud:spring-cloud-config-client"
    implementation "org.springframework:spring-beans"
    implementation "org.springframework:spring-context"
    implementation "org.springframework:spring-core"
    implementation "org.slf4j:slf4j-api"
    implementation "ch.qos.logback:logback-classic"
    implementation "org.slf4j:jul-to-slf4j"
    implementation "org.slf4j:log4j-over-slf4j"

application-cassandra.yaml file

server:
  port: 8083

spring:
  config:
    liquibase.change-log: classpath:/${java-param}/changelog.xml

  spring:
    autoconfigure:
      exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
    data:
      cassandra:
        port: 9042
        contact-points: 127.0.0.1
        local-datacenter: datacenter1
        keyspace-name: hs360_pokus

and just a sample changelog.xml from docs https://docs.liquibase.com/start/install/tutorials/cassandra.html

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xmlns:pro="http://www.liquibase.org/xml/ns/pro"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
        http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
    <changeSet id="1" author="Liquibase">
        <createTable tableName="test_table">
            <column name="test_id" type="int">
                <constraints primaryKey="true"/>
            </column>
            <column name="test_column" type="varchar"/>
        </createTable>

    </changeSet>
</databaseChangeLog>

What are we missing? Something in config or in dependencies?

Upvotes: 0

Views: 551

Answers (1)

clunven
clunven

Reputation: 1695

I suspect the issue comes from your application.yaml file. If you look at the key hierarchy I notice you put twice spring. a.k.a keys should look like spring.data.cassandra and not spring.spring.data.cassandra.

The yaml file should then look like this:

server:
  port: 8083

spring:
  config:
    liquibase.change-log: classpath:/${java-param}/changelog.xml

  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
  data:
    cassandra:
      port: 9042
      contact-points: 127.0.0.1
      local-datacenter: datacenter1
      keyspace-name: hs360_pokus

The connectivity is currently successful because you connect to a node with default spring data cassandra values (127.0.0.1 / 9042 / datacenter1) but it probably writes the tables in the default keyspace system and not using the one you set in your configuration.

Upvotes: 1

Related Questions