ecto-patterns

Guide Ecto schemas, queries, changesets, and migrations in Elixir.

517|35|Updated Feb 12, 2026
One-click install
npx skills add https://github.com/oliver-kriska/claude-elixir-phoenix --skill ecto-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ecto-patterns
Source: https://github.com/oliver-kriska/claude-elixir-phoenix/tree/main/plugins/elixir-phoenix/skills/ecto-patterns
Command: npx skills add https://github.com/oliver-kriska/claude-elixir-phoenix --skill ecto-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides clear, actionable guidance and best practices for working with Ecto, Elixir's powerful database wrapper, preventing common pitfalls and ensuring robust data management.

Core Features & Use Cases

  • Schema Design: Learn optimal field types and association strategies.
  • Changeset Management: Understand cast, put_change, and custom validations for secure data handling.
  • Query Optimization: Discover techniques for efficient data retrieval and avoiding N+1 queries.
  • Migrations: Implement safe and reliable database schema changes.
  • Use Case: When writing a new Ecto schema, quickly reference the correct field types for money (:integer for cents) and timestamps (:utc_datetime_usec), and ensure all external input is handled via cast/4.

Quick Start

Show me the best way to handle user input for an Ecto changeset.

Frequently Asked Questions about ecto-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the best way to handle user input in an Ecto changeset?

The best way to handle user input in an Ecto changeset is using the cast function to filter and coerce external data. This ensures secure data handling by only permitting specified fields and performing custom validations before database persistence.

How do I avoid N+1 queries when preloading associations in Ecto?

To avoid N+1 queries in Ecto, implement proper preload strategies when retrieving associated data. The Skill provides query optimization techniques that ensure efficient data retrieval by batching association loads instead of executing separate database queries for each record.

What are the correct Ecto field types for storing money and timestamps?

For Ecto schema design, the correct field type for money is :integer representing cents, while timestamps should use :utc_datetime_usec. Following these optimal field types ensures data integrity and prevents common storage anti-patterns in Elixir applications.

How do I perform safe database schema migrations with Ecto?

Safe database schema migrations with Ecto require implementing reliable techniques for database changes. The Skill provides best practices for executing migrations that prevent data loss and maintain database integrity during application evolution in Elixir environments.

Can I use Ecto patterns with Phoenix framework applications?

Yes, Ecto patterns integrate directly with Phoenix framework applications for database interactions. The Skill provides comprehensive guidance on schemas, changesets, and queries specifically tailored for Elixir and Phoenix development workflows.

Why does my Ecto changeset validation fail when using put_change instead of cast?

Ecto changeset validations fail when using put_change instead of cast because put_change bypasses the casting and filtering process. The Skill clarifies when to use each function, ensuring all external input is securely handled via cast for proper data validation.