finds.dev← search

// the find

ctran/annotate_models

★ 4,490 · Ruby · NOASSERTION · updated Aug 2024

Annotate Rails classes with schema and routes info

annotate_models writes a comment block at the top or bottom of your ActiveRecord model files showing the current database schema — column names, types, indexes, foreign keys. It also optionally annotates routes.rb with `rake routes` output. Rails shops use it to avoid context-switching to db/schema.rb every time they want to know what columns a model has.

Hooks into db:migrate automatically so annotations stay current without a manual step. The --show-indexes and --show-foreign-keys flags surface constraints that are otherwise invisible in day-to-day model editing. Supports factories, fixtures, serializers, and custom paths via --additional-file-patterns, so the schema comment lives next to every artifact that cares about it. The --frozen flag lets CI reject unannotated or stale annotations, which is a useful guardrail.

Last push was August 2024 and activity has been thin for a couple of years — open issues pile up without much triage. The WARNING in the README is real and undersells the risk: any leading comment block that looks like a prior annotation gets silently blown away, which bites you if you've manually added notes above the class. No support for non-ActiveRecord ORMs or databases that aren't Postgres/MySQL/SQLite. The routes annotation ages out fast and tends to create noisy diffs in repos with many routes, making it more trouble than it's worth.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →