grails-database-migration
grails-database-migration copied to clipboard
Postgres dbm-gorm-diff fails with Integer defaultValue
Situation
I use Grails 3.2.4, Hibernate5 and PostgreSQL 9.3.15.
When i specify defaultValue in mapping on Domain, dbm-gorm-diff fails after second time.
I summarized the situation.
Preparation and Migrate first time
1. Create new Grails 3.2.4 application. (with database-migration:3.0.0, org.liquibase:liquibase-core:3.5.3)
2. Setup database-migration plugin.(create changelog.groovy and tables)
grails dbm-generate-changelog changelog.groovy
grails dbm-update
changelog.groovy
databaseChangeLog = {
}
tables
migrationtest=# \d
List of relations
Schema | Name | Type | Owner
--------+-----------------------+-------+-------
public | databasechangelog | table | koji
public | databasechangeloglock | table | koji
(2 rows)
migrationtest=#
3. Create Domain.
package migrationtest
class Person {
Integer age = -1
static constraints = {
}
static mapping = {
age defaultValue: "-1"
}
}
4. migration!
dbm-gorm-diff 1.groovy --add
dbm-update
5. check result. No problem.
migrationtest=# \d
List of relations
Schema | Name | Type | Owner
--------+-----------------------+----------+-------
public | databasechangelog | table | koji
public | databasechangeloglock | table | koji
public | hibernate_sequence | sequence | koji
public | person | table | koji
public | person_id_seq | sequence | koji
(5 rows)
migrationtest=#
migrationtest=# \d person
Table "public.person"
Column | Type | Modifiers
---------+---------+-----------------------------------------------------
id | bigint | not null default nextval('person_id_seq'::regclass)
version | bigint | not null
age | integer | not null default (-1)
Indexes:
"personPK" PRIMARY KEY, btree (id)
migrationtest=#
Then a problem occurs.
When i execute dbm-gorm-diff now again, occurs follwoing error.
INFO 17/01/10 11:03: liquibase: Can not use class org.grails.plugins.databasemigration.liquibase.GormDatabase as a Liquibase service because it does not have a no-argument constructor
Command execution error: liquibase.command.CommandExecutionException: java.lang.ClassCastException: liquibase.statement.DatabaseFunction cannot be cast to java.lang.Integer
:dbmGormDiff FAILED
FAILURE: Build failed with an exception.
Actually the following message should be displayed because there is NOT change.
databaseChangeLog = {
}
BUILD SUCCESSFUL
When i delete or comemnt out age defaultValue: "-1" from static mapping, then
databaseChangeLog = {
}
BUILD SUCCESSFUL
displayed.
By the way, if property is String, does not occurs this problem. I think that this problem is caused by "defaultValue". Or am i something wrong?
I created sample repository for this issue. https://github.com/koji-k/grails3-database-migration-debug
Note
This problem occurs Liquibase side.
I added issue on JIRA of Liquibase.
https://liquibase.jira.com/browse/CORE-2986
This is a problem with liquibase/liquibase-hibernate. You need to report the issue there.
The issue is:
The postgres snapshot for the age column returns a liquibase.statement.DatabaseFunction when getAttribute("defaultValue", Object.class) is called (https://github.com/liquibase/liquibase/blob/a57dfe9c73a849dcfd71a59cbcd394611a828bb2/liquibase-core/src/main/java/liquibase/diff/compare/core/DefaultDatabaseObjectComparator.java#L62).
Eventually to compare the values it attempts to call Integer.compareTo() and pass in the DatabaseFunction, which fails because the compareTo method only accepts another Integer (https://github.com/liquibase/liquibase/blob/a57dfe9c73a849dcfd71a59cbcd394611a828bb2/liquibase-core/src/main/java/liquibase/diff/ObjectDifferences.java#L133)
When you create an issue with liquibase, please link to this issue.
PS: Thanks so much for the sample repo with the docker instructions. Made my life a lot easier!
@jameskleeh Thank you for checking this proboem! I wrote about this proboem on JIRA of Liquibase. https://liquibase.jira.com/browse/CORE-2986
I am glad that i can take part for this plugin. This Migration plugin is helping my life every day. Really thanks for providing this nice plugin!
I got the same issue with h2 database. So I think this is not just related to Postgres.
If you came here with the same issue, please create a jira account and upvote the ticket to speed up resolution: https://liquibase.jira.com/browse/CORE-2986
Hi Liquibase project works again. https://github.com/liquibase/liquibase/releases There 2 Updates from 3.5.3.(so latest version is 3.5.5)
I wrote a ISSUE on Jira of Liquibase last year. https://liquibase.jira.com/browse/CORE-2986) My issue is not yet resolved maybe. But there are many Bugfix from Liquibase 3.5.3. Does grails-database-migration plugin update Liquibase version?
@koji-k v3.0.4 of the plugin will be using liquibase 3.5.5
@puneetbehl Thanks! i will try it!