Skip to Content
Droot Developers

Changing a Field's Type

Changing a field's type: locked fields, structural customisations, and the routes.

A tenant can change the type of a field or a table column, an app's included: every stored value is converted (text to a dropdown, a number to an amount, a date to a date and time…). For an app's field or column the change is a structural customisation of the installed row, which the app's updates may change back. This page is what an app developer needs to know about it: how to keep a field out of it, what the customisation looks like, and the routes.

Keeping a field's type: locked

A field in the bundle's fields.json may say that the app's code relies on its type:

{ "modelKey": "fleet.trip", "fieldKey": "distanceKm", "label": "Distance", "type": "number", "locked": true }

A locked field can't change type on any server (Setup's Change Type, Droot AI and the API refuse it, saying the app's code relies on it). Without locked, the platform still refuses the change when it can tell your app relies on the type:

  • the field is a flow's status field, or the model's title field;
  • one of your app's scripts reads it;
  • a unit of your package code (code/code.json) that runs on the model (model, or a records.read: or records.write: scope on it) names the field in its file.

A package code unit on the model that doesn't name the field, and your server module (server/index.js, which declares nothing and is minified), are named in a warning the administrator reads before changing it. Mark a field locked when your code reads it as its type in a way none of these show.

The structural customisation

The installed row is never edited. The change is a delta (metadata_overrides) marked structural:

{ "kind": "field", "targetKey": "fleet.trip:distanceKm", "set": { "type": "text", "unit": null },
  "structural": { "keys": ["type", "unit"], "base": { "type": "number", "unit": null } } }

structural.base is your row's type and type settings when the tenant changed them; a table field's retyped columns are listed in structural.columns (your other columns stay yours, and a column you add arrives beside them). A contributed table column (table-column) is retyped through its column.

When an update changes what the tenant retyped (its type, choices, money settings, or the column), the update's inspection lists it before it installs (finding customisation-retyped, with the tenant's type, yours before and yours in the release). After the update the delta is a conflict in Setup › Customize › Review After Upgrade: its type still applies (the values are stored that way) until the administrator chooses Keep Mine or Take New, which converts the values to your type through the same conversion. A plain revert of a structural delta is refused.

A structural customisation travels with the tenant's other customisations: in the app's customisations document (GET /api/admin/apps/:app/deltas, with structural) and in a configuration changeset (config.promote). On the target it is never written as it stands: it is applied as a type change of that server's values, refused (and named per item in Compare and the dry run) while one doesn't convert. Rolling the promotion back converts them back.

Routes

Every route needs metadata.write and every company.

Route What it does
GET /api/admin/models/:key/fields/:field/type-change[?column=] The types it may become (or why it can't change), the warnings, its past changes
POST …/type-change/preview { to, column?, options?, optionMap?, money?, unconverted? }: what converts, examples of what doesn't, what would break. Writes nothing
POST …/type-change Applies it: 200 when converted at once, 202 when a background job converts (inbox_field_type_changes); 409 while something blocks it or a value doesn't convert (unconverted: "clear" clears those, kept for undo). takeNew: true is Review After Upgrade's Take New
POST …/type-change/keep { column? }: Keep Mine for a structural delta in conflict
GET /api/admin/type-changes/:id A change's progress
POST /api/admin/type-changes/:id/undo Undo for 30 days: the old type and values back. Every value is checked first, in batches; 409 when one written since can't go back