ecto-changeset-patterns

Installation
SKILL.md

Ecto Changeset Patterns

RULES — Follow these with no exceptions

  1. Create separate named changesets per operationregistration_changeset, email_changeset, password_changeset; never overload a single changeset/2
  2. Never require foreign key fields in cast_assoc child changesets — the parent sets them automatically; requiring them causes "can't be blank" errors
  3. Compose changesets with pipes — each validation step is a separate function for reuse and clarity
  4. Use unsafe_validate_unique paired with unique_constraint — never one without the other; unsafe_validate_unique gives fast UI feedback, unique_constraint handles race conditions
  5. Use update_change/3 for field transformations — trimming, downcasing, slugifying happen in the changeset, never in the controller or context
  6. Accept opts \\ [] for conditional validation — allows callers to toggle validation rules without creating yet another changeset function
  7. Validate at the changeset level, not in context functions — context functions should be thin wrappers around Repo calls

Separate Changesets Per Operation

Different operations need different validation rules. Don't overload changeset/2.

Related skills
Installs
1
GitHub Stars
118
First Seen
Apr 21, 2026