gem annotate をバージョンアップしたら動作しなくなった
前提
gem annotate とは
例えば以下のように、モデルファイルにテーブルの情報をコメント形式で作成してくれるgemです。
Class SakeBrand < ApplicationRecord # == Schema Information # # Table name: sake_brands # # id :bigint not null, primary key # name(銘柄名) :string not null # name_kana(銘柄名かな) :string not null # created_at :datetime not null # updated_at :datetime not null # sake_brewery_id(酒蔵ID) :bigint # # Indexes # # index_sake_brands_on_sake_brewery_id (sake_brewery_id) # # Foreign Keys # # fk_rails_... (sake_brewery_id => sake_breweries.id) #
バリデーションを書きたいときなどに、
「カラム名何だったっけ?」とschema.rbをわざわざ見に行かなくても済むので便利です。
かゆいところに手が届くってやつですね。
状況
dependabotさんが「annotateのバージョンアップができるよー」とお知らせしてくれたので、
サラッと見てバージョンアップしました。というかしちゃいました。
新しいマイグレーションファイルを作成して bin/rails db:migrate
を実行すると..
あれー???何もしてくれないよーーー(T_T)
bundle exec annotate
をやってみても何もしてくれない。
どうしちゃったん。
対応
公式によると、
バージョン3系ではデフォルトでannotateを追加しないよう変更したとのこと。
なるほど💡
親切にREAD.MEに書いてくれているではないか。
ということで、annotateを導入したときに作成した auto_annotate_models.rake に、
以下のように 'models' => 'true'
を追加しましょう。
Annotate.set_defaults( ... 'models' => 'true', ...
気を取り直して、 bundle exec annotate
を実行します。
% bundle exec annotate Annotated (9): ..., ...., ....
やったね!