ecto-changeset-patterns
Installation
SKILL.md
Ecto Changeset Patterns
RULES — Follow these with no exceptions
- Create separate named changesets per operation —
registration_changeset,email_changeset,password_changeset; never overload a singlechangeset/2 - Never require foreign key fields in
cast_assocchild changesets — the parent sets them automatically; requiring them causes "can't be blank" errors - Compose changesets with pipes — each validation step is a separate function for reuse and clarity
- Use
unsafe_validate_uniquepaired withunique_constraint— never one without the other;unsafe_validate_uniquegives fast UI feedback,unique_constrainthandles race conditions - Use
update_change/3for field transformations — trimming, downcasing, slugifying happen in the changeset, never in the controller or context - Accept
opts \\ []for conditional validation — allows callers to toggle validation rules without creating yet another changeset function - Validate at the changeset level, not in context functions — context functions should be thin wrappers around
Repocalls
Separate Changesets Per Operation
Different operations need different validation rules. Don't overload changeset/2.
Related skills
More from j-morgan6/elixir-phoenix-guide
oban-essentials
MANDATORY for ALL Oban work. Invoke before writing workers or enqueuing jobs.
1phoenix-json-api
MANDATORY for ALL JSON API work. Invoke before writing API controllers, pipelines, or JSON responses.
1ecto-essentials
MANDATORY for ALL database work. Invoke before modifying schemas, queries, or migrations.
1otp-essentials
MANDATORY for ALL OTP work. Invoke before writing GenServer, Supervisor, Task, or Agent modules.
1code-quality
Automated code quality detection — duplication, complexity, unused functions. Invoke when analyzing or refactoring Elixir code.
1phoenix-uploads
MANDATORY for file upload features. Invoke before implementing upload or file serving functionality.
1