Skip to content

Set up annotaterb for automatic model schema annotation#97

Merged
danielpaul merged 2 commits into
mainfrom
claude/pensive-hopper-uuZ1u
Jun 5, 2026
Merged

Set up annotaterb for automatic model schema annotation#97
danielpaul merged 2 commits into
mainfrom
claude/pensive-hopper-uuZ1u

Conversation

@danielpaul
Copy link
Copy Markdown
Owner

What

Sets up the annotaterb gem so model files (and their factories) carry an up-to-date schema annotation, and keeps them in sync automatically.

annotaterb is the actively-maintained successor to the original annotate gem and is compatible with Rails 8.

Changes

  • Gemfile — add gem "annotaterb" to the :development group; Gemfile.lock locks annotaterb (4.22.0).
  • .annotaterb.yml — config generated by rails g annotate_rb:install (gem defaults). Annotations are placed at the top of the file (position: before) and frozen_string_literal magic comments are preserved above them.
  • lib/tasks/annotate_rb.rake — rake hook that automatically annotates models after bin/rails db:migrate in development. Added a # frozen_string_literal: true comment to the generated file so it passes the project's RuboCop config.
  • Annotations added to app/models/{user,org}.rb and spec/factories/{users,orgs}.rb. This also corrects a stale column order in the pre-existing User annotation so it matches the live schema.

How it works going forward

After this lands, running bin/rails db:migrate re-annotates models automatically. To skip, set ANNOTATERB_SKIP_ON_DB_TASKS=1. To annotate on demand: bundle exec annotaterb models.

Verification

  • bundle install succeeds; annotaterb 4.22.0 installed.
  • rails g annotate_rb:install generated the config + rake hook.
  • bundle exec annotaterb models annotated the models/factories; re-running reports "Model files unchanged" (idempotent).
  • Confirmed the db:migrate hook re-annotates a reverted model automatically.
  • RuboCop passes on all changed Ruby files.
  • App boots and FactoryBot.lint builds both factories successfully.

Note: unrelated db/*_schema.rb changes that db:migrate produced in this environment (a [8.0][8.1] schema-format header bump) were intentionally reverted to keep this PR focused on the annotaterb setup.

https://claude.ai/code/session_01Ra2ZHPT8zux5xh8Swo2YmJ


Generated by Claude Code

Add the annotaterb gem so model schema annotations stay in sync with
the database automatically.

- Add gem "annotaterb" to the :development group and lock it (4.22.0)
- Generate .annotaterb.yml config and lib/tasks/annotate_rb.rake hook,
  which auto-annotates models after db:migrate in development
- Add a frozen_string_literal magic comment to the generated rake task
  so it satisfies the project's RuboCop config
- Annotate existing models and their factories (User, Org); this also
  corrects the stale column order in the User annotation to match the
  live schema

https://claude.ai/code/session_01Ra2ZHPT8zux5xh8Swo2YmJ
@danielpaul danielpaul marked this pull request as ready for review June 5, 2026 03:59
@danielpaul danielpaul merged commit 34046a5 into main Jun 5, 2026
4 checks passed
@danielpaul danielpaul deleted the claude/pensive-hopper-uuZ1u branch June 5, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants