Increase a text field's length
Increase an existing text field's capacity by changing its model and generating a new migration. This guide follows
the optional trackingCode field from Add a field; its recorded length is 80 characters.
Change the declared lengthโ
In src/main/jcm/model/Request.yml, change only trackingCode from length: 80 to length: 160:
entity: Request
instance-name: title
fields:
title: {type: text, length: 200, required: true}
receivedOn: {type: date}
urgent: {type: boolean, default: false}
urgencyReason: {type: text, length: 1000, label: Why it is urgent}
trackingCode: {type: text, length: 160}
A text-length increase does not need changed: true. Keep the field name and column mapping. Renaming a field or
changing text to another type is a different migration; changed: true is not a general conversion switch.
jcm changelog
git diff -- src/main/jcm/model src/main/resources
git status --short
Inspect the newly created XML file. It should alter TRACKING_CODE to text length 160 and leave unrelated columns
alone. When the column has an index or foreign key, the generated migration handles those dependencies; do not
simplify it by deleting generated operations. Keep the older changelogs unchanged.
Check the new capacityโ
Update the field's persistence test to save and reload a value longer than the old limit and within the new limit, such as 120 characters. Keep a short-value case too. Review any separately declared form, integration or import validation that still limits input to 80 characters.
jcm check
All four stages should pass. Before deploying, rehearse the upgrade from the prior schema on the intended database
family with invented rows already present. Confirm their values are unchanged, and then store/reload a value over
80 characters. A fresh empty database with the new schema is useful evidence, but does not exercise the alteration
of a populated table. Commit the model, new migration, schema.json and tests together.
If you meant to shorten itโ
A shorter text length is a narrowing operation. JCM refuses it without changed: true, and its generated migration
refuses rows whose values would be lost. First identify and resolve those values under the application's data
policy; do not assume the database will truncate them for you. Once a generated migration has partly run, preserve
it and follow its refusal rather than editing away the guard. Remove a completed changed: true mark so a later
narrowing needs a new explicit decision. See the full
migration rules before narrowing or changing decimal precision/scale.