Repository navigation
Description
Summary
@expr is registered on both index.lookup and identity.secondary, the migrate engine
builds it, and the Postgres emitter renders it — but the loader's @fields requirement
makes it unreachable as documented. The registry describes @expr as:
Raw key EXPRESSION for a functional/expression index (e.g.
lower(email)). Used
INSTEAD of@fields— the index key is the expression rather than plain columns.
Yet omitting @fields fails to load on both node types, and the one spelling that does
load (@fields and @expr) silently discards the declared fields.
Net effect: an expression index cannot be expressed in metadata. An adopter has to keep it
as hand-written SQL outside the migration ledger, which then shows up as permanent
verify --db drift.
Version: 0.24.0 (npm @metaobjectsdev/[email protected]; same result via the Python package).
Reproduction
Entity with a jsonb column, targeting Postgres:
{ "object.entity": { "name": "Notification", "children": [
{ "source.rdb": { "@table": "notifications" } },
{ "field.string": { "name": "id", "@required": true } },
{ "field.timestamp": { "name": "delivered_at" } },
{ "field.string": { "name": "payload", "@dbColumnType": "jsonb", "@required": true } },
{ "identity.primary": { "name": "pk", "@fields": ["id"] } },
{ "index.lookup": { "name": "pending_device_idx",
"@expr": "(payload->>'device_id')",
"@where": "delivered_at IS NULL" } }
] } }meta verify →
failed to load metadata: index.lookup "pending_device_idx" on "Notification"
has no @fields; at least one field is required
Matrix
| Node | attrs | Result |
|---|---|---|
index.lookup |
@expr only |
❌ has no @fields; at least one field is required |
identity.secondary |
@expr only |
❌ is missing required attribute '@fields' |
index.lookup |
@fields + @expr |
✅ loads — but @fields is silently dropped |
The third row is the concerning one. With @fields: ["delivered_at"] and
@expr: "(payload->>'device_id')", the emitted schema snapshot
(.metaobjects/migrations/.schema.postgres.json) records:
{ "columns": [], "expr": "(payload->>'device_id')", "name": "t2", "unique": false }columns: [] — the declared field is gone, with no error and no warning. So the only
spelling that loads is one where part of the declaration is quietly ignored.
Why this looks like a validation gap rather than a missing feature
The capability is already implemented downstream of the loader:
migrate-tsexpected-schema.js— "An expression index keys off@expr(not
@fields); a plain index needs@fields", and it setsindex.exprfor both
index.lookupandidentity.secondary.migrate-tsemit/postgres.js— rendersCREATE [UNIQUE] INDEX … (keys)[ WHERE …],
honoring@using/@where.- Introspection reads expression keys back (
pg_get_expr), so drift comparison is
already expression-aware. - The SQLite/D1 introspectors have explicit expression-index handling too, and a past fix
restored@expr/@where/@ordersthere — so expression indexes are clearly intended
to work end to end.
expected-schema.js already branches on "expression index vs plain index", so the
requirement that a plain index needs @fields appears to have been applied unconditionally
at the loader instead of being waived when @expr is present.
Suggested fix
Treat @fields as required unless @expr is present, on both index.lookup and
identity.secondary — matching what expected-schema.js already does. Then either:
- reject
@fields+@exprtogether as a contradiction (fail closed, since one is
currently discarded), or - define and document a precedence rule.
Failing closed seems more consistent with the sealed-strict-registry posture: today the
combination is accepted and half-honored, which is the silent-wrong-output case the strict
loader generally exists to prevent.
Docs
If the @fields-always requirement is intentional, then the @expr description ("Used
INSTEAD of @fields") is wrong on both node types and should say what the supported
spelling actually is.
Activity
fix(metamodel): the index key is @fields XOR @expr, in all five ports (…
fix(metamodel): close the holes review found in the #342 XOR rule (#342)
fix(codegen-ts): emit a shared enum's TYPE as a type-only import (#341)
docs(llms): correct the retired requirement vocabulary (#343)
docs(changelog): 0.24.1 records the adopter batch — #339, #340, #341, #…
docs(changelog): name 0.24.1 as the sole claimant of metamodelVersion…
dmealing commentedon Aug 23, 2026
Fixed on
mainin e96bbe3 + 6de4013, shipping in0.24.1.The index key is
@fieldsXOR@exprin all five ports:@expralone now loads,@fieldsalone still loads, and declaring BOTH is now an error rather than silentlydiscarding
@fields.metamodelVersionmoves0.10→0.11for the@fieldsrelaxation.
feat(gates): shipped metadata examples must load under the strict reg…
docs(changelog): 0.24.1 absorbs #335, ships metamodelVersion 0.12, an…
fix(metadata,cli): meta upgrade repairs the @fields + @expr index key (…
docs(skills): the audit + verify skills catch up with the requirement…
feat(metamodel): @status: retired restores the requirement guardrail …
fix(scripts): the doc-example gate never counted what it couldn't parse
docs(1.0): retire the quiet period; ratify the correction bar that re…
docs: three corrections to yesterday's ruling, found by re-reading th…
fix(migrate-ts): the one @expr spelling a human writes was the one th…