explaingit

ctran/annotate_models

4,486RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

A Ruby gem that automatically adds database schema comments to Rails model files, so you can see column names and types without leaving your code editor.

Mindmap

mindmap
  root((annotate_models))
    What it does
      Adds schema comments
      Runs after migrations
      Delete all annotations
    Files annotated
      Model files
      Test and fixture files
      Routes file
    Configuration
      Top or bottom placement
      Opt-out per file
      Post-migration auto-run
    Tech
      Ruby gem
      Rails only
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Auto-add schema comment blocks to Rails model files each time you run a migration.

USE CASE 2

Annotate test files, fixtures, and factory files so database column names are visible when writing tests.

USE CASE 3

Add a routes summary comment to routes.rb for quick URL reference without running rake routes.

Tech stack

RubyRails

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Annotate is a Ruby gem for Rails applications that automatically adds a comment block to your model files showing the current database table structure. When your database has a table called "line_items" with columns like id, quantity, and product_id, running the annotate command inserts a comment at the top or bottom of your model file that lists those columns along with their data types. This means you can see the database schema without leaving your code editor or running a separate query. Beyond model files, it can add the same kind of schema comments to related files: test files, fixture files, and factory files used by testing libraries like factory_bot. It can also annotate your routes.rb file with the full output of rake routes, giving you a quick reference to your app's URL structure right inside that file. Annotate integrates with Rails migrations. Once configured, it runs automatically every time you run a database migration, so your schema comments stay up to date without any manual step. You can also run it on demand from the command line, and there is a delete option to remove all annotations if you want to clean them out. Configuration is handled through a generated rake file where you can control whether annotations go at the top or bottom of files, which types of files get annotated, and whether the automatic post-migration run is active. Individual files can opt out by including a special comment string anywhere in the file. The gem is intended for development use only and is listed in the development group in a Gemfile. It supports geometric column types used with spatial database adapters like PostGIS, annotating them with geometry type and spatial reference information. Outside Rails, it can be used with explicit options pointing to your model directories.

Copy-paste prompts

Prompt 1
In my Rails app using annotate_models, configure annotations to appear at the bottom of model files and skip spec files.
Prompt 2
Set up annotate_models to run automatically after every Rails migration in my project.
Prompt 3
How do I remove all annotate_models comments from my Rails codebase at once using the delete command?
Prompt 4
Configure annotate_models to annotate factory_bot factory files alongside model files.
Prompt 5
My annotate_models schema comments do not show PostGIS geometry columns correctly, how do I fix the spatial reference output?
Open on GitHub → Explain another repo

← ctran on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.