docs: document checks examples + migrations naming convention (#13052)

This commit is contained in:
Shahed Nasser
2025-07-25 17:22:37 +03:00
committed by GitHub
parent b40b2ff676
commit 5a01ef89ea
5 changed files with 189 additions and 5 deletions
@@ -58,6 +58,32 @@ const Post = model.define("post", {
export default Post
```
#### Limit Text Length
To limit the allowed length of a `text` property, use the [checks method](../check-constraints/page.mdx).
For example, to limit the `name` property to a maximum of 50 characters:
export const textLengthHighlights = [
["7", "checks", "Add check constraints to the data model."],
]
```ts highlights={textLengthHighlights}
import { model } from "@medusajs/framework/utils"
const Post = model.define("post", {
name: model.text(),
// ...
})
.checks([
(columns) => `${columns.name.length} <= 50`,
])
export default Post
```
This will add a database check constraint that ensures the `name` property of a record does not exceed 50 characters. If a record with a longer `name` is attempted to be inserted, an error will be thrown.
### number
The `number` method defines a number property.