Skip to content

collectionConfigToVexSchema

collectionConfigToVexSchema(props): string

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

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 fields with an explicit field.index property
  • .index("by_<fieldKey>", ["<fieldKey>"]) auto-generated for every relationship field
  • .searchIndex() for text fields with field.searchIndex configured
  • .searchIndex("search_<useAsTitle>", { searchField: "<useAsTitle>", filterFields: [] }) auto-generated when another collection has a relationship pointing HERE and useAsTitle is not a Convex system field (_id, _creationTime), provided no manually configured search index already has that name.

Input props.

CollectionConfig

The resolved collection definition to convert.

VexConfig

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