apache / apache/grails-core

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

Open
#14,376 10 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-hibernate5-dbmigration
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown Grails domain field, constraints, and mapping, then run dbm-generate-gorm-changelog and dbm-generate-changelog. Compare their generated byte_data column with the schema types produced without the DBM plugin for maxSize values present and absent. Done means the generated changeset preserves the appropriate MySQL byte-array size instead of always using BLOB.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, mysql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.