Created
December 18, 2014 09:11
-
-
Save StanBoyet/0b81b74828e4c4ff3ed2 to your computer and use it in GitHub Desktop.
This file contains 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