question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Liquibase 4.7.0 upgrade causing issue with table name

See original GitHub issue

I have a hobby project running on Spring Boot 2.7 snapshot which today upgraded from Liquibase 4.6.2 to 4.7.0.

With Liquibase 4.6.2 and H2 datasource the following changelog

databaseChangeLog:
  - changeSet:
      id: 1
      author: me
      changes:
        - createTable:
            tableName: user
            columns:
              - column:
                  name: id
                  type: int
                  autoIncrement: true
                  constraints:
                    nullable: false
                    primaryKey: true
                    primaryKeyName: user_pk
              - ..

will create UPPERCASE tables in H2:

image

In fact I never really paid attention to the uppercase/lowercase table/column name in the H2 console despite having them lowercase in the changelog.

Also a changelog like this (lowercase names) works:

        - insert:
            tableName: user_role
            columns:
              - column:
                  name: user_id
                  valueComputed: select id from user where username = 'foo_bar'
              - column:
                  name: role_name
                  value: ROLE_USER

Doing some manual queries in the H2 console work for these:

  • SELECT * FROM USER
  • SELECT * FROM user
  • SELECT * FROM "USER"

but not for SELECT * FROM "user"

Now with upgrade to Liquibase 4.7.0 I see other behaviour with above setup.

The application won’t start as the changelog with the insert fails now:

Reason: liquibase.exception.DatabaseException: Table "USER" not found; SQL statement:
INSERT INTO PUBLIC.user_role (user_id, role_name) VALUES (select id from user where username = 'foo_bar', 'ROLE_USER') [42102-200] [Failed SQL: (42102) INSERT INTO PUBLIC.user_role (user_id, role_name) VALUES (select id from user where username = 'foo_bar, 'ROLE_USER')]

Although “USER” (uppercase) is not used like that in the insert it still fails.

Now I probably should have not used the table name user as USER is a reserved word, so I can only blame myself 😉 but this might impact others as well…

In the Liquibase 4.7.0 release notes I don’t see anything noteworthy that changed that could explain this behaviour.

Is this unexpected and a bug or expected behaviour?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gstanchevcommented, Feb 2, 2022

We have ran into this (or similar) issue as well so interested to see the outcome of the investigation. We have a table that has a column name value. Here is the changelog:

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.8.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
    <changeSet author="Apphub" id="1575593693147-1">
        <createTable tableName="bosun_dep_add_yaml">
            <column name="deployment_id" type="VARCHAR(255)">
                <constraints nullable="false" primaryKey="true" primaryKeyName="ADD_YAML_PK"/>
            </column>
            <column name="name" type="VARCHAR(255)">
                <constraints nullable="false" primaryKey="true" primaryKeyName="ADD_YAML_PK"/>/>
            </column>
            <column name="value" type="clob"/>
        </createTable>
    </changeSet>
    <changeSet author="AppHub" id="202108-1.0.0-2"></changeSet>
</databaseChangeLog>

Liquibase 4.6.2 creates column VALUE

image

Liquibase 4.7.0 and 4.71 creates column value

image

The latter then cannot be selected - we get Column “VALUE” not found

select value from BOSUN_DEP_ADD_YAML

or

insert into bosun_dep_add_yaml (deployment_id, name, value) values ('a', 'b', 'c')

org.h2.jdbc.JdbcSQLSyntaxErrorException: Column “VALUE” not found; SQL statement: insert into bosun_dep_add_yaml (deployment_id, name, value) values (?, ?, ?) [42122-200]

1reaction
nvoxlandcommented, Aug 8, 2022

We should re-look into the best list of reserved words for h2, possibly divided by version since they have changed them significantly between 1.x and 2.x.

For the times you hit incorrectly quoted (and therefore case sensitive) names, you can use modifySql to fix what is generated to keep them from being stored in the wrong case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error running changesets after 4.7 update - Liquibase Forum
Hi Team,. There seems to be an issue in 4.7.1 occuring when “KEY”, “VALUE” column names are spelled lowercase in the changeset xml....
Read more >
Release Notes | Liquibase Docs
Here is a closer look at what we improved in the latest release. Known Issues. In version 4.7.0, users that have "edb" in...
Read more >
Spring Boot migration script syntax problems due to H2 ...
210 and the migration scripts now fails due to syntax errors. Migration scripts are 2 types - pre (pure SQL) and post liquibase...
Read more >
Percona Online Schema Change - Liquibase Extensions
https://github.com/liquibase/liquibase-percona/issues ... 2 <addColumn tableName="person"> 3 <column name="address" type="varchar(255)"/> 4 ...
Read more >
[KEYCLOAK-2949] update to 1.9.3 failure - Red Hat
36 more Caused by: liquibase.exception.DatabaseException: Cannot add foreign key constraint [Failed SQL: ALTER TABLE keycloak.KEYCLOAK_GROUP ADD CONSTRAINT ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found