Column Modifiers
Modifiers customize column behavior, validation, and documentation.
Modifier Reference
Section titled “Modifier Reference”| Modifier | What 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 |
Validation Modifiers
Section titled “Validation Modifiers”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),});Migration Helpers
Section titled “Migration Helpers”Use .backfill() when adding required columns to existing tables.
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"),});Documentation
Section titled “Documentation”The .docs() modifier adds SQL comments and OpenAPI descriptions.
export default table({ id: col.id(), total: col.decimal(12, 2).docs("Order total in USD"),});Chaining Example
Section titled “Chaining Example”Combine multiple modifiers in any order.
col.email().optional().unique().docs("User email address");