본문으로 건너뛰기
Skillpedia
API 및 서버 (백엔드)33k · #8871

pb-collections

하는 일

이 스킬은 PocketBase 앱의 데이터 구조를 설정하도록 돕습니다. 컬렉션, 필드, 관계를 포함합니다. PocketBase에서 깔끔한 데이터베이스 설계를 원하는 개발자에게 맞습니다.

사용하는 경우

  • ✓새 컬렉션을 만들거나 기존 컬렉션에 필드를 추가해야 할 때.
  • ✓관계(relation)로 두 컬렉션을 연결해야 할 때.
  • ✓기본(base), 인증(auth), 뷰(view) 컬렉션 중 골라야 할 때.

스킬 링크

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/pocketbase/pb-collections/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/pocketbase/pb-collections/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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/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 —
자주 묻는 질문

뷰 컬렉션이란 무엇인가요?

SQL 쿼리로 만들어진 읽기 전용 컬렉션이며, 조인과 요약에 유용합니다.

인증 컬렉션이란 무엇인가요?

기본 컬렉션에 이메일, 비밀번호, 인증 여부 같은 로그인 필드를 더하는 컬렉션입니다.

어떤 실수를 피하도록 돕나요?

잘못된 필드 타입을 막고 0 기본값 동작을 문서화하도록 작성되어 있습니다.

상세 정보

작성자의 원본 설명

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.

repo: davila7/claude-code-templates

인기도

GitHub 스타
33k
순위
#8871
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬