serverpod-models

Define Serverpod data models in YAML to generate Dart classes and database tables.

3.2k|369|Updated May 22, 2021
One-click install
npx skills add https://github.com/serverpod/serverpod --skill serverpod-models
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serverpod-models
Source: https://github.com/serverpod/serverpod/tree/main/packages/serverpod/skills/serverpod-models
Command: npx skills add https://github.com/serverpod/serverpod --skill serverpod-models

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Serverpod data models are the foundation for type-safe serialization and ORM-backed database access, and this skill streamlines defining them in a single YAML source of truth.

Core Features & Use Cases

  • Model definition in YAML (.spy.yaml): Create server and client Dart code from declarative model schemas.
  • Serialization and schema generation: Generate serialization behavior, optional database tables, relations, enums, and exceptions.
  • Database alignment via migrations: Ensure schema changes are propagated through the migration workflow when table definitions change.
  • Common use cases: Define new entities, update fields safely for backward compatibility, add relations (one-to-one, one-to-many, many-to-many), and model custom exceptions sent to clients.

Quick Start

Update or create your model in a .spy.yaml file under your server lib/ directory, then run serverpod generate and (if tables changed) apply the corresponding migrations workflow from serverpod-migrations.

Frequently Asked Questions about serverpod-models

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define Serverpod models in YAML for serialization and ORM tables?

You define Serverpod models by creating declarative schemas in a .spy.yaml file under your server lib/ directory. This YAML source of truth generates Dart server and client classes, serialization logic, and optional database ORM tables.

How do I add database relations like one-to-many or many-to-many in Serverpod?

You add database relations by declaring them directly in your Serverpod model YAML files. This allows you to model one-to-one, one-to-many, and many-to-many relations, which are then generated into Dart classes and ORM table definitions.

Do I need to run database migrations when updating Serverpod model fields?

Yes, you must run database migrations whenever your table definitions change. After updating your .spy.yaml model, run serverpod generate and apply the corresponding migrations workflow to ensure safe backward-compatible schema evolution.

Can I define custom exceptions and enums in Serverpod YAML models?

Yes, you can define custom serializable exceptions and enums in your .spy.yaml files. These definitions are processed to generate corresponding Dart classes that can be safely sent across the server and client protocol layers.

What are scoped or non-persisted fields in Serverpod data models?

Scoped and non-persisted fields are model attributes defined in your YAML that exist across protocol layers but are excluded from the generated database ORM tables. They allow you to transmit data without altering the database schema.

What is the best way to ensure backward compatibility when modifying Serverpod models?

To ensure backward compatibility, you must apply safe field typing and evolution rules when modifying your .spy.yaml files. Any structural table definition changes must be aligned with the database migration workflow to prevent schema conflicts.