Skip to content

versionFieldsToVexSchema

versionFieldsToVexSchema(props): object

Defined in: packages/core/src/versions/schema.ts:67

The generated-schema source lines a versioned table needs: the three vex_* system fields and the two indexes every draft-aware query reads through (by_status for the published-only filter, by_published for findDraftRow).

Returns LINES rather than a finished table string because its two callers build their tables differently — collectionConfigToVexSchema (collections/validator.ts) accumulates fieldsBlock/indexes arrays from a CollectionConfig, while generateVexSchema hand-writes the vex_globals block as a literal line array (a global is not a CollectionConfig and never passes through the former). Emitting lines lets both splice into what they already have instead of re-parsing a string one of them just produced.

Input props.

string

The table these lines are emitted into. Also the target of the self-referential vex_publishedId: a draft row always points back at a published row in this SAME table, globals included (design-review §9 treats a global’s draft as another vex_globals row).

object

fields — object-literal member lines, tab-indented and comma-terminated to match the field lines around them; indexes — .index(...) chain lines, tab-indented to match the existing chain.

Never checks versions.drafts itself — each caller owns that branch, since each already holds the config and neither wants a no-op call on the common non-versioned path.

fields: string[]

indexes: string[]

const { fields, indexes } = versionFieldsToVexSchema({ tableName: "posts" });
fieldsBlock.push(...fields);
collectionIndexes.push(...indexes);