
Ecto Patterns
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-codeInstalls 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- Vercel Observability345
- Media Transcoding344
- Clap341
- Phoenix Ops341
- Prisma Orm341
- Graphql340
- Pre Merge339
- Vb6 Legacy338
- Vercel Functions Runtime338
- Vercel Overview338
- Vercel Security Access338
- Flexlayout React337
- Digitalocean Agentic Cloud334
- Artifacts Builder333
- Vercel Ai333
- Terraform332
- Validated Handler332
- Bad Example Skill329
- Emergency Release Workflow328
- Digitalocean Teams327
- Vector Search Workflows324
- Vercel Storage Data324
- Example Framework Skill323
- Vercel Teams Billing320