mcpField
E
ecto-essentials

ecto-essentials

github.com/igmarinDevelopment538 installsUpdated 4w ago
Repository

About ecto-essentials

ecto-essentials is a skill for applying repository conventions to Ecto schemas, queries, and database writes. It guides developers to keep business rules in contexts or domain modules and database access at the persistence edge.

Key features

  1. 01Validate external input with changesets
  2. 02Use parameterized, composable queries
  3. 03Guide association preloading
  4. 04Choose transaction patterns for writes
  5. 05Test persistence changes

Use cases

  1. 01Adding or updating Ecto schemas
  2. 02Building safe database queries
  3. 03Implementing multi-step database writes
  4. 04Changing persistence behavior and its tests

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/igmarin/elixir-phoenix-skills --skill ecto-essentials

After installing, type/ecto-essentialsin Claude Code to confirm it loaded.

Bundled filesassets/changeset_snippets.exassets/migration_checklist.md

Details

From the project README

Ecto Essentials

Follow the repository's Ecto and database conventions. Keep business rules in the context or pure domain modules; keep Repo calls at the persistence edge.

Schemas and changesets

  • Model persisted data in schemas and validate external input with changesets.
  • Use cast/3 with an explicit field allowlist for external maps. Use change/2 for trusted internal updates.
  • Attach database constraints to changesets with unique_constraint/3, foreign_key_constraint/3, or the matching constraint helper so expected database errors return changeset errors.
  • Keep association ownership and delete behavior explicit. Use cast_assoc/3 only when nested input is part of the public operation.

Queries and associations

  • Compose Ecto.Query fragments with named bindings and parameterized values. Never interpolate user input into SQL.
  • Keep reusable filters and ordering in query functions; keep policy and orchestration in the context.
  • Preload what the caller needs. For lists, inspect query counts and prefer joins or batched preloads over per-row Repo.get/2 calls.
  • Use Repo.one/1, Repo.all/1, and bang variants according to the caller's expected absence and error contract.

Writes and transactions

  • Return {:ok, value} / {:error, changeset_or_reason} from expected failures.
  • Use Ecto.Multi when a transaction has multiple named steps or its failure step matters to the caller. Use a normal transaction for a small atomic block.
  • Do not put network calls or other irreversible side effects inside a database transaction.
  • For upserts, state the conflict target and verify the database constraint matches it.

Verification

Add or update tests for the changed persistence behavior. Run the focused test, then the project checks that cover Ecto and migrations. Use ecto-changeset-patterns, ecto-nested-associations, or ecto-migration only when that narrower behavior is central.

Comments

Markdown supported