serverpod-migrations

Generate and apply SQL migrations from `.spy.yaml` model changes.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents schema drift and broken deployments by guiding you through creating, applying, and repairing Serverpod database migrations when your .spy.yaml models change.

Core Features & Use Cases

  • Generate migrations from model changes: Creates SQL migrations when tables, fields, relations, or indexes defined with table in .spy.yaml are added, removed, renamed, or modified.
  • Apply migrations in the right lifecycle: Supports applying migrations via the serverpod MCP tool during development, or via dart run bin/main.dart --apply-migrations when starting the server.
  • Repair inconsistent database states: Uses serverpod create-repair-migration and then applies the repair migration through the CLI restart flag when the database is inconsistent.

Quick Start

Tell the AI: "Create a migration for my latest .spy.yaml changes using the MCP flow, then apply it with apply_migrations so my running Serverpod stays in sync with the database."

Frequently Asked Questions about serverpod-migrations

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

FAQPage Schema
How do I create database migrations when my Serverpod yaml models change?

Serverpod database migrations are generated by detecting changes to tables, fields, relations, or indexes in your `.spy.yaml` models and creating the corresponding SQL migration files. You can trigger this using the `serverpod` MCP tool during development.

What is the best way to apply Serverpod migrations in a production deployment?

The best way to apply Serverpod migrations during production deployment is by starting the server with the `dart run bin/main.dart --apply-migrations` command. This ensures your database schema stays in sync when the server launches.

How do I repair a Serverpod database when the schema is inconsistent?

To repair an inconsistent Serverpod database, generate a repair migration using the `serverpod create-repair-migration` command, then apply it by restarting the server with the `--apply-repair-migration` CLI flag.

Does Serverpod generate SQL migrations automatically from ORM models?

Yes, Serverpod generates SQL migrations automatically from your ORM models. When you modify `table` definitions in your `.spy.yaml` files, it derives the necessary SQL schema changes to prevent drift.

When should I skip Serverpod database migration operations?

You should skip Serverpod migration operations when no database is configured for your application. The migration workflow is only necessary when your project relies on a database to store its data.

Why does my Serverpod deployment suffer from schema drift after model updates?

Schema drift occurs when `.spy.yaml` model changes are not translated into applied SQL migrations. Prevent broken deployments by generating migrations from your model updates and applying them via the MCP tool or server startup command.