LoginSignup
0
1

More than 1 year has passed since last update.

ridgepoleした後に、annotateを同時に実行する。

Last updated at Posted at 2021-06-14

ridgepoleをした後に、annotateしてくれる流れを記載します。

以下のように annotate を実行するようにします。

Rake::Task['annotate_models'].invoke if Rails.env.development?

annotate_models は rails g annotate:install 実行後に利用可能となります。
お忘れなく。
cf: https://github.com/ctran/annotate_models#configuration-in-rails

ridgepoleをtaskにまとめて実行します。
以下のように annotate_models を追加したら終了です。

$ cat lib/tasks/ridgepole.rake
# frozen_string_literal: true

namespace :ridgepole do
  desc 'Apply database schema'
  task apply: :environment do
    ridgepole('--apply', "-E #{Rails.env}", "--file #{schema_file}")
    Rake::Task['db:schema:dump'].invoke if Rails.env.development?
    Rake::Task['annotate_models'].invoke if Rails.env.development? # これを追加する。
  end

  desc 'Export database schema'
  task export: :environment do
    ridgepole('--export', "-E #{Rails.env}", '--split', "--output #{schema_file}")
  end

  private def schema_file
    Rails.root.join('db/schemas/Schemafile')
  end

  private def config_file
    Rails.root.join('config/database.yml')
  end

  private def ridgepole(*options)
    command = ['bundle exec ridgepole', "--config #{config_file}"]
    system [command + options].join(' ')
  end
end

スキーマを適応する。

$ bundle exec rake ridgepole:apply 

【新卒】→ SIer入社、ドキュメントの日々
【転職】→ IT上場企業、主にインフラ担当
【転職】→ ベンチャーIT企業、主にインフラ担当
【現在】→ 起業

IT業界限定で全ての方に向けて、
今だけ限定で無料キャリア相談実施中。
オンライン面談予約は http://nekakoshi.youcanbook.me

0
1
0

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
0
1