pb-collections
できること
このスキルは、PocketBaseアプリのデータ構造を設定する手伝いをします。コレクション、フィールド、リレーションを含みます。PocketBaseで、きれいなデータベース設計をしたい開発者向けです。
使う場面
- ✓新しいコレクションを作成したり、既存のコレクションにフィールドを追加したりするとき。
- ✓2つのコレクションをリレーションでつなぐ必要があるとき。
- ✓ベース、認証、ビューのコレクションから選ぶ必要があるとき。
スキルのリンク
https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/pocketbase/pb-collections/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“ユーザー、投稿、コメントを持つ私のブログ用のPocketBaseのコレクションを設計し、適切につないでください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、各データに適したコレクションの種類とフィールドの型を選び、リレーションを設定します。既定値と、関連するレコードを削除したときのカスケード動作も示します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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.
-- 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/zerounique— unique constraint (composite via unique indexes)presentable— included in relation displayhidden— excluded from API responses unless explicitly requested:autogenerate— fortextfields: 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/passwordpasswordAuth.identityFields— fields used for login (default:email; can addusername)oauth2.enabled— toggle OAuth2otp.enabled— toggle OTP
Best Practices
- Prefer
selectoverboolwhen there might be more than 2 states in the future - Use
relationnottextfor foreign keys — you get cascade, expand, and type safety jsonfields are schemaless —
よくある質問
ビューのコレクションとは何ですか?
SQLクエリから作られる読み取り専用のコレクションです。結合や集計に役立ちます。
認証のコレクションとは何ですか?
ベースのコレクションに、メール、パスワード、認証済みの状態などのログイン用のフィールドを加えたコレクションです。
どんな間違いを避けるのに役立ちますか?
誤ったフィールドの型を防ぎ、ゼロの既定値の動作を文書化するように書かれています。
詳細
作者による元の説明
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.
人気
- GitHubのスター
- 33k
- ランキング
- #8871
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
owasp-security
33kエージェントがWebアプリ、API、モバイル、コンテナ、AIエージェント向けの OWASP のセキュリティ指針を理解し、よくある弱点を見つけて修正案を出せるよう支援します。
agent-management
33kエージェントが、AI Maestro のコマンドラインを使って AI エージェントを作成、一覧表示、休止、再開、名前変更、削除できるよう支援します。各エージェントのライフサイクルを管理します。
agent-messaging
33kエージェントが、主に自分のマシン上で Agent Messaging Protocol を使い、AIエージェント同士の署名付きメッセージを送信、受信、返信できるよう支援します。
docs-search
33kエージェントが、自動生成されたコードのドキュメントから関数の署名、クラスの定義、コメントを検索できるよう支援します。コードを変更する前に、実際のAPIを確認できます。
似ているスキル
api-connector-builder
280kエージェントが既存のパターンに従って、新しいAPI連携を構築します。新しい方式を作らずに、もう一つ連携を追加したいときに使います。
api-design
280kエージェントがベストプラクティスに沿ってREST APIを設計できるようにします。APIの通信方法、エラーの表示方法、データの整理方法を決めるのに役立ちます。
backend-patterns
280kエージェントのサーバーサイドのアーキテクチャパターンとデータベースの最適化を支援します。サーバー上で動くコードを作成またはレビューするときに役立ちます。