Agent skill

Ecto Persistence Patterns

by georgeguimaraes in georgeguimaraes/elixir-agent-tools

Designs and debugs Elixir persistence with Ecto: schemas, changesets, queries, preloads, migrations and multi-tenancy, kept within application contexts.

Apache-2.0Auto-check passedBackend & APIs

Install Ecto Persistence Patterns

skills CLI
$ npx skills add georgeguimaraes/elixir-agent-tools --skill ecto -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install georgeguimaraes/elixir-agent-tools ecto --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/georgeguimaraes/elixir-agent-tools.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/elixir-dev/skills/ecto .claude/skills/ecto && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
ecto
GitHub stars
184
Token cost
~1.2k tokens
SKILL.md length
444 words
Files
1
Skills in repo
5
Repo updated
First seen
Licence
Apache-2.0

At a glance

Designs and debugs Elixir persistence with Ecto: schemas, changesets, queries, preloads, migrations and multi-tenancy, kept within application contexts.

  • Designing Ecto schemas and changesets for a new feature
  • SKILL.md covers Context = Setting That Changes…, Cross-Context References: IDs,…, DDD Patterns as Pipelines and Schema ≠ Database Table, plus 7 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Choosing between preloads and joins when loading associations

What it does

The skill starts from the idea that a context changes what words mean, so each bounded context may have its own Product schema and table. Design goes top-down from subdomain to context to entity, cross-context references use IDs rather than associations, and queries go through the context. Domain patterns are written as pipelines, with events passed as data structs. It also keeps schema and table apart: embedded schemas serve forms and API payloads, and one schema can have several changesets such as registration, profile and admin.

For multi-tenancy it recommends composite foreign keys and prepare_query/3 for automatic scoping, raising when org_id is missing. For preloads, separate queries suit large has-many sets and join preloads suit belongs-to and has-one, since joins can use ten times the memory on has-many. Plain CRUD contexts are fine, and generators cover simple cases. It lists gotchas from the Ecto core team, including CTEs not inheriting the schema prefix in multi-tenant apps and parameterized queries not being prepared statements.

When your agent uses it

  • Designing Ecto schemas and changesets for a new feature
  • Choosing between preloads and joins when loading associations
  • Adding tenant scoping to queries in a multi-tenant Elixir app
  • Deciding how contexts should reference each other

Example prompts

  • “Design Ecto schemas and changesets for a signup flow with separate registration and profile updates.”
  • “This query preloads thousands of comments per post and uses too much memory; fix it.”
  • “Add tenant scoping by org_id to every query in the Billing context.”
  • “Review my migration for composite foreign keys across tenants.”

What it can do on your machine

Read from SKILL.md and the folder at commit ac3a5a1. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are elixir).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Ecto Persistence Patterns loads about 1.2k tokens when it runs. Until then it costs about 61 tokens; SKILL.md has 444 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~61
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from georgeguimaraes/elixir-agent-tools at commit ac3a5a1, republished under its Apache-2.0 licence (© georgeguimaraes). 444 words, ~1,163 tokens.

Download SKILL.mdSave it as .claude/skills/ecto/SKILL.md (or your agent's skills folder).
name
ecto
description
Design and debug Elixir persistence with Ecto. Use for schemas, changesets, queries, preloads, transactions, migrations, multi-tenancy, and data access through application contexts. Covers database query performance and connection pools.

Ecto

Model persistence, compose queries, and keep data access within application boundaries.

Context = Setting That Changes Meaning

Context isn't just a namespace—it changes what words mean. "Product" means different things in Checkout (SKU, name), Billing (SKU, cost), and Fulfillment (SKU, warehouse). Each bounded context may have its OWN Product schema/table.

Think top-down: Subdomain → Context → Entity. Not "What context does Product belong to?" but "What is a Product in this business domain?"

Cross-Context References: IDs, Not Associations

elixir
schema "cart_items" do
  field :product_id, :integer  # Reference by ID
  # NOT: belongs_to :product, Catalog.Product
end

Query through the context, not across associations. Keeps contexts independent and testable.

DDD Patterns as Pipelines

elixir
def create_product(params) do
  params
  |> Products.build()       # Factory: unstructured → domain
  |> Products.validate()    # Aggregate: enforce invariants
  |> Products.insert()      # Repository: persist
end

Use events (as data structs) to compose bounded contexts with minimal coupling.

Schema ≠ Database Table

Use CaseApproach
Database tableStandard schema/2
Form validation onlyembedded_schema/1
API request/responseEmbedded schema or schemaless

Multiple Changesets per Schema

elixir
def registration_changeset(user, attrs)  # Full validation + password
def profile_changeset(user, attrs)       # Name, bio only
def admin_changeset(user, attrs)         # Role, verified_at

Different operations = different changesets.

Multi-Tenancy: Composite Foreign Keys

elixir
add :post_id, references(:posts, with: [org_id: :org_id], match: :full)

Use prepare_query/3 for automatic scoping. Raise if org_id missing.

Preload vs Join Trade-offs

ApproachBest For
Separate preloadsHas-many with many records (less memory)
Join preloadsBelongs-to, has-one (single query)

Join preloads can use 10x more memory for has-many.

CRUD Contexts Are Fine

"If you have a CRUD bounded context, go for it. No need to add complexity."

Use generators for simple cases. Add DDD patterns only when business logic demands it.

Gotchas from Core Team

CTE Queries Don't Inherit Schema Prefix

In multi-tenant apps, CTEs don't get the parent query's prefix.

Fix: Explicitly set prefix: %{recursive_query | prefix: "tenant"}

Parameterized Queries ≠ Prepared Statements
  • Parameterized queries: WHERE id = $1 — always used by Ecto
  • Prepared statements: Query plan cached by name — can be disabled

pgbouncer: Use prepare: :unnamed (disables prepared statements, keeps parameterized queries).

Show full SKILL.md (176 more words)Show less
pool_count vs pool_size

More pools with fewer connections = better for benchmarks. But with mixed fast/slow queries, a single larger pool gives better latency.

Rule: pool_count for uniform workloads, larger pool_size for real apps.

Sandbox Mode Doesn't Work With External Processes

Cachex, separate GenServers, or anything outside the test process won't share the sandbox transaction.

Fix: Make the external service use the test process, or accept it's not in the same transaction.

Null Bytes Crash Postgres

PostgreSQL rejects null bytes even though they're valid UTF-8.

Fix: Sanitize at boundaries: String.replace(string, "\x00", "")

preload_order for Association Sorting
elixir
has_many :comments, Comment, preload_order: [desc: :inserted_at]

Note: Doesn't work for through associations.

Runtime Migrations Use List API
elixir
Ecto.Migrator.run(Repo, [{0, Migration1}, {1, Migration2}], :up, opts)

Idioms

  • Prefer Repo.insert/1 over Repo.insert!/1—handle {:ok, _} / {:error, _} explicitly
  • Use Repo.transact/1 (Ecto 3.12+) for simple transactions instead of Ecto.Multi

Red Flags - STOP and Reconsider

  • belongs_to pointing to another context's schema
  • Single changeset for all operations
  • Preloading has-many with join
  • CTEs in multi-tenant apps without explicit prefix
  • Using pgbouncer without prepare: :unnamed
  • Testing with Cachex/GenServers assuming sandbox shares transactions
  • Accepting user input without null byte sanitization

Any of these? Re-read the Gotchas section.

© georgeguimaraes, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in plugins/elixir-dev/skills/ecto of georgeguimaraes/elixir-agent-tools.

Open the folder on GitHubat commit ac3a5a1

Compare with similar skills

Ecto Persistence Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Ecto Persistence Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Ecto Persistence Patterns this skillgeorgeguimaraes/elixir-agent-tools184—~1.2kAutomated safety check: PassApache-2.0
Dsqlawslabs/agent-plugins915—~6.9kAutomated safety check: PassApache-2.0
DB SculptorEliasOulkadi/shokunin114—~3.1kAutomated safety check: NotesMIT
Jpa Patternsaffaan-m/ECC276k5 repos~1.2kAutomated safety check: PassMIT
Prisma Expertdavila7/claude-code-templates32k7 repos~2.6kAutomated safety check: PassMIT
Discover Databaserand/cc-polymath181—~2kAutomated safety check: PassMIT

Similar skills

  • Dsql

    awslabs/agent-plugins

    Official

    Build with Aurora DSQL — manage schemas, execute queries, handle migrations, diagnose query plans, diagnose cluster performance, load data, and develop applications with a serverless, distributed…

    915 GitHub stars~6.9k tokensUpdated yesterday
    DatabasesAuto-check passed
  • DB Sculptor

    EliasOulkadi/shokunin

    Design database schemas with Prisma/Drizzle, PostgreSQL index strategy (B-tree, GIN, GiST, BRIN, Hash), query optimization (EXPLAIN ANALYZE), migration safety (expand/contract, zero-downtime), and…

    114 GitHub stars~3.1k tokensUpdated 4 days ago
    DatabasesAuto-check: notes
  • Jpa Patterns

    affaan-m/ECC

    JPA/Hibernate patterns for entity design, relationships, query optimization, transactions, auditing, indexing, pagination, and pooling in Spring Boot.

    276k GitHub starsUsed in 5 repos~1.2k tokens
    DatabasesAuto-check passed
  • Prisma Expert

    davila7/claude-code-templates

    Prisma ORM expert for schema design, migrations, query optimization, relations modeling, and database operations.

    32k GitHub starsUsed in 7 repos~2.6k tokens
    DatabasesAuto-check passed
  • Discover Database

    rand/cc-polymath

    Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.

    181 GitHub stars~2k tokensUpdated 7 mo ago
    DatabasesAuto-check passed
  • Prisma Patterns

    affaan-m/ECC

    Prisma ORM patterns for TypeScript backends — schema design, query optimization, transactions, pagination, and critical traps like updateMany returning count not records, $transaction timeouts…

    276k GitHub starsUsed in 1 repo~3.8k tokens
    DatabasesAuto-check: notes

More from georgeguimaraes/elixir-agent-tools

  • Idiomatic Elixir

    georgeguimaraes/elixir-agent-tools

    Writes and refactors idiomatic Elixir modules and functions, with rules for pattern matching, error handling, protocols and when a process is really needed.

    184 GitHub stars~2.1k tokensUpdated 19 days ago
    Auto-check passed
  • Oban Background Jobs

    georgeguimaraes/elixir-agent-tools

    Guidance for building and debugging durable background jobs in Elixir with Oban and Oban Pro, covering serialization, retries, uniqueness, chaining, chunking and workflows.

    184 GitHub stars~2.2k tokensUpdated 19 days ago
    Auto-check passed
  • Elixir OTP Concurrency

    georgeguimaraes/elixir-agent-tools

    Guides choices among GenServer, Supervisor, Task, Registry, ETS and Broadway when designing or debugging Elixir concurrency, state and fault recovery.

    184 GitHub stars~1.2k tokensUpdated 19 days ago
    Auto-check passed
  • Phoenix LiveView Patterns

    georgeguimaraes/elixir-agent-tools

    Guidance for building and debugging Phoenix web interfaces: where LiveView loads data, scopes, PubSub topics, external polling and component state.

    184 GitHub stars~1.3k tokensUpdated 19 days ago
    Auto-check passed

Works with

Questions about Ecto Persistence Patterns

What does Ecto Persistence Patterns do?

Designs and debugs Elixir persistence with Ecto: schemas, changesets, queries, preloads, migrations and multi-tenancy, kept within application contexts. The skill starts from the idea that a context changes what words mean, so each bounded context may have its own Product schema and table. Design goes top-down from subdomain to context to entity, cross-context references use IDs rather than associations, and queries go through the context.

When should I use Ecto Persistence Patterns?

Ecto Persistence Patterns fits situations like: designing Ecto schemas and changesets for a new feature; choosing between preloads and joins when loading associations; adding tenant scoping to queries in a multi-tenant Elixir app; deciding how contexts should reference each other.

How do I install Ecto Persistence Patterns in Claude Code?

Run `npx skills add georgeguimaraes/elixir-agent-tools --skill ecto -a claude-code`. Or copy the skill folder (plugins/elixir-dev/skills/ecto in georgeguimaraes/elixir-agent-tools) into .claude/skills/ecto in your project. Claude Code loads it when a task matches its description.

How do I install Ecto Persistence Patterns in Codex?

Run `npx skills add georgeguimaraes/elixir-agent-tools --skill ecto -a codex`. Or copy the skill folder (plugins/elixir-dev/skills/ecto in georgeguimaraes/elixir-agent-tools) into .agents/skills/ecto in your project. Codex loads it when a task matches its description.

Can I use Ecto Persistence Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add georgeguimaraes/elixir-agent-tools --skill ecto -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/ecto, .gemini/skills/ecto, .github/skills/ecto and .opencode/skills/ecto in your project.

What does Ecto Persistence Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Ecto Persistence Patterns is instructions for the agent only.

Does Ecto Persistence Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Ecto Persistence Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Ecto Persistence Patterns use?

Ecto Persistence Patterns is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Ecto Persistence Patterns use?

About 1.2k tokens (SKILL.md is roughly 4.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Ecto Persistence Patterns?

Skills that share tags, products or a category with Ecto Persistence Patterns: Dsql (awslabs/agent-plugins, 915 stars), DB Sculptor (EliasOulkadi/shokunin, 114 stars), Jpa Patterns (affaan-m/ECC, 276k stars) and Prisma Expert (davila7/claude-code-templates, 32k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Ecto Persistence Patterns?

georgeguimaraes (a GitHub user) maintains it in georgeguimaraes/elixir-agent-tools, which has 184 GitHub stars. The repository holds 5 skills in this directory. The repository was last updated on September 20, 2026.

Source: georgeguimaraes/elixir-agent-tools on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.