Skip to content

Commit 0273abf

Browse files
akoclaude
andcommitted
fix: reject INDEX on String(unlimited) in check --references
String(unlimited) maps to TEXT/CLOB which cannot be indexed in Mendix/RDBMS. The reference validator now checks index columns against attribute types and rejects unlimited strings with an actionable error message suggesting a fixed length. Also validates that index columns reference existing attributes. Closes #145 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2c71231 commit 0273abf

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

mdl/executor/validate.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ func (e *Executor) validateWithContext(stmt ast.Statement, sc *scriptContext) er
181181
}
182182
}
183183
// Validate enumeration references in attributes
184+
attrTypes := make(map[string]ast.DataType)
184185
for _, attr := range s.Attributes {
186+
attrTypes[attr.Name] = attr.Type
185187
if attr.Type.Kind == ast.TypeEnumeration && attr.Type.EnumRef != nil {
186188
enumRef := attr.Type.EnumRef
187189
// Check for missing module (common mistake - bare type name)
@@ -199,6 +201,18 @@ func (e *Executor) validateWithContext(stmt ast.Statement, sc *scriptContext) er
199201
}
200202
}
201203
}
204+
// Validate index columns
205+
for _, idx := range s.Indexes {
206+
for _, col := range idx.Columns {
207+
dt, exists := attrTypes[col.Name]
208+
if !exists {
209+
return fmt.Errorf("INDEX on unknown attribute '%s'", col.Name)
210+
}
211+
if dt.Kind == ast.TypeString && dt.Length == 0 {
212+
return fmt.Errorf("INDEX on attribute '%s' is not allowed — String(unlimited) maps to TEXT/CLOB which cannot be indexed. Use a fixed length, e.g. String(200)", col.Name)
213+
}
214+
}
215+
}
202216
case *ast.CreateAssociationStmt:
203217
if s.Name.Module != "" && !sc.modules[s.Name.Module] {
204218
if _, err := e.findModule(s.Name.Module); err != nil {

0 commit comments

Comments
 (0)