``` ██████╗ ██████╗████████╗ ██████╗ █████╗ ███╗ ██╗███╗ ██╗ ██████╗ ████████╗ █████╗ ████████╗███████╗ ██╔══██╗██╔════╝╚══██╔══╝██╔═══██╗ ██╔══██╗████╗ ██║████╗ ██║██╔═══██╗╚══██╔══╝██╔══██╗╚══██╔══╝██╔════╝ ██████╔╝██║ ██║ ██║ ██║ ███████║██╔██╗ ██║██╔██╗ ██║██║ ██║ ██║ ███████║ ██║ █████╗ ██╔══██╗██║ ██║ ██║ ██║ ██╔══██║██║╚██╗██║██║╚██╗██║██║ ██║ ██║ ██╔══██║ ██║ ██╔══╝ ██████╔╝╚██████╗ ██║ ╚██████╔╝ ██║ ██║██║ ╚████║██║ ╚████║╚██████╔╝ ██║ ██║ ██║ ██║ ███████╗ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ``` **A powerful Mix task to annotate your Ecto schemas with comprehensive database information** *Inspired by Ruby's `annotate` gem and `schema_plus`* [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Elixir](https://img.shields.io/badge/Elixir-1.16+-purple.svg)](https://elixir-lang.org/)

Features

Core Functionality

Display Features

Configuration

Installation

Add ecto_annotate to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_annotate, "~> 0.1.0", only: :dev}
  ]
end

Then run:

mix deps.get

Usage

Display Schema Information

Run the Mix task to display schema information:

mix ecto_annotate

This will scan all migrations in priv/repo/migrations/ and all schema files in lib/, then display a beautifully formatted output.

Annotate Schema Files

To actually write annotations to your schema files:

mix ecto_annotate --annotate

This will add comprehensive comments to each schema file with:

Remove Annotations

To remove existing annotations:

mix ecto_annotate --remove

Annotation Position

Control where annotations are placed:

mix ecto_annotate --annotate --position top    # Insert at top of file
mix ecto_annotate --annotate --position before # Insert before schema declaration (default)

Output Format

The default output is a colored table format. You can also output JSON:

mix ecto_annotate --format json

Custom Paths

Specify custom paths for migrations and schemas:

mix ecto_annotate --migrations-path custom/migrations --schemas-path app/schemas

Configuration File

Create a .ecto_annotate.exs file in your project root:

%{
  migrations_path: "priv/repo/migrations",
  schemas_path: "lib",
  exclude: ["ecto_annotate", "some_other_dir"],
  position: :before,  # or :top
  show_indexes: true,
  show_foreign_keys: true,
  show_primary_keys: true
}

Example Output

CLI Display

================================================================================
Table: users
================================================================================
Module: TestApp.User

Primary Key:
--------------------------------------------------------------------------------
  integer id

Columns:
--------------------------------------------------------------------------------
  age : integer
  balance : decimal [default: "0.0", precision: 10, scale: 2]
  bio : text
  email : string [null: :false]
  is_active : boolean [default: :true]
  name : string

Indexes:
--------------------------------------------------------------------------------
  index_users_on_email: [email] (unique)

Foreign Keys:
--------------------------------------------------------------------------------
  user_id: user_id -> users.id (on_delete: delete_all)

Associations:
--------------------------------------------------------------------------------
  has_one :profile -> TestApp.Profile (integer id)
  has_many :posts -> TestApp.Post (integer id)

Generated Annotation Comments

When you run mix ecto_annotate --annotate, it adds comments like this to your schema files:

defmodule MyApp.User do
  use Ecto.Schema

  # == Schema Information
  #
  # Table name: users
  #
  # Primary Key: integer id
  #
  # Columns:
  #   age : integer
  #   balance : decimal [default: "0.0", precision: 10, scale: 2]
  #   bio : text
  #   email : string [null: :false]
  #   is_active : boolean [default: :true]
  #   name : string
  #
  # Indexes:
  #   index_users_on_email: [email] (unique)
  #
  # Foreign Keys:
  #   user_id -> users.id (on_delete: delete_all)
  #
  # Associations:
  #   has_one :profile -> MyApp.Profile (integer id)
  #   has_many :posts -> MyApp.Post (integer id)

  schema "users" do
    field :email, :string
    field :name, :string
    # ... rest of schema
  end
end

Features in Detail

Primary Key Detection

Index Display

Foreign Key Details

Binary ID Detection

Development

To contribute or develop locally:

git clone <repository>
cd ecto_annotate
mix deps.get
mix test
mix format  # Format code

License

MIT