Set up annotaterb for automatic model schema annotation#97
Merged
Conversation
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
…-uuZ1u # Conflicts: # Gemfile.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Sets up the
annotaterbgem so model files (and their factories) carry an up-to-date schema annotation, and keeps them in sync automatically.annotaterbis the actively-maintained successor to the originalannotategem and is compatible with Rails 8.Changes
Gemfile— addgem "annotaterb"to the:developmentgroup;Gemfile.locklocksannotaterb (4.22.0)..annotaterb.yml— config generated byrails g annotate_rb:install(gem defaults). Annotations are placed at the top of the file (position: before) andfrozen_string_literalmagic comments are preserved above them.lib/tasks/annotate_rb.rake— rake hook that automatically annotates models afterbin/rails db:migratein development. Added a# frozen_string_literal: truecomment to the generated file so it passes the project's RuboCop config.app/models/{user,org}.rbandspec/factories/{users,orgs}.rb. This also corrects a stale column order in the pre-existingUserannotation so it matches the live schema.How it works going forward
After this lands, running
bin/rails db:migratere-annotates models automatically. To skip, setANNOTATERB_SKIP_ON_DB_TASKS=1. To annotate on demand:bundle exec annotaterb models.Verification
bundle installsucceeds;annotaterb 4.22.0installed.rails g annotate_rb:installgenerated the config + rake hook.bundle exec annotaterb modelsannotated the models/factories; re-running reports "Model files unchanged" (idempotent).db:migratehook re-annotates a reverted model automatically.FactoryBot.lintbuilds both factories successfully.https://claude.ai/code/session_01Ra2ZHPT8zux5xh8Swo2YmJ
Generated by Claude Code