name: ecto description: Ecto conventions for schemas, changesets, query composition, and migration design. Use when modifying schemas, context queries, constraints, indexes, transactions, or migrations.
Ecto
Rules
- Always use changesets for insert/update operations.
- Preload associations before template access to avoid N+1 queries.
- Use transactions for multi-step operations that must succeed together.
- Add database constraints and mirror them in changesets.
- Keep
Repousage inside context modules, not web layer modules. - Add indexes for foreign keys and high-frequency query fields.
- Keep migration changes reversible and explicit.
Use This Skill When
- Editing schemas, changesets, context query functions, or migrations.
- Designing table constraints and index strategy.
- Reviewing database access boundaries in contexts.
Workflow
- Start from schema and changeset rules.
- Add/update migration for structural changes.
- Expose operations through context APIs.
- Add tests for valid and invalid paths.
References
./references/ecto-conventions.md../elixir/references/project-structure.md
Related Skills
elixirtesting