PocketBase Migrations

Creates and manages PocketBase schema migrations, collection definitions, and versioned database snapshots.

30.5k|3.5k|Updated Jul 4, 2025
One-click install
npx skills add https://github.com/davila7/claude-code-templates --skill pocketbase-migrations
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: PocketBase Migrations
Source: https://github.com/davila7/claude-code-templates/tree/main/cli-tool/components/skills/pocketbase/pb-migrations
Command: npx skills add https://github.com/davila7/claude-code-templates --skill pocketbase-migrations

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Managing PocketBase schema changes across development, staging, and production environments is error-prone when done manually through the Dashboard. This Skill provides the commands, file formats, and patterns needed to version-control schema changes, sync collections between environments, and roll back failed migrations safely.

Core Features & Use Cases

  • Migration CLI Workflows: Create, apply, revert, and snapshot migrations using migrate create, migrate up, migrate down, migrate collections, and history-sync.
  • Programmatic Collection Definitions: Write migration files that define base, auth, and view collections with fields, indexes, API rules, and auth settings in JavaScript.
  • Environment Sync & Seeding: Use auto-migrate in development, disable it in production with --automigrate=0, snapshot schemas with importCollections, and seed superusers or settings via migrations and onBootstrap.
  • Use Case: You designed collections in the Dashboard during development and now need to deploy to production. Commit the auto-generated pb_migrations/ files, deploy with auto-migrate disabled, and migrations run automatically on server start.

Quick Start

Ask the assistant to create a PocketBase migration that adds a posts collection with title, body, and author relation fields including a reversible down migration.

Frequently Asked Questions about PocketBase Migrations

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

FAQPage Schema
How do I create a PocketBase migration?

Run `./pocketbase migrate create "migration_name"` to generate a timestamped JavaScript file in `pb_migrations/`. Write your schema changes in the up function and the reversal logic in the down function, then apply it with `./pocketbase migrate up`.

How do I sync PocketBase collections between environments?

Use `./pocketbase migrate collections` to generate a full snapshot migration of all current collections, commit it to git, and deploy. On the target environment, migrations run automatically on server start, or use `migrate history-sync` when importing an existing database.

Should I disable automigrate in PocketBase production?

Yes, run production with `./pocketbase serve --automigrate=0` so Dashboard changes do not generate new migration files. Develop with auto-migrate enabled, commit the generated files, and let committed migrations apply on startup in production.

Can I run raw SQL in PocketBase migrations?

Yes, use `app.db().newQuery("ALTER TABLE ...").execute()` inside a migration for raw SQL. Be aware that raw SQL bypasses the schema cache, so run `migrate collections` afterward to re-sync if needed.

Why did my PocketBase migration roll back?

The `app` instance inside migrations is transactional, so any thrown error rolls back the entire migration. Common causes include referencing a nonexistent collection ID in relation fields or missing required environment variables like PB_ADMIN_EMAIL.