Run seeds.rb file only against Development.
In my Rails seeds file I sometimes have the need to destroy all records for a given model. This is extremely dangerous in production. One key slip and you could potentially trash the entire database and then you'd need to restore from a backup. An entire morning wasted.
Here's a simple trick to only run destructive seed instructions in Development.
case Rails.env
when 'development'
Person.delete_all
Address.delete_all
Person.create!(name: 'Sergio Tapia')
end
No more botched seed runs.
Written by Sergio Tapia Gutierrez
Related protips
2 Responses
Do not use #create
in seeds.rb
. Use #create!
to be sure that your models are created.
over 1 year ago
·
Good idea! I agree. I'll edit the tip.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#