Add a resource for an existing Prisma model
Add a resource for an existing Prisma model
Files to touch: resources/<name>/resource.json
Steps
1. Generate a stub
Run crouton update to introspect the Prisma schema and generate stubs for any models that do not yet have a resource:
npx crouton update resourcesThe CLI prompts you to confirm each new resource and skips existing ones. Accept the ones you want. The result is a directory like:
resources/book/
βββ resource.json β generated stub
βββ schema.ts β generated Zod model (do not edit by hand)Alternatively, create the files manually with crouton create resource:
npx crouton create resource book --title "Books"2. Set required fields
Open resource.json and verify:
namematches the folder name (e.g."book"inresources/book/)modelis the exact Prisma model name (case-sensitive, e.g."Book")titleis the human-readable label for the sidebar and page heading
3. Validate
npx crouton validate resources resources/book/resource.jsonFix any reported issues, then run the command again until it passes.
4. Add to the sidebar
By default the resource appears in the sidebar alphabetically. To set an explicit position or group:
"sidebar": { "label": "Books", "group": "catalogue", "position": 1 }Groups are defined in crouton.json under sidebarGroups.
Complete example
The book resource from the book-collection example β a Prisma model with searchable/sortable columns, an enum status field, an autocomplete relation, and a manyToMany relation:
{
"$schema": "https://ghentcdh.github.io/crouton/schema/v1/resource.schema.json",
"schemaVersion": 1,
"name": "book",
"source": {
"model": "Book"
},
"title": "Books",
"columns": {
"id": {
"idField": true,
"hiddenInForm": true
},
"title": {
"sortable": true
},
"isbn": {
"sortable": true
},
"publishedYear": {
"type": "integer",
"sortable": true
},
"status": {
"enum": "bookStatus"
},
"summary": {
"fieldInput": {
"type": "textarea"
},
"hiddenInTable": true
},
"authorId": {
"label": "Author",
"relation": {
"resource": "./author.resource",
"type": "manyToOne"
},
"fieldInput": {
"type": "autocomplete"
}
},
"categories": {
"label": "Categories",
"relation": {
"resource": "./category.resource",
"type": "manyToMany"
},
"hiddenInTable": true
}
},
"operations": {
"findAll": {
"include": [
"author",
"categories"
],
"search": [
"title",
"authorId"
],
"filter": [
"title",
"status"
]
}
}
}What crouton update owns vs what you own
crouton update regenerates schema.ts and may add new columns it detects in the Prisma schema. It will not overwrite field-level config you have set (fieldInput, relation, label, etc.) β but it will add columns you have not seen yet. Review the diff each time before accepting.
See Decision tables for the full breakdown.