[Feature][Generators] Add support for generation of a db seed as well in the generate command

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Feature][Generators] Add support for generation of a db seed as well in the generate command

Anurag Tiwari
Recently while developing many times I found there should be support to generate rails seed for the model as well. It can be as simple as an empty file with some basic boilerplate.

Enter code here...
namespace :seed do
  desc
'Generate an empty seed file, Usage => rake seed:create seed_name'
  task create
: :environment do
    argument
= ARGV[1]
    argument
= "_#{ARGV[1]}" if argument.present?
    seed_path
= "db/seeds/#{Time.now.to_i}#{argument}_seed.rb"
   
FileUtils.touch(seed_path)
   
exit
 
end
end

I did something like this for all our organization products because we needed seeds to run in specific order. Need your reviews on this, is it a good idea to have the generator in the rails itself?

Additional details are here -> Medium Blog

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.