Liquibase 4.7.0 upgrade causing issue with table name
See original GitHub issueI 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:
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:
- Created 2 years ago
- Comments:11 (4 by maintainers)
Top GitHub Comments
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:
Liquibase 4.6.2 creates column VALUE
Liquibase 4.7.0 and 4.71 creates column value
The latter then cannot be selected - we get Column “VALUE” not found
or
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column “VALUE” not found; SQL statement: insert into bosun_dep_add_yaml (deployment_id, name, value) values (?, ?, ?) [42122-200]
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.