Skip to content

collectionConfigToVexSchema

collectionConfigToVexSchema(props): string

Defined in: packages/core/src/collections/validator.ts:161

Converts a resolved CollectionConfig to a Convex defineTable(...) source string.

Iterates the collection’s fields, builds each field’s Convex validator via adminFieldToValidator, and appends index chains:

  • .index() for every index resolveCollectionIndexes resolves — field-level indexes may be compound, and win over a collection-level entry of the same name
  • .searchIndex() for fields declaring their own field.searchIndex
  • a .searchIndex(...) for useAsTitle auto-generated when another collection has a relationship pointing HERE, via resolveTitleSearchIndex — reuses the useAsTitle field’s own searchIndex name when it has one, generates search_<useAsTitle> when it doesn’t, and is omitted entirely when useAsTitle is a Convex system field or a non-searchable field type

Input props.

CollectionConfig

The resolved collection definition to convert.

VexClientConfig

The full resolved VexCMS config, needed for cross-collection relationship detection.

string

A TypeScript source string declaring the Convex table.

const posts = defineCollection({
slug: "posts",
fields: { author: relationship({ collection: "authors", required: true }) },
});
collectionConfigToVexSchema({ collection: posts, config });
// → 'export const posts = defineTable({...})\n\t.index("by_author", ["author"])'
@see {@link generateVexSchema} for the full-file generator that wraps this function
@see {@link getIncomingRelationships} for the cross-collection helper
@see {@link resolveTitleSearchIndex} for the `useAsTitle` index-name resolution rule