Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Liquibase to quote column and table names

Tags:

liquibase

h2

Our Spring Boot application uses Liquibase for database migration upon deployment.

Our production system uses an SAP HANA database, while for local testing, we're using H2.

Due to various problems we want to migrate from H2 v1.4.x to H2 v2, but the problem is that some column and table identifiers we used in our Liquibase changesets are reserved words in H2 v2.x (but not in SAP HANA) and lead to SQL syntax errors when testing locally.

Adapting the changeset files is not an option since that would change their checksum and lead to liquibase errors when the application is deployed.

Is there a global flag that can be set outside the changeset files which forces Liquibase to double-quote all identifiers when generating the SQL statements?

What I've tried so far:

  • inserting - objectQuotingStrategy: QUOTE_ALL_OBJECTS into the master changelog file from which the individual changesets are included.
  • inserting parameter.objectQuotingStrategy=QUOTE_ALL_OBJECTS into liquibase.properties.
  • setting the parameter objectQuotingStrategy to QUOTE_ALL_OBJECTS programmatically upon instantiation of the SpringLiquibase bean.

Those settings don't seem to do anything in that respect.

like image 746
ronin667 Avatar asked Dec 06 '25 15:12

ronin667


1 Answers

I managed to find a viable solution.

Actually objectQuotingStrategy would be the way to go as intended by the Liquibase developers but due to a high-priority bug in Liquibase that has been open since 2017, this does not work for H2 databases.

However I was able to work around the problem by exempting some reserved words through the DB connection string:

jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;NON_KEYWORDS=DAY,VALUE
like image 85
ronin667 Avatar answered Dec 10 '25 15:12

ronin667