Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Disabling rake db:reset in production


  • Please log in to reply
No replies to this topic

#1 Ohm

Ohm

    Driver

  • Moderators
  • 479 posts
  • LocationCopenhagen

Posted 02 April 2014 - 10:36 AM

We just had a developer accidentally run

rake db:reset

on our production database.

 

Why Rails not disables or at least guards this by default, I do not know.

 

We implemented this little check to disable the call in the future.

# lib/tasks/db.rake
if Rails.env == 'production'
  tasks = Rake.application.instance_variable_get '@tasks'
  tasks.delete 'db:reset'
  tasks.delete 'db:drop'

  namespace :db do
    desc 'db:reset not available in this environment'
    task :reset do
      puts 'db:reset has been disabled'
    end

    desc 'db:drop not available in this environment'
    task :drop do
      puts 'db:drop has been disabled'
    end
  end
end

... now back to fiddling with backups.  :(


Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users