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

Failed to insert changelog into DATABASECHANGELOG table if multiple changes in changesets #258

Closed
noda-sin opened this issue Dec 20, 2023 · 6 comments

Comments

@noda-sin
Copy link

noda-sin commented Dec 20, 2023

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?

@noda-sin noda-sin changed the title Failed to insert DATABASECHANGELOG table if multiple changes in changesets Failed to insert changelog into DATABASECHANGELOG table if multiple changes in changesets Dec 20, 2023
@maximevw
Copy link
Contributor

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?

@noda-sin
Copy link
Author

noda-sin commented Dec 25, 2023

@maximevw

Thanks. It looks you are maintainers of cassandra-jdbc-wrapper too.
I created the ticket in ing-bank/cassandra-jdbc-wrapper#50

Can I close this ticket?

@maximevw
Copy link
Contributor

@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).

@noda-sin
Copy link
Author

noda-sin commented Jan 9, 2024

It will be resolved by #259

@kevin-atx
Copy link
Contributor

@noda-sin - could you let us know if this is working for you now so we know if we can close this ticket? Thanks!

@noda-sin
Copy link
Author

@kevin-atx

Sorry for late. Yes, It's working on my env. Let me close this ticket. thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants