liquibase-cassandra
liquibase-cassandra copied to clipboard
Failed to insert changelog into DATABASECHANGELOG table if multiple changes in changesets
Hi, I'm testing version 4.25.0.1
, but it seems that if there are multiple changes within a single changeset, the insertion into the DATABASECHANGELOG fails.
Here is a sample of the changelog.yml:
databaseChangeLog:
- changeSet:
id: create-tables
author: test
changes:
- sql:
dbms: mysql
sql: >
CREATE TABLE a (
user_id BIGINT,
PRIMARY KEY (user_id)
);
- sql:
dbms: cassandra
sql: >
CREATE TABLE b (
user_id BIGINT,
PRIMARY KEY (user_id)
);
rollback:
- sql:
dbms: mysql
sql: DROP TABLE a
- sql:
dbms: cassandra
sql: DROP TABLE b
error messages
Unexpected error running Liquibase: line 1:282 mismatched character '<EOF>' expecting ''' [Failed SQL: (0) INSERT INTO test.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('create-tables', 'test', 'changelog.yml', 1703112425259, 1, '9:abd6cfa9eea355da8b0d16523bcc5115', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.25.0', '3112424168')]
Caused by: java.sql.SQLTransientException: com.datastax.oss.driver.api.core.servererrors.SyntaxError: line 1:282 mismatched character '<EOF>' expecting '''
liquibase.exception.CommandExecutionException: liquibase.exception.LiquibaseException: liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: com.datastax.oss.driver.api.core.servererrors.SyntaxError: line 1:282 mismatched character '<EOF>' expecting ''' [Failed SQL: (0) INSERT INTO test.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('create-tables', 'test', 'changelog.yml', 1703112425259, 1, '9:abd6cfa9eea355da8b0d16523bcc5115', 'sql; sql', '', 'EXECUTED', NULL, NULL, '4.25.0', '3112424168')]
at liquibase.command.CommandScope.execute(CommandScope.java:237)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:55)
After conducting some research, it seems that there is a compatibility issue between liquibase-core
and ing-bank/cassandra-jdbc-wrapper
.
Liquibase attempts to insert text separated by semicolons (;
) into the description of the DATABASECHANGELOG when there are multiple changes in a changeset.
https://github.com/liquibase/liquibase/blob/e605cee3c7795688b2d178a67c5fed818ac52d0e/liquibase-standard/src/main/java/liquibase/changelog/ChangeSet.java#L1250
However, cassandra-jdbc-wrapper splits SQL statements at semicolons (;
). As a result, it ends up trying to execute incomplete SQL statements. This behavior is evident in their code here:
https://github.com/ing-bank/cassandra-jdbc-wrapper/blob/a36a0d207be8fee1dbafc9aa731855bf649e9614/src/main/java/com/ing/data/cassandra/jdbc/CassandraStatement.java#L300
Below is a project for reproduction purposes.
https://github.com/noda-sin/liquibase-cassandra-sample
Suggestion
Can we consider adding a Custom MarkChangeSetRanGenerator to liquibase-cassandra to convert semicolons (;
) in the description to a different character?
Hello @noda-sin,
Very interesting finding! Another solution could also be to modify the behaviour of the Cassandra JDBC driver to better handle the multiple statements. Indeed, splitting by semi-colons is probably a too naive way to proceed to split statements because, even for cases not specifically related to Liquibase, it could lead to unexpected behaviours.
Could you please open an issue in the JDBC driver project for this?
@maximevw
Thanks. It looks you are maintainers of cassandra-jdbc-wrapper too. I created the ticket in https://github.com/ing-bank/cassandra-jdbc-wrapper/issues/50
Can I close this ticket?
@noda-sin I think we can keep this one open until the issue is fully fixed and the fix successfully tested with Liquibase (when it'll be available).
It will be resolved by https://github.com/liquibase/liquibase-cassandra/pull/259
@noda-sin - could you let us know if this is working for you now so we know if we can close this ticket? Thanks!
@kevin-atx
Sorry for late. Yes, It's working on my env. Let me close this ticket. thank you!