Skip to content

Column Modifiers

Modifiers customize column behavior, validation, and documentation.

ModifierWhat it does
.optional()Allow NULL
.unique()Unique constraint
.default(value)Default for new rows
.backfill(value)Fill existing rows in migrations
.min(n)Minimum value/length
.max(n)Maximum value/length
.pattern(regex)Regex validation
.docs(text)SQL comment + OpenAPI description
schemas/catalog/product.js
export default table({
id: col.id(),
sku: col.string(20).pattern(/^[A-Z]{3}-\d{4}$/),
price: col.decimal(10, 2).min(0),
name: col.string(100).min(3).max(100),
});

Use .backfill() when adding required columns to existing tables.

schemas/auth/user.js
export default table({
id: col.id(),
email: col.email().unique(),
// New required column - backfill sets value for existing rows
tier: col.string(20).default("free").backfill("free"),
});

The .docs() modifier adds SQL comments and OpenAPI descriptions.

schemas/sales/order.js
export default table({
id: col.id(),
total: col.decimal(12, 2).docs("Order total in USD"),
});

Combine multiple modifiers in any order.

col.email().optional().unique().docs("User email address");