- Home
- Skills
- J Morgan6
- Elixir Phoenix Guide
- Ecto Essentials
ecto-essentials_skill
- Shell
56
GitHub Stars
1
Bundled Files
3 weeks ago
Catalog Refreshed
2 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstart where the catalogue uses aiagentskills.
npx veilstart add skill j-morgan6/elixir-phoenix-guide --skill ecto-essentials- SKILL.md8.1 KB
Overview
This skill enforces essential Ecto patterns and checks to run before any database work. It codifies rules for schemas, changesets, queries, migrations, and repo usage to prevent common mistakes and ensure data integrity. Use it as a mandatory checklist prior to modifying schemas, queries, or migrations.
How this skill works
The skill inspects code and practices to confirm changeset usage, association preloads, transaction boundaries, and database constraints. It validates schema fields, timestamps, indexes, and migration patterns and flags anti-patterns like direct Repo calls from the web layer or raw map inserts. It also recommends composable queries, proper association definitions, and safe upsert/update flows.
When to use it
- Before creating or modifying schemas or migrations
- Prior to changing queries, repository calls, or association logic
- When adding or updating insert/update code paths
- During code review for any database-related pull request
- When introducing nested or bulk operations that require transactions
Best practices
- Always use changesets for inserts and updates; never pass raw maps to Repo
- Preload associations before accessing them to avoid N+1 queries
- Wrap multi-step operations in Repo.transaction and rollback on errors
- Declare database constraints (unique, foreign key, check) and mirror them in changeset validations
- Use contexts to access Repo; avoid calling Repo directly from controllers or views
- Add indexes on foreign keys and frequently queried fields and include timestamps() in every schema
Example use cases
- Creating a new schema: include timestamps(), indexes, and matching changeset validations
- Implementing a file upload model: validate content_type and file_size in changesets and add foreign_key_constraint for folder_id
- Moving records between folders: perform the operation inside Repo.transaction with proper error handling
- Bulk insert/update with potential conflicts: use on_conflict and conflict_target for safe upserts
- Returning nested results from an API: use preload or cast_assoc with changesets for nested creation
FAQ
Changesets centralize casting and validation, enforce constraints, and prevent invalid data from reaching the database.
When should I use transactions?
Use transactions for multi-step operations that must succeed or fail as a unit, such as transfers or batched updates.