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

dbm-generate-gorm-changelog and dbm-generate-changelog both fail to generate the correct byte array MySQL type #253

Open
robertsantiago opened this issue Dec 19, 2021 · 10 comments

Comments

@robertsantiago
Copy link

robertsantiago commented Dec 19, 2021

I have a Grails application and using the database migration plugin (DBM) it fails to generate the correct MySQL type for byte arrays.

I have the following domain field with constraints and mapping:

byte[] byteData

static constraints = {
    byteData(nullable: false, maxSize: 250000)
}

static mapping = {
    byteData(column: 'byte_data', type: 'binary')
}

Without the DBM plugin, the table in question would generate a field of type MEDIUMBLOB . If the maxSize constraint is removed, then the generated type would be TINYBLOB . I would expect the DBM plugin to generate from either the GORM classes or from the MySQL database the change sets for the byte array with its size constraint correctly but this is not the case.

When I use **dbm-generate-gorm-changelog** or **dbm-generate-changelog** they both result in the same column command inside the changeset as follows:

column(name: "byte_data", type: "BLOB") {
    constraints(nullable: "false")
}

It seems that the commands are ignoring the maxSize constraint specified above which causes a problem when we assign arrays longer than what the BLOB type allows.

We can manually change the type to MEDIUMBLOB in the change set although it seems like a hack. Not sure if this is a known problem or if it is a problem at all. I would appreciate any advice on this issue.

@puneetbehl
Copy link
Contributor

Please specify the version of Grails® framework and the plugin version.

@robertsantiago
Copy link
Author

Grails: 4.0.1
Migration plugin: 3.1.0

@robertsantiago
Copy link
Author

robertsantiago commented Dec 27, 2021

The problem also happens in the latest version of Grails and the latest versions of the migration plugin and Liquibase:

Grails: 5.1.1
Migration plugin: 4.0.0-RC3
Liquibase: 4.6.2

@abcfy2
Copy link

abcfy2 commented Jan 2, 2022

Maybe this issue is the same as #187 ?

@abcfy2
Copy link

abcfy2 commented Jan 2, 2022

Maybe you should use sqlType: 'binary' instead of type: 'binary'

@robertsantiago
Copy link
Author

abcfy2 Thanks for the help. Unfortunately, using sqlType: 'binary' still yields a similar result but without the constraint:

column(name: "byte_data", type: "BLOB")

@robertsantiago
Copy link
Author

Correction: I changed the constraint to nullable: true and that was what caused the result without the constraint. When using nullable: false again, the result of using abcfy2 suggestion (sqlType: 'binary') is the same as above.

@abcfy2
Copy link

abcfy2 commented Jan 3, 2022

I find the reason, that's liquibase limitation. You can't use this in dbm-generate-gorm-changelog. You can find full description in my comment: #187 (comment)

Maybe you have to drop and create your database and use:

./grailsw dbm-create-changelog changelog.groovy
./grailsw dbm-gorm-diff v1_init.groovy

@abcfy2
Copy link

abcfy2 commented Jan 3, 2022

Liquibase BLOB type logic can be found here: https://github.com/liquibase/liquibase/blob/6a609ce2cacb67d9a3aeda3f23e942752f935229/liquibase-core/src/main/java/liquibase/datatype/core/BlobType.java#L19

dbm-generate-gorm-changelog will use GormDatabase not MysqlDatabase, which does not connect to MySQL, so liquibase will not use MySQL BINARY type to convert this sqlType.

So you have to use dbm-gorm-diff, not dbm-generate-gorm-changelog.

@robertsantiago
Copy link
Author

abcfy2, your insight is very close. Indeed creating the changelog from the database and not from GORM is the right workaround. I had to:

  1. Recreate the database from GORM.
  2. Use dbm-generate-changelog which will generate the correct type. (using dbm-create-changelog creates an empty databaseChangeLog)

In addition, creating the changelog from the database using dbm-generate-changelog works in both Grails versions 4.0.1 and 5.1.1.

Thanks very much for your help.

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