Skip to content

Instantly share code, notes, and snippets.

@StanBoyet
Created December 18, 2014 09:11
Show Gist options
  • Save StanBoyet/0b81b74828e4c4ff3ed2 to your computer and use it in GitHub Desktop.
Save StanBoyet/0b81b74828e4c4ff3ed2 to your computer and use it in GitHub Desktop.
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