Add a field to a running model
Adding a field to a type whose table already holds data should be as easy as adding the field to the model and reloading. Today it is hand SQL: create-tables (lisp/model.lisp) probes information_schema per table and creates only what is missing, so an existing table is never altered, and the reload is snapshot, fresh process, set-model, hand SQL (docs/migration.md).
Scope, settled by Donnie on 2026-11-29: the reload path adds new nullable columns, and everything else stays hand SQL. This item replaces "Migrations when the model changes" (slot 15500), retired the same day as too general.
The ask
- On every pass of the reload path, each model field with no column in its existing table gets an
alter table … add column, nullable. The reload path is wherevercreate-tablesruns:set-modelon a fresh process, andheal-model. "Separate index creation" (slot 8300) does the same for indexes. - Everything else is left for hand SQL and is reported, so nobody diffs the model against the table to find it: a changed column type, a new
:not-nullfield, a renamed or dropped field (its old column stays), a changed identity index. - For the plan: whether a new reference field (a nullable column plus its foreign key) rides along in the first cut.
What changes in practice
- A deploy is a fresh process, so in production the path becomes: snapshot, edit the model, bump
:version, commit, deploy, and the columns are there. - New types and new join tables need no SQL today and still need none.
- Unchanged: loading a changed model file on a live image still takes a restart, because
heal-modelcannot re-read the file.
First consumers: a caption column on Model Bank :images ("Authored image captions", slot 7177), and the blog's later columns.
The settings headache, for context. Settings are per-user, and no app-wide home takes a new value easily ("App settings", slot 29900). Three kinds of value, three homes. A field on an existing type is a column: this item. A model key (:title, and the blog's :publisher) is an edit and a reload, with no table. A :styling slot is editable in the app but frozen to banner, footer and heading.
Tests: an existing table gains the new column and keeps its rows; a second pass adds nothing; a :not-null field is reported and not added.
- Slot
- 7600
- Status
- 10 Open
- Tags
- mvp, backend, scripts, mig, setting
- Contributors
- Donnie, Sofia