A comprehensive reference for Ecto database patterns in Phoenix apps. Covers the full stack: schemas with proper changeset validation paired with database constraints, safe migration practices including DDL lock management, transactional workflows with Ecto.Multi, and performance concerns like N+1 preloading. The multi-tenancy section alone (prefix-based vs row-based partitioning) is worth having on hand. Particularly strong on the "don't just validate in changesets, enforce it in the database" principle that trips up developers coming from ORMs in other languages. If you're building anything beyond a toy Phoenix app, you'll reference the transaction and constraint patterns regularly.

skills.sh installs
345
GitHub stars
79
last updated
Aug 21, 2026

Install

$ npx -y skills add bobmatnyc/claude-mpm-skills --skill ecto-patterns --agent claude-code

Installs into .claude/skills of the current project.

Files

Ecto Patterns for Phoenix/Elixir

Ecto is the data layer for Phoenix applications: schemas, changesets, queries, migrations, and transactions. Good Ecto practice keeps domain logic in contexts, enforces constraints in the database, and uses transactions for multi-step workflows.

Schemas and Changesets

defmodule MyApp.Accounts.User do
  use Ecto.Schema
  import Ecto.Changeset

  schema "users" do
    field :email, :string
    field :hashed_password, :string
    field :confirmed_at, :naive_datetime
    has_many :memberships, MyApp.Orgs.Membership
    timestamps()
  end

  def registration_changeset(user, attrs) do
    user
    |> cast(attrs, [:email, :password])
    |> validate_required([:email, :password])
    |> validate_format(:email, ~r/@/)
    |> validate_length(:password, min: 12)
    |> unique_constraint(:email)
    |> hash_password()
  end

  defp hash_password(%{valid?: true} = cs),
    do: put_change(cs, :hashed_password, Argon2.hash_pwd_salt(get_change(cs, :password)))
  defp hash_password(cs), do: cs
end

Sponsors

Details

Repository
github.com/bobmatnyc/claude-mpm-skills
Categories
Testing & QA, Debugging
First seen
Jun 3, 2026

More from bobmatnyc/claude-mpm-skills

All 158
1kazukinagata avatare-taxkazukinagata/shinkokuThis skill should be used when the user wants to file their tax return electronically via the 確定申告書等作成コーナー (NTA Tax Return Preparation Corner) using Claude in C342skills.sh installs
2jezweb avatarcloudflare-browser-renderingjezweb/claude-skillsAdd headless Chrome automation with Puppeteer/Playwright on Cloudflare Workers. Use when: taking screenshots, generating PDFs, web scraping, crawling sites, bro341skills.sh installs
3szeyu avatarexam-prepszeyu/vibe-study-skillsComprehensive exam preparation strategies and materials. Creates study schedules, review sheets, practice tests, and identifies weak areas. Use when preparing f341skills.sh installs
4octagonai avatarcommodities-listoctagonai/skillsRetrieve the full catalog of tradable commodities across energy, metals, and agriculture using Octagon MCP. Use when researching commodity markets, identifying 338skills.sh installs
5onewave-ai avataremail-subject-line-optimizeronewave-ai/claude-skillsA/B test subject line variations using proven copywriting frameworks. Predict open rates based on historical performance.337skills.sh installs
6patricio0312rev avatarrbac-permissions-builderpatricio0312rev/skillsImplements role-based access control with permission matrix, route guards, policy functions, and UI permission hints. Provides middleware/guards, helper utiliti333skills.sh installs