How to Specify a Single File to Be Seed Only

How to seed a one file only with sequelize-cli?

To run a specific seed indicate --seed <seed_file_nams.js>:

sequelize db:seed --seed my_seeder_file.js

Adonis: How do I seed only a specific file?

Looks like I should have run adonis seed --help. Here is how to do it in production.

adonis seed --files IndustrySeeder.js --force

Laravel 4 db seed specific seeder file

You can call individual seed classes by their class name.
From the docs.

By default, the db:seed command runs the DatabaseSeeder class, which
may be used to call other seed classes. However, you may use the
--class option to specify a specific seeder class to run individually:

php artisan db:seed --class=ProductTableSeeder

In the example above, the ProductTableSeeder class should exist in database/seeds.

Is it possible to rake db:seed just one model? - Rails 4

I think you should use your custom rake task to build what you want. The task rake db:seed is just a helper to get you organised from the beginning. But you can also add under YOUR_APP/lib/tasks your custom rake tasks.

http://cobwwweb.com/how-to-write-a-custom-rake-task

Is there a way to db:seed only one table in Rails?

With below custom rake file, you can have multiple seed files in db/seeds/ folder.

# lib/tasks/custom_seed.rake
# lib/tasks/custom_seed.rake
namespace :db do
namespace :seed do

Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename|
task_name = File.basename(filename, '.rb').intern

task task_name => :environment do
load(filename)
end
end

task :all => :environment do
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].sort.each do |filename|
load(filename)
end
end

end
end

Then, in order to run specific seed file, you can just run

rake db:seed:seed_file_name

To run all the seeds file with order in that db/seeds folder, run below command

rake db:seed:all

Adding a custom seed file

Start by creating a separate directory to hold your custom seeds – this example uses db/seeds. Then, create a custom task by adding a rakefile to your lib/tasks directory:

# lib/tasks/custom_seed.rake
namespace :db do
namespace :seed do
Dir[Rails.root.join('db', 'seeds', '*.rb')].each do |filename|
task_name = File.basename(filename, '.rb')
desc "Seed " + task_name + ", based on the file with the same name in `db/seeds/*.rb`"
task task_name.to_sym => :environment do
load(filename) if File.exist?(filename)
end
end
end
end

This rakefile accepts the name of a seed file in the db/seeds directory (excluding the .rb extension), then runs it as it would run seeds.rb. You can execute the rake task by issuing the following from the command line:

rake db:seed:file_name # Name of the file EXCLUDING the .rb extension 

Update: Now it should also list the seed tasks when running rake --tasks or rake -T.



Related Topics



Leave a reply



Submit