SQL Optimization Patterns
ynulihao/AgentSkillOS
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.
A skill your agent uses when defining schemas, writing queries, or creating migrations — schema design, Repo usage, indexes, query composition.
$ npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install j-morgan6/elixir-phoenix-guide ecto-essentials --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/j-morgan6/elixir-phoenix-guide.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/ecto-essentials .claude/skills/ecto-essentials && rm -rf skills-srcUse ~/.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/
Install the "ecto-essentials" agent skill from https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentials into .claude/skills/ecto-essentials/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ecto-essentials", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentialsType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install j-morgan6/elixir-phoenix-guide ecto-essentials --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/j-morgan6/elixir-phoenix-guide.git skills-src && mkdir -p .agents/skills && cp -r skills-src/skills/ecto-essentials .agents/skills/ecto-essentials && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "ecto-essentials" agent skill from https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentials into .agents/skills/ecto-essentials/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ecto-essentials", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install j-morgan6/elixir-phoenix-guide ecto-essentials --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/j-morgan6/elixir-phoenix-guide.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/skills/ecto-essentials .cursor/skills/ecto-essentials && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "ecto-essentials" agent skill from https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentials into .cursor/skills/ecto-essentials/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ecto-essentials", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/j-morgan6/elixir-phoenix-guide.git --path skills/ecto-essentials--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install j-morgan6/elixir-phoenix-guide ecto-essentials --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/j-morgan6/elixir-phoenix-guide.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/skills/ecto-essentials .gemini/skills/ecto-essentials && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "ecto-essentials" agent skill from https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentials into .gemini/skills/ecto-essentials/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ecto-essentials", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install j-morgan6/elixir-phoenix-guide ecto-essentialsInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/j-morgan6/elixir-phoenix-guide.git skills-src && mkdir -p .github/skills && cp -r skills-src/skills/ecto-essentials .github/skills/ecto-essentials && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "ecto-essentials" agent skill from https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentials into .github/skills/ecto-essentials/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ecto-essentials", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install j-morgan6/elixir-phoenix-guide ecto-essentials --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/j-morgan6/elixir-phoenix-guide.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/skills/ecto-essentials .opencode/skills/ecto-essentials && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "ecto-essentials" agent skill from https://github.com/j-morgan6/elixir-phoenix-guide/tree/main/skills/ecto-essentials into .opencode/skills/ecto-essentials/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "ecto-essentials", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
ecto-essentialsA skill your agent uses when defining schemas, writing queries, or creating migrations — schema design, Repo usage, indexes, query composition.
Ecto Essentials is an agent skill from j-morgan6/elixir-phoenix-guide. Use when defining schemas, writing queries, or creating migrations — schema design, Repo usage, indexes, query composition.
Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.
It sits in Databases, covering Database schema design. The licence is MIT.
7 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit cdfddac. It shows what the files ask for, not the result of running them.
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.
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.
No URLs in SKILL.md.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Ecto Essentials loads about 2.2k tokens when it runs. Until then it costs about 35 tokens; SKILL.md has 251 words of instructions outside code blocks.
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.
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.
The full file from j-morgan6/elixir-phoenix-guide at commit cdfddac, republished under its MIT licence (© j-morgan6). 251 words, ~2,212 tokens.
.claude/skills/ecto-essentials/SKILL.md (or your agent's skills folder).Define schemas with proper types and associations.
defmodule MyApp.Media.Image do
use Ecto.Schema
import Ecto.Changeset
schema "images" do
field :title, :string
field :description, :string
field :filename, :string
field :file_path, :string
field :content_type, :string
field :file_size, :integer
belongs_to :folder, MyApp.Media.Folder
timestamps()
end
endAlways use changesets for data validation and casting.
def changeset(image, attrs) do
image
|> cast(attrs, [:title, :description, :filename, :file_path, :content_type, :file_size, :folder_id])
|> validate_required([:title, :filename, :file_path, :content_type, :file_size])
|> validate_length(:title, min: 1, max: 255)
|> validate_inclusion(:content_type, ["image/jpeg", "image/png", "image/gif"])
|> validate_number(:file_size, greater_than: 0, less_than: 10_000_000)
|> foreign_key_constraint(:folder_id)
endBuild queries composably using Ecto.Query.
import Ecto.Query
def list_images_by_folder(folder_id) do
Image
|> where([i], i.folder_id == ^folder_id)
|> order_by([i], desc: i.inserted_at)
|> Repo.all()
end
def search_images(query_string) do
search = "%#{query_string}%"
Image
|> where([i], ilike(i.title, ^search) or ilike(i.description, ^search))
|> Repo.all()
endUse preload to avoid N+1 queries.
Bad:
images = Repo.all(Image)
# Later accessing image.folder causes N queries
Enum.each(images, fn image -> image.folder.name end)Good:
images =
Image
|> preload(:folder)
|> Repo.all()
Enum.each(images, fn image -> image.folder.name end)Use Repo.transaction for operations that must succeed together.
def transfer_images(image_ids, from_folder_id, to_folder_id) do
Repo.transaction(fn ->
with {:ok, from_folder} <- get_folder(from_folder_id),
{:ok, to_folder} <- get_folder(to_folder_id),
{count, nil} <- update_images(image_ids, to_folder_id) do
# Repo.transaction wraps the return — don't return {:ok, _} from inside
count
else
{:error, reason} -> Repo.rollback(reason)
_ -> Repo.rollback(:unknown_error)
end
end)
end
# Repo.transaction/1 always wraps the fn's return in {:ok, _}.
# Returning {:ok, count} from inside would yield {:ok, {:ok, count}} to the caller.
# Callers see {:ok, count} or {:error, reason}:
case transfer_images(ids, from_id, to_id) do
# count is the number of images transferred
{:ok, count} -> Logger.info("Images transferred", count: count)
# transaction rolled back
{:error, reason} -> Logger.error("Transfer failed", reason: inspect(reason))
endUse Repo.insert and Repo.update with changesets.
def create_image(attrs) do
%Image{}
|> Image.changeset(attrs)
|> Repo.insert()
end
def update_image(%Image{} = image, attrs) do
image
|> Image.changeset(attrs)
|> Repo.update()
endUse on_conflict for upsert behavior.
def create_or_update_folder(attrs) do
%Folder{}
|> Folder.changeset(attrs)
|> Repo.insert(
on_conflict: {:replace, [:name, :updated_at]},
conflict_target: :name
)
endDefine associations properly in schemas.
# Parent schema
defmodule MyApp.Media.Folder do
use Ecto.Schema
schema "folders" do
field :name, :string
has_many :images, MyApp.Media.Image
timestamps()
end
end
# Child schema
defmodule MyApp.Media.Image do
use Ecto.Schema
schema "images" do
field :title, :string
belongs_to :folder, MyApp.Media.Folder
timestamps()
end
endUse Ecto.build_assoc to create associated records.
def add_image_to_folder(folder, image_attrs) do
folder
|> Ecto.build_assoc(:images)
|> Image.changeset(image_attrs)
|> Repo.insert()
end
cast_assocusage, the FK-in-child-changeset pitfall, and nested-data patterns: see the ecto-changeset-patterns and ecto-nested-associations skills.
Build queries dynamically based on filters.
def list_images(filters) do
Image
|> apply_filters(filters)
|> Repo.all()
end
defp apply_filters(query, filters) do
Enum.reduce(filters, query, fn
{:folder_id, folder_id}, query ->
where(query, [i], i.folder_id == ^folder_id)
{:search, term}, query ->
where(query, [i], ilike(i.title, ^"%#{term}%"))
{:min_size, size}, query ->
where(query, [i], i.file_size >= ^size)
_, query ->
query
end)
endUse aggregation functions for statistics.
def count_images_by_folder do
Image
|> group_by([i], i.folder_id)
|> select([i], {i.folder_id, count(i.id)})
|> Repo.all()
|> Map.new()
end
def total_storage_used do
Image
|> select([i], sum(i.file_size))
|> Repo.one()
endCommon Repo operations:
# Fetch single record
Repo.get(Image, id) # Returns record or nil
Repo.get!(Image, id) # Returns record or raises
Repo.get_by(Image, title: "Photo")
# Fetch all records
Repo.all(Image)
# Insert
Repo.insert(changeset) # Returns {:ok, record} or {:error, changeset}
Repo.insert!(changeset) # Returns record or raises
# Update
Repo.update(changeset)
Repo.update!(changeset)
# Delete
Repo.delete(record)
Repo.delete!(record)
# Delete all matching
Repo.delete_all(Image)
Repo.delete_all(where(Image, [i], i.folder_id == ^folder_id))Write clear, reversible migrations.
defmodule MyApp.Repo.Migrations.CreateImages do
use Ecto.Migration
def change do
create table(:images) do
add :title, :string, null: false
add :description, :text
add :filename, :string, null: false
add :file_path, :string, null: false
add :content_type, :string, null: false
add :file_size, :integer, null: false
add :folder_id, references(:folders, on_delete: :nilify_all)
timestamps()
end
create index(:images, [:folder_id])
create index(:images, [:inserted_at])
end
endAdd unique constraints in schema and migration.
# Migration
create unique_index(:folders, [:name])
# Schema changeset
def changeset(folder, attrs) do
folder
|> cast(attrs, [:name])
|> validate_required([:name])
|> unique_constraint(:name)
endUse virtual fields for computed or temporary data.
schema "images" do
field :title, :string
field :file_path, :string
field :url, :string, virtual: true
timestamps()
end
def with_url(%Image{} = image) do
%{image | url: "/uploads/#{Path.basename(image.file_path)}"}
endDefine custom Ecto types for special data.
defmodule MyApp.FileSize do
use Ecto.Type
def type, do: :integer
def cast(size) when is_integer(size) and size >= 0, do: {:ok, size}
def cast(_), do: :error
def load(size), do: {:ok, size}
def dump(size), do: {:ok, size}
endOrganize database operations in contexts.
defmodule MyApp.Media do
alias MyApp.Media.{Image, Folder}
alias MyApp.Repo
def list_images, do: Repo.all(Image)
def get_image!(id), do: Repo.get!(Image, id)
def create_image(attrs) do
%Image{}
|> Image.changeset(attrs)
|> Repo.insert()
end
def update_image(%Image{} = image, attrs) do
image
|> Image.changeset(attrs)
|> Repo.update()
end
def delete_image(%Image{} = image) do
Repo.delete(image)
end
endWhen writing tests for Ecto schemas, changesets, or contexts, invoke elixir-phoenix-guide:testing-essentials before writing any _test.exs file.
© j-morgan6, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in skills/ecto-essentials of j-morgan6/elixir-phoenix-guide.
Open the folder on GitHubat commit cdfddac
Ecto Essentials 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.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Ecto Essentials this skillj-morgan6/elixir-phoenix-guide | 166 | — | ~2.2k | Automated safety check: Pass | MIT | |
| SQL Optimization Patternsynulihao/AgentSkillOS | 617 | 11 repos | ~3.3k | Automated safety check: Pass | None | |
| Add Mpk Taskmirage-project/mirage | 2.5k | — | ~4.5k | Automated safety check: Pass | Apache-2.0 | |
| Datamodellmnimbalyst/nimbalyst | 1.9k | — | ~713 | Automated safety check: Pass | MIT | |
| B200 Flash Attention4 Plannermirage-project/mirage | 2.5k | — | ~1.9k | Automated safety check: Pass | Apache-2.0 | |
| Experiment Auditwanshuiyin/Auto-claude-code-research-in-sleep | 17k | 1 repos | ~2.7k | Automated safety check: Notes | MIT |
ynulihao/AgentSkillOS
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries.
mirage-project/mirage
Step-by-step guide for adding a new task implementation to Mirage Persistent Kernel (MPK).
nimbalyst/nimbalyst
Create visual data models for database schemas using Nimbalyst's DataModelLM editor.
mirage-project/mirage
A skill your agent uses when the user wants to design or extend a FlashAttention-style forward kernel on B200/Blackwell, involving the two MMAs QKᵀ and PV, online softmax, S/P/O in TMEM, warp roles…
wanshuiyin/Auto-claude-code-research-in-sleep
Audit experiment integrity before claiming results. An agent skill from wanshuiyin/Auto-claude-code-research-in-sleep.
fastrepl/anarlog
Design or review schemas for crates/cloudsync using SQLite Sync constraints, not generic SQLite advice.
j-morgan6/elixir-phoenix-guide
A skill your agent uses when refactoring for duplication, complexity, or dead code — includes the plugin's on-demand analysis scripts.
j-morgan6/elixir-phoenix-guide
A skill your agent uses when preparing releases or deployment config — runtime.exs vs compile-time config, release migrations, PHXHOST/PHXSERVER, assets, health checks.
j-morgan6/elixir-phoenix-guide
A skill your agent uses when a resource needs multiple changesets (registration vs update), conditional validation, field transforms, or uniqueness validation — changeset composition.
j-morgan6/elixir-phoenix-guide
A skill your agent uses when a form or operation manages parent and child records together — castassoc/castembed, onreplace, Ecto.Multi across tables, FK cascade design.
j-morgan6/elixir-phoenix-guide
A skill your agent uses when writing or refactoring core Elixir — pattern matching, case/cond/with, pipes, {:ok, }/{:error, } contracts.
j-morgan6/elixir-phoenix-guide
A skill your agent uses when writing background jobs with Oban — worker options, return contracts, idempotency, uniqueness, Oban.Testing.
Categories
A skill your agent uses when defining schemas, writing queries, or creating migrations — schema design, Repo usage, indexes, query composition. Ecto Essentials is an agent skill from j-morgan6/elixir-phoenix-guide. Use when defining schemas, writing queries, or creating migrations — schema design, Repo usage, indexes, query composition.
Ecto Essentials fits situations like: defining schemas; writing queries; creating migrations — schema design; query composition.
Run `npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a claude-code`. Or copy the skill folder (skills/ecto-essentials in j-morgan6/elixir-phoenix-guide) into .claude/skills/ecto-essentials in your project. Claude Code loads it when a task matches its description.
Run `npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -a codex`. Or copy the skill folder (skills/ecto-essentials in j-morgan6/elixir-phoenix-guide) into .agents/skills/ecto-essentials in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add j-morgan6/elixir-phoenix-guide --skill ecto-essentials -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-essentials, .gemini/skills/ecto-essentials, .github/skills/ecto-essentials and .opencode/skills/ecto-essentials in your project.
SKILL.md names no scripts, command-line tools or credentials: Ecto Essentials is instructions for the agent only.
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.
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.
Ecto Essentials is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 2.2k tokens (SKILL.md is roughly 8.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Ecto Essentials: SQL Optimization Patterns (ynulihao/AgentSkillOS, 617 stars), Add Mpk Task (mirage-project/mirage, 2.5k stars), Datamodellm (nimbalyst/nimbalyst, 1.9k stars) and B200 Flash Attention4 Planner (mirage-project/mirage, 2.5k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
j-morgan6 (a GitHub user) maintains it in j-morgan6/elixir-phoenix-guide, which has 166 GitHub stars. The repository holds 19 skills in this directory. The repository was last updated on July 6, 2026.
Source: j-morgan6/elixir-phoenix-guide on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.