Created
December 12, 2014 15:18
-
-
Save styx/beb1aa5210c3afb45fd9 to your computer and use it in GitHub Desktop.
Disable a task in production environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DISABLED_TASKS = [ | |
'db:drop', | |
'db:migrate:reset', | |
'db:schema:load', | |
'db:seed', | |
# ... | |
] | |
namespace :db do | |
desc "Disable a task in production environment" | |
task :guard_for_production do | |
if Rails.env.production? | |
if ENV['I_KNOW_THIS_MAY_SCREW_THE_DB'] != "1" | |
puts 'This task is disabled in production.' | |
puts 'If you really want to run it, call it again with `I_KNOW_THIS_MAY_SCREW_THE_DB=1`' | |
exit | |
else | |
require 'heroku' | |
puts 'Making a backup of the database, just in case...' | |
puts `heroku pgbackups:capture` | |
end | |
end | |
end | |
end | |
DISABLED_TASKS.each do |task| | |
Rake::Task[task].enhance ['db:guard_for_production'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment