LoginSignup
0
1

More than 5 years have passed since last update.

rake task でridgepole 実行

Posted at

こちらの記事を参考に以下を修正しました。(ほぼ同じ)
- Rails.envを考慮
- annotateを実行
- 出力をsplit
- rspecの前に流す

lib/tasks/ridgepole.rake
# frozen_string_literal: true

# see https://qiita.com/lhside/items/0dcad79d9b801e34bc7c
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/schema/Schemafile') # rubocop:disable Rails/FilePath
  end

  private def config_file
    Rails.root.join('config/database.yml') # rubocop:disable Rails/FilePath
  end

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

spec/spec_helper.rb
# frozen_string_literal: true

require 'rake'

## ~~~~略~~~~
RSpec.configure do |config|
  config.before(:suite) do
    Rails.application.load_tasks
    Rake.application['ridgepole:apply'].invoke
## ~~~~略~~~~
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