Skip to content

Instantly share code, notes, and snippets.

@lhside
Last active November 23, 2017 05:28
Show Gist options
  • Save lhside/84d889d91eba6d9c73ee to your computer and use it in GitHub Desktop.
Save lhside/84d889d91eba6d9c73ee to your computer and use it in GitHub Desktop.
RakeでRidgepoleコマンドを実行する ref: https://qiita.com/lhside/items/0dcad79d9b801e34bc7c
bundle exec ridgepole --apply --file Schemafile --config config/database.yml
Apply ridgepole schema
$ bundle exec rake ridgepole:apply
Export ridgepole schema
$ bundle exec rake ridgepole:export
namespace :ridgepole do
desc 'Apply database schema'
task apply: :environment do
ridgepole('--apply', "--file #{schema_file}")
Rake::Task['db:schema:dump'].invoke
end
desc 'Export database schema'
task export: :environment do
ridgepole('--export', "--output #{schema_file}")
end
private
def schema_file
Rails.root.join('Schemafile')
end
def config_file
Rails.root.join('config/database.yml')
end
def ridgepole(*options)
command = ['bundle exec ridgepole', "--config #{config_file}"]
system [command + options].join(' ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment