phoenix-ecto

Ecto Guidelines

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill provides a specialized set of best practices and architectural guidelines for Ecto, the database wrapper for Elixir and Phoenix. It focuses on optimizing database performance through association preloading, ensuring application security by preventing mass assignment vulnerabilities, and enforcing consistent coding standards for schemas and changesets.

Use Cases

  • Performance Optimization: Automatically identifying and preloading Ecto associations to prevent N+1 query issues in Phoenix templates.
  • Security Auditing: Ensuring sensitive fields like user_id are handled programmatically rather than through user-controlled cast calls to prevent unauthorized data modification.
  • Code Standardization: Enforcing consistent field type definitions and correct changeset access patterns (using get_field) across the development team.
  • Database Scripting: Providing necessary module imports and structural guidance for writing reliable and error-free seeds.exs files.
namephoenix-ecto
descriptionEcto Guidelines

Ecto Guidelines

  • Always preload Ecto associations in queries when they'll be accessed in templates, ie a message that needs to reference the message.user.email
  • Remember import Ecto.Query and other supporting modules when you write seeds.exs
  • Ecto.Schema fields always use the :string type, even for :text, columns, ie: field :name, :string
  • Ecto.Changeset.validate_number/2 DOES NOT SUPPORT the :allow_nil option. By default, Ecto validations only run if a change for the given field exists and the change value is not nil, so such as option is never needed
  • You must use Ecto.Changeset.get_field(changeset, :field) to access changeset fields
  • Fields which are set programatically, such as user_id, must not be listed in cast calls or similar for security purposes. Instead they must be explicitly set when creating the struct