apache / apache/grails-core

inList check constraints are missing!

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

Description

### Task List

- [x] Steps to reproduce provided
- [ ] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce
For `inList` fields the check constraints seem to be missing:
- https://github.com/aadrian/fieldbugs1/blob/master/grails-app/domain/com/mycorp/fieldbugs1/TableOne.groovy#L22` should allow only `'S','M','L','XL'` and `null`
- https://github.com/aadrian/fieldbugs1/blob/master/grails-app/domain/com/mycorp/fieldbugs1/TableOne.groovy#L23 should allow only `22, 42, 44, 66`
- https://github.com/aadrian/fieldbugs1/blob/master/grails-app/domain/com/mycorp/fieldbugs1/TableOne.groovy#L24 should allow only `'y','n','x'`

but the generated DDL https://github.com/aadrian/fieldbugs1/blob/master/ddl.sql does not contain constraints on those fields (only a size limitation)

### Expected Behaviour
`schema-export` (and all `dbCreate` modes except 'none') should make use of the check constraints, i.e. the generated DB should have them, and when starting an application with `dbCreate=validate` should warn/error that they're missing (like in the case of other mapping differences).

### Actual Behaviour
No check constraints are being used, nor any warning/error is being displayed for `dbCreate=validate`.

### Environment Information

- **Operating System:** OSX, Linux, Win 7,8,10
- **GORM Version:** 6.1.9
- **Grails Version (if using Grails):** 3.3.3
- **JDK Version:** 1.8.0_162

### Example Application
https://github.com/aadrian/fieldbugs1/

Thank you.

Contributor guide

Open the contributing guide

Research direction

Start with the linked TableOne.groovy fields and generated ddl.sql, then trace schema-export and the dbCreate modes involved in schema validation. Reproduce the example application and compare the generated database with the inList constraints. Done means constraints are generated and dbCreate=validate reports missing or differing constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
database
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.