ppazos opened a new issue, #14332:
URL: https://github.com/apache/grails-core/issues/14332
When working with indexes in MySQL (maybe in other databases too), there is
an index size limit. If there is a string field that is bigger than the index
size, Grails doesn't create the index even if it's defined in the mapping.
In MySQL it's possible to define a big varchar, then for the index to be
created:
CREATE TABLE t1 (
col1 VARCHAR(10),
col2 VARCHAR(4096),
INDEX (col1, col2(10))
);
Without the size in the index, this error is thrown: Specified key was too
long; max key length is 3072 bytes
CREATE TABLE t1 (
col1 VARCHAR(10),
col2 VARCHAR(4096),
INDEX (col1, col2)
);
Though something like that defined as a Grails Domain class would fail
silently.
### Task List
- [ ] Steps to reproduce provided
- [ ] Stacktrace (if present) provided
- [ ] Example that reproduces the problem uploaded to Github
- [ ] Full description of the issue provided (see below)
### Steps to Reproduce
1. Use MySQL as the database.
2. Define a domain with a big string constraint:
```groovy
class DataIndex {
String archetypeId
String archetypePath
static constraints = {
archetypePath(maxSize: 2048)
}
static mapping = {
archetypeId index: 'aid,aidpath'
archetypePath index: 'aidpath'
}
}
```
3. Run the app so the database schema is generated.
4. You will notice the index that should contain archetypeId and
archetypePath is not created in the database.
### Expected Behaviour
There is no problem with the behavior, since the current mapping DSL doesn't
allow to specify the size of the index. What I would propose is something like
a maxSize on the long field when defining the indexes, because that is the one
that causes issues independently of the index or indexes that include the
corresponding table column:
```groovy
class DataIndex {
String archetypeId
String archetypePath
static constraints = {
archetypePath(maxSize: 2048)
}
static mapping = {
archetypeId index: 'aid,aidpath'
archetypePath index: 'aidpath', maxSize: 255
}
}
```
### Actual Behaviour
An index size is not supported in the mapping DSL.
### Environment Information
- **Operating System**: Linux Minth 21.3
- **GORM Version:** the one that's on Grails 5.3.3
- **Grails Version (if using Grails):** Grails 5.3.3
- **JDK Version:** OpenJDK 11.0.20.1
### Example Application
- TODO: link to github repository with example that reproduces the issue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]