Last active
April 4, 2017 20:54
-
-
Save dpaluy/7c7bb18348c3b1529664 to your computer and use it in GitHub Desktop.
Disable dangerous rake tasks in production
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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://www.developingandstuff.com/2014/06/disable-dangerous-rake-tasks-in.html