6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Rails】モデルの上にDBの設計情報が出てくる? annotateが便利なんだ

6
Posted at

annotateとは?

モデルの上にDBの設計情報を自動で書いてくれるGemでござる。

使うとどうなる?

実行前

class User < ApplicationRecord
end

実行後

# == Schema Information
#
# Table name: users
#
# id    :bigint
# name  :string
# email :string
#

class User < ApplicationRecord
end

→ モデルを見るだけでカラムが分かる!
SUGOINE☆

メリット

① DBを探しに行かなくていい

通常:
schema.rbを開く
テーブルを探す
カラムを確認

annotateあり:
→ モデルを見るだけ!便利!

インストールのしかた

Gemfile

group :development do
  gem 'annotate'
end

必ず development(開発環境)の中に記載しよう。
そしたら

bundle install

これだけ!!( ^ω^ )

使い方

bundle exec annotate

マイグレーション後に実行:

rails db:migrate
bundle exec annotate

自動化がめっちゃおすすめ

毎回コマンドを打つのが面倒な場合

rails g annotate:install

これで:
db:migrate後に自動でannotateが実行されます

まとめ

annotate =
「モデルにDBの説明を書いてくれる便利ツール」

Gemfile の中に
「gem annotate」を入れるだけ( ◠‿◠ )

6
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?