PocketBase Collections
Collection and schema design for PocketBase. Use when creating collections, designing schemas, adding fields, setting up relations, or choosing between base/auth/view collection types. Prevents wrong field types, documents zero-default behavior, and covers relation cascading.
Best use case
PocketBase Collections is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Collection and schema design for PocketBase. Use when creating collections, designing schemas, adding fields, setting up relations, or choosing between base/auth/view collection types. Prevents wrong field types, documents zero-default behavior, and covers relation cascading.
Teams using PocketBase Collections should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/pb-collections/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How PocketBase Collections Compares
| Feature / Agent | PocketBase Collections | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Collection and schema design for PocketBase. Use when creating collections, designing schemas, adding fields, setting up relations, or choosing between base/auth/view collection types. Prevents wrong field types, documents zero-default behavior, and covers relation cascading.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
SKILL.md Source
# PocketBase Collection & Schema Design ## Collection Types ### Base Collection Standard data collection. System fields: `id`, `created`, `updated`. ### Auth Collection Extends base with authentication. Additional system fields: `email`, `emailVisibility`, `verified`, `password`, `tokenKey`. Cannot delete system fields. Can disable email/password auth in collection options. ### View Collection Read-only, backed by a SQL SELECT query. No create/update/delete. Fields are auto-detected from the query. Useful for aggregations, joins, and computed views. ```sql -- Example: view collection query SELECT p.id, p.title, COUNT(c.id) as comments_count FROM posts p LEFT JOIN comments c ON c.post = p.id GROUP BY p.id ``` View collections support API rules (list/view only) and can be used in relations. ## Field Types | Type | Go type | Zero default | Notes | |------|---------|-------------|-------| | `text` | `string` | `""` | min/max length, regex pattern | | `editor` | `string` | `""` | Rich text (sanitized HTML) | | `number` | `float64` | `0` | min/max, `noDecimal` option | | `bool` | `bool` | `false` | | | `email` | `string` | `""` | Auto-validated format | | `url` | `string` | `""` | Auto-validated format | | `date` | `string` | `""` | ISO 8601 (`2024-01-01 00:00:00.000Z`) | | `select` | `string`/`[]string` | `""`/`[]` | `values` list, `maxSelect` | | `file` | `string`/`[]string` | `""`/`[]` | `maxSelect`, `maxSize`, `mimeTypes` | | `relation` | `string`/`[]string` | `""`/`[]` | `collectionId`, `cascadeDelete`, `maxSelect` | | `json` | `any` | `null` | Only type that can be null! `maxSize` | | `autodate` | `string` | auto | `onCreate`/`onUpdate` modifiers | | `password` | `string` | `""` | Stored hashed, never returned in API | **Critical**: all types default to their zero value, NOT null. Only `json` fields can be null. ## Field Modifiers Use in collection schema definitions: - **`required`** — field cannot be empty/zero - **`unique`** — unique constraint (composite via unique indexes) - **`presentable`** — included in relation display - **`hidden`** — excluded from API responses unless explicitly requested - **`:autogenerate`** — for `text` fields: auto-generate value (e.g., slug from other field) ## Relation Patterns ### One-to-many ``` posts.author -> users (maxSelect: 1) ``` Each post has one author. Query posts by author: `author = "USER_ID"`. ### Many-to-many ``` posts.tags -> tags (maxSelect: 0, meaning unlimited) ``` Multi-select relation. Filter: `tags ?= "TAG_ID"` (contains). ### Back-relations No explicit back-relation field needed. Use `@collection.posts.author` in API rules or expand from either side: ``` GET /api/collections/users/records/USER_ID?expand=posts_via_author ``` ### Cascade Delete Set `cascadeDelete: true` on the relation field. When the referenced record is deleted, all records pointing to it are also deleted. Default is `false` (sets to empty string). ### Self-referencing A collection can reference itself: ``` categories.parent -> categories (maxSelect: 1) ``` ## Indexes - Created in the collection settings (not field-level) - Format: `CREATE [UNIQUE] INDEX idx_name ON collection (field1, field2)` - Unique indexes enforce composite uniqueness - Partial indexes: `CREATE INDEX ... WHERE condition` - Indexes on relation fields improve join performance ## Auth Collection Specifics ### OAuth2 Enable per-provider in collection settings. Each provider needs client ID + secret. PocketBase handles the full OAuth2 flow. ### OTP (One-Time Password) Enable in auth collection settings. Sends code via email. Configure `otp.enabled`, `otp.duration`, `otp.length`. ### MFA (Multi-Factor Authentication) Enable in auth collection settings. Requires a second factor after primary auth. `mfa.enabled`, `mfa.duration`, `mfa.rule` (filter to determine which users need MFA). ### Password Auth Enabled by default. Can customize `minPasswordLength`. Can disable entirely if using only OAuth2/OTP. ### Auth Options - `authToken.duration` — token lifetime (seconds) - `passwordAuth.enabled` — toggle email/password - `passwordAuth.identityFields` — fields used for login (default: `email`; can add `username`) - `oauth2.enabled` — toggle OAuth2 - `otp.enabled` — toggle OTP ## Best Practices 1. **Prefer `select` over `bool`** when there might be more than 2 states in the future 2. **Use `relation` not `text`** for foreign keys — you get cascade, expand, and type safety 3. **`json` fields** are schemaless — use sparingly, prefer typed fields 4. **Name collections** in lowercase snake_case (e.g., `blog_posts`, `user_profiles`) 5. **Index early** — add indexes for any field used in filters or sorts 6. **`maxSelect: 1`** on relations returns a string ID; **`maxSelect: >1` or `0`** returns an array
Related Skills
PocketBase SDK
JavaScript SDK usage for PocketBase client applications. Use when calling PocketBase from frontend or Node.js, authenticating users, subscribing to realtime events, uploading files, or working with the PocketBase JS/TS SDK. Covers CRUD, auth flows, authStore, realtime SSE, file handling, batch operations, and query syntax.
PocketBase Migrations
Schema migrations and versioning for PocketBase. Use when creating migrations, managing schema versions, syncing collections between environments, using automigrate, or creating collections programmatically. Covers migrate commands, migration file format, snapshot imports, and the _migrations tracking table.
PocketBase Hooks
Server-side JavaScript hooks for PocketBase (pb_hooks). Use when writing custom routes, event hooks, cron jobs, sending emails, making HTTP requests, querying the database, or extending PocketBase with server-side logic. Covers the goja ES5 runtime, routing, middleware, all event hooks, DB queries, record operations, and global APIs.
PocketBase Deploy
Production deployment for PocketBase. Use when deploying PocketBase to a server, setting up Docker, configuring systemd, reverse proxy (nginx/Caddy), TLS, SMTP, backups, S3 storage, rate limiting, or hardening for production. Provides ready-to-use configs.
PocketBase API Rules
API rules and filter expressions for PocketBase access control. Use when setting permissions, writing filter expressions, configuring who can access what, or debugging 403/404 responses. Covers all 5 rule types, filter syntax, operators, request/collection macros, and field modifiers.
async-python-patterns
Comprehensive guidance for implementing asynchronous Python applications using asyncio, concurrent programming patterns, and async/await for building high-performance, non-blocking systems.
slack-automation
Automate Slack workspace operations including messaging, search, channel management, and reaction workflows through Composio's Slack toolkit.
linear-automation
Automate Linear tasks via Rube MCP (Composio): issues, projects, cycles, teams, labels. Always search tools first for current schemas.
jira-automation
Automate Jira tasks via Rube MCP (Composio): issues, projects, sprints, boards, comments, users. Always search tools first for current schemas.
gitops-workflow
Complete guide to implementing GitOps workflows with ArgoCD and Flux for automated Kubernetes deployments.
github-automation
Automate GitHub repositories, issues, pull requests, branches, CI/CD, and permissions via Rube MCP (Composio). Manage code workflows, review PRs, search code, and handle deployments programmatically.
github-actions-templates
Production-ready GitHub Actions workflow patterns for testing, building, and deploying applications.