Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Ecto patterns — schemas, changesets, queries, migrations, Multi, associations, preloads, upserts. Use when editing Repo calls, Ecto.Query, or schema fields. Skip for Ash.
.claude/skills/oliver-kriska-ecto-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 39% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 0% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 4% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 13% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 17% | 0% |
Reference for working with Ecto schemas, queries, and migrations.
cast/4 for user/API input, change/2 or put_change/3 for internal trusted data:float FOR MONEY — Always use :decimal or :integer (cents)u.name == ^user_input is safe, string interpolation causes SQL injectionhas_many, JOIN FOR belongs_to — Avoids row multiplicationfrom(a in A, b in B) without on: creates Cartesian productcast_assoc WITH SHARED DATA — When multiple parents share child data, deduplicate child records BEFORE building changesets. Dedup only works within a single changesetelixirdefmodule MyApp.Context.Entity do use Ecto.Schema import Ecto.Changeset @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "entities" do field :name, :string field :status, Ecto.Enum, values: [:draft, :active, :archived] field :amount_cents, :integer # Never :float for money! belongs_to :user, MyApp.Accounts.User timestamps(type: :utc_datetime_usec) end def changeset(entity, attrs) do entity |> cast(attrs, [:name, :status, :amount_cents]) |> validate_required([:name]) |> foreign_key_constraint(:user_id) end end
| Function | Use When | |----------|----------| | cast/4 | External data (user input, API) | | put_change/3 | Internal trusted data (timestamps, computed) | | change/2 | Internal data from existing struct |
| Relationship | Strategy | |--------------|----------| | belongs_to | JOIN (single query) | | has_many | Separate queries (avoid row multiplication) |
| Wrong | Right | |-------|-------| | field :amount, :float | field :amount_cents, :integer | | "SELECT * WHERE name = '#{name}'" | from(u in User, where: u.name == ^name) | | Repo.all(User) \|> Enum.filter(& &1.active) | from(u in User, where: u.active) | | Preloading in loops | Repo.preload(posts, :comments) | | Repo.get!(User, user_id) with user input | Repo.get(User, id) + handle nil | | {:ok, _} = Repo.update(cs) inside Repo.transaction | case/with + Repo.rollback(cs) (see transactions.md) |
For detailed patterns, see:
references/changesets.md - cast vs put_change, custom validations, prepare_changesreferences/queries.md - Composable queries, dynamic, subqueries, preloadingreferences/migrations.md - Safe migrations, concurrent indexes, NOT NULLreferences/transactions.md - Repo.transact, Ecto.Multi, upserts| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 10,495 | 8,879 | -15% | 1 | 1 | 0% | 2,007 | 2,786 | +39% | 0 | 0 | — |
case-02 | pass→pass | 10,685 | 6,107 | -43% | 1 | 1 | 0% | 1,890 | 1,973 | +4% | 0 | 0 | — |
case-03 | pass→pass | 15,345 | 11,963 | -22% | 1 | 1 | 0% | 2,930 | 3,312 | +13% | 0 | 0 | — |
case-04 | pass→pass | 9,254 | 6,099 | -34% | 1 | 1 | 0% | 1,677 | 1,966 | +17% | 0 | 0 | — |
case-05 | pass→pass | 8,936 | 6,741 | -25% | 1 | 1 | 0% | 1,670 | 2,137 | +28% | 0 | 0 | — |
case-06 | pass→pass | 11,677 | 8,948 | -23% | 1 | 1 | 0% | 2,092 | 2,511 | +20% | 0 | 0 | — |
case-07 | pass→pass | 14,774 | 7,947 | -46% | 1 | 1 | 0% | 2,320 | 2,362 | +2% | 0 | 0 | — |
case-08 | pass→pass | 10,503 | 5,258 | -50% | 1 | 1 | 0% | 1,710 | 1,866 | +9% | 0 | 0 | — |
case-09 | pass→pass | 14,246 | 7,783 | -45% | 1 | 1 | 0% | 2,549 | 2,408 | -6% | 0 | 0 | — |
case-10 | pass→pass | 9,737 | 6,299 | -35% | 1 | 1 | 0% | 1,772 | 2,050 | +16% | 0 | 0 | — |
case-11 | fail→pass | 14,073 | 8,497 | -40% | 1 | 1 | 0% | 2,423 | 2,432 | +0% | 0 | 0 | — |
case-17 | pass→pass | 10,019 | 7,825 | -22% | 1 | 1 | 0% | 1,868 | 2,215 | +19% | 0 | 0 | — |
case-12 | pass→pass | 13,702 | 8,440 | -38% | 1 | 1 | 0% | 2,423 | 2,507 | +3% | 0 | 0 | — |
case-13 | pass→pass | 9,517 | 6,625 | -30% | 1 | 1 | 0% | 1,779 | 2,190 | +23% | 0 | 0 | — |
case-14 | pass→pass | 14,847 | 8,833 | -41% | 1 | 1 | 0% | 2,487 | 2,566 | +3% | 0 | 0 | — |
case-15 | pass→pass | 8,887 | 3,835 | -57% | 1 | 1 | 0% | 1,675 | 1,541 | -8% | 0 | 0 | — |
case-16 | pass→pass | 14,299 | 11,900 | -17% | 1 | 1 | 0% | 2,418 | 3,228 | +33% | 0 | 0 | — |
case-18 | pass→pass | 9,991 | 5,762 | -42% | 1 | 1 | 0% | 1,728 | 1,889 | +9% | 0 | 0 | — |
case-19 | pass→pass | 8,159 | 7,411 | -9% | 1 | 1 | 0% | 1,424 | 2,135 | +50% | 0 | 0 | — |
case-20 | pass→pass | 13,534 | 7,766 | -43% | 1 | 1 | 0% | 2,293 | 2,306 | +1% | 0 | 0 | — |
case-21 | pass→pass | 11,127 | 7,777 | -30% | 1 | 1 | 0% | 2,240 | 2,447 | +9% | 0 | 0 | — |
case-22 | pass→pass | 9,435 | 8,243 | -13% | 1 | 1 | 0% | 1,667 | 2,481 | +49% | 0 | 0 | — |
case-23 | pass→pass | 2,240 | 3,206 | +43% | 1 | 1 | 0% | 441 | 1,519 | +244% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.