Skip to content

Instantly share code, notes, and snippets.

@ryenski
Created May 28, 2024 16:33
Show Gist options
  • Save ryenski/559d651fae71a11e8b8e091ebc5b4892 to your computer and use it in GitHub Desktop.
Save ryenski/559d651fae71a11e8b8e091ebc5b4892 to your computer and use it in GitHub Desktop.
Protect production environment from destructive rake tasks
desc 'Raise exception if used in production'
task protect_prod: [:environment] do
raise 'This task cannot be run in production' if Rails.env.production?
end
['db:drop', 'db:reset', 'db:seed'].each do |t|
Rake::Task[t].enhance ['protect_prod']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment