apache / apache/grails-core

static mapping index not creating index for varchar > 255 (for MySQL)

Open
#14,603 1 comment 0 reactions 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Steps to Reproduce

1. Create a domain class like this:

```
class MyDomain {

String attr

static constraints = {
attr(maxSize: 2048)
}
static mapping = {
attr index: 'my_idx'
}
}
```

2. run-app

3. Check the database, the index is not being created since 2048 exceeds the index max size (255).

### Expected Behaviour

The index creation code should check the maxSize and specify the size of the index like (this is for MySQL):

`INDEX `my_idx` (`attr`(255))`

### Actual Behaviour

It seems Grails is not checking the maxSize and tries to create the index without the size, and the database is not allowing it.

### Environment Information

- **Grails Version:** 2.5.6
- **JDK Version:** 1.7

Contributor guide

Open the contributing guide

Research direction

Start from the static mapping index creation path and reproduce the MyDomain example with MySQL using run-app. Inspect the generated database index for attr, then verify that the completed behavior creates my_idx with the applicable prefix length for the maxSize value.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.