Automatically adds schema comments (columns, indexes, triggers, enums) to Rails models.
-
Annotates Rails models with:
- Columns and types
- Default values and constraints
- Enums with values
- Indexes (only if present)
- Triggers (only if present)
-
Skips unchanged annotations
-
Smart formatting with aligned columns
Example:
# == Annotato Schema Info
# Table: users
#
# Columns:
# id :bigint not null, primary key
# email :string not null, unique
# role :string default("user"), not null
#
# Enums:
# role: { user, admin }
class User < ApplicationRecord
end
Add this line to your Gemfile:
gem "annotato"
Then run:
bundle install
To annotate all models, run:
bundle exec rake annotato:models
You can now pass one or multiple model names to the task.
# Annotate only the User model
rake annotato:models[User]
# Annotate multiple models (User and Admin::Account)
rake annotato:models["User,Admin::Account"]
rake annotato:models[MODEL]
- Automatically loads all models via
Rails.application.eager_load!
- Modifies model files in place
- Replace existing Annotato and legacy annotate blocks
- Pass
MODEL
argument (single or comma-separated) to target specific models
To run tests:
bundle exec rspec
To check code coverage:
COVERAGE=true bundle exec rspec
Feel free to open issues or pull requests.
MIT