The data contract
Your contract is the file where you declare models, their fields and how they relate. Everything else — migrations, the client, its types — is generated from it.
A first contract
import { model, id, text, email, timestamp, relation } from "@strata/contract";export const User = model("User", { id: id(), email: email().unique(), name: text().optional(), posts: relation.many(() => Post),});export const Post = model("Post", { id: id(), title: text(), published: boolean().default(false), author: relation.one(() => User), createdAt: timestamp().defaultNow(),});Field types
Builder | PostgreSQL | SQLite | TypeScript |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Modifiers
.optional()makes the column nullable and the fieldT | null.unique()adds a unique index.default(value)and.defaultNow()set a database default.map("column_name")keeps a legacy column name
Renaming a field without .map() drops the column and creates a new one. strata migrate dev warns you before it does; strata migrate deploy does not ask.
Updated
Was this page helpful?