user21236160
user21236160

Reputation:

DATABASECHANGELOG not generated by liquibase when I use it with scylladb

I'm new to liquibase and I want to use it on scylladb database, although it's a small project but instead of creating schema by hand I would like to use something more professional like liquibase.

What i did to achieve this task.

I'm using scala language having sbt.version = 1.2.8

What I did in scala is given below.

build.sbt:

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.13.1"

lazy val root = (project in file("."))
  .settings(
    name := "scylladb_liquibase"
  )
libraryDependencies ++= Seq(
  "org.liquibase" % "liquibase-core" % "4.1.1",
  "com.scylladb" % "java-driver-core" % "4.15.0.0",
  "org.ow2.util.bundles" % "cassandra-jdbc-1.2.5" % "1.0.0")

Scala object:

import liquibase.Liquibase
import liquibase.database.jvm.JdbcConnection
import liquibase.resource.ClassLoaderResourceAccessor

import java.io.File
import java.sql.DriverManager

object Liquibase extends App {
  val props = new java.util.Properties()
  val fis = new java.io.FileInputStream(new File("liquibase-files/liquibase.properties"))
  props.load(fis)
  fis.close()

  val jdbcUrl = props.getProperty("url")
  val driver = props.getProperty("driver")
  Class.forName(driver)

  val connection = DriverManager.getConnection(jdbcUrl)

  val jdbcConnection = new JdbcConnection(connection)

  // Run the Liquibase migration
  val liquibase = new Liquibase("changelog.sql", new ClassLoaderResourceAccessor(), jdbcConnection)

  // Execute the SQL statement
  liquibase.update("")
}

liquibase.properties:

url= jdbc:cassandra://172.24.0.3:9042/test01;DefaultKeyspace=test01
driver= com.simba.cassandra.jdbc42.Driver
defaultSchemaName= test01

liquibase.sql

--liquibase formatted sql

--changeset asif:1
CREATE TABLE test01.TESTME1 ( foo int PRIMARY KEY, bar text );
--rollback DROP TABLE test01.TESTME2;
--changeset asif:2
CREATE TABLE test01.TESTME2 ( foo int PRIMARY KEY, bar text );
--rollback DROP TABLE test01.TESTME2;

When I run(update) the program it generate an error

INFO: No DATABASECHANGELOGLOCK available in cassandra.

Through terminal I found that the databasechangelog not created but databasechangeloglock created.

What I tried:

Here is an error:

May 03, 2023 1:20:13 PM liquibase.logging
INFO: successfully.acquired.change.log.lock
May 03, 2023 1:20:13 PM liquibase.servicelocator
INFO: Cannot load service: liquibase.parser.ChangeLogParser: liquibase.parser.core.json.JsonChangeLogParser Unable to get public no-arg constructor
May 03, 2023 1:20:13 PM liquibase.servicelocator
INFO: Cannot load service: liquibase.parser.ChangeLogParser: liquibase.parser.core.yaml.YamlChangeLogParser Unable to get public no-arg constructor
May 03, 2023 1:20:13 PM liquibase.ext
INFO: Creating database history table with name: "".DATABASECHANGELOG
May 03, 2023 1:20:13 PM liquibase.ext
INFO: Reading from "".DATABASECHANGELOG
May 03, 2023 1:20:14 PM liquibase.servicelocator
INFO: Cannot load service: liquibase.hub.HubService: Provider liquibase.hub.core.OnlineHubService could not be instantiated
Caused by: liquibase.exception.DatabaseException: Error executing SQL UPDATE "".DATABASECHANGELOGLOCK SET LOCKED = FALSE, LOCKEDBY = NULL WHERE ID = 1: [Simba][CassandraJDBCDriver](500211) ERROR Invalid query: UPDATE "".DATABASECHANGELOGLOCK SET LOCKED = FALSE, LOCKEDBY = NULL WHERE ID = 1, Cause: com.simba.cassandra.shaded.datastax.driver.core.exceptions.SyntaxError: line 1:8  : missing elements...
.
    at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:95)
    at liquibase.executor.jvm.JdbcExecutor.update(JdbcExecutor.java:278)
    at liquibase.executor.jvm.JdbcExecutor.update(JdbcExecutor.java:246)
    at liquibase.ext.cassandra.lockservice.LockServiceCassandra.releaseLock(LockServiceCassandra.java:126)

We can release that lock from cqlsh using command:

UPDATE DATABASECHANGELOGLOCK SET locked=false, lockgranted=null, lockedby=null WHERE id=1;

But when I run program again, its behavior remain same as I described, first changeset works then it do not release lock.

What is the main issue, Where I'm doing wrong?

UPDATE:

We see an exception of missing elements. The problem is when we run this program, it executes first changeset and acquire lock - then it send entry to databasechangelog table. Now the problem is it is sending 13 values i.e.,

[Simba][CassandraJDBCDriver](500211) ERROR Invalid query: INSERT INTO "".DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('111', 'sheng.w', 'changelog.xml', 1683178609999, 3, '8:1dc9bb64b8fe1be5bf4a6ed2f1bb88ef', 'sql', '', 'EXECUTED', NULL, NULL, '4.1.1', '3178609878'), Cause: com.simba.cassandra.shaded.datastax.driver.core.exceptions.SyntaxError: line 1:13  : missing elements...

It is not sending 'tag' column's value. In cqlsh autogenerated table databasechangelog has 14 columns. For this problem I've searched on different browsers and found we can send 'tag' via xml - so I created 'changelog.xml' just to check what if we send 'tag'.

changelog.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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-3.9.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">

    <changeSet id="111" author="zaryab">
        <tagDatabase tag="1.1" />
    </changeSet>

</databaseChangeLog>

Now it is sending 'tag' but still exception is same.

[Simba][CassandraJDBCDriver](500211) ERROR Invalid query: INSERT INTO "".DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID, TAG) VALUES ('111', 'zaryab', 'changelog.xml', 1683178609999, 3, '8:1dc9bb64b8fe1be5bf4a6ed2f1bb88ef', 'tagDatabase', '', 'EXECUTED', NULL, NULL, '4.1.1', '3178609878', '1.1'), Cause: com.simba.cassandra.shaded.datastax.driver.core.exceptions.SyntaxError: line 1:13  : missing elements...

Help us in that, how can we resolve this issue?

Upvotes: 1

Views: 1140

Answers (1)

Daryl Doak
Daryl Doak

Reputation: 244

I know nothing about scylladb or cassandra, but from looking at the supported databases page scylladb is not supported. There must be enough of a behind the scenes difference between the 2 to prevent Liquibase from working.

https://www.liquibase.com/supported-databases?category=advanced,contributed,foundational

Upvotes: 0

Related Questions