[Feature Request] Allow loading of multiple seed files

I think it would be beneficial to loop over the array of paths in paths[“db/seeds.rb”] instead of just grabbing the first one and loading it. Might be good to rename it"db/seeds" and prefill it with “db/seed.rb” then.

This would especially be helpful in engines that already add migrations. Right now this can still be achieved by hooking into the rake task but it’s not as great (either runs after the app’s seeds that may be dependent on it or it runs before the whole task, missing the abort_if_pending_migrations check which loads the environment and config).

If this is something you’d be interested in, I can create a pull request!

https://github.com/rails/rails/blob/8898a0ae2a0d5c8826fe08bbf4ccd10745802f9e/railties/lib/rails/engine.rb#L548

https://github.com/rails/rails/blob/fdc219e0f857c372748296eae9cc5828ffb2c2c3/activerecord/lib/active_record/railties/databases.rake

Thanks,

Tom

You can use db/seeds.rb as an entry point to load more seeds files:


# db/seeds.rb

load "./seeds/admin_seeds"

load "./seeds/customer_seeds"

load "./seeds/more_seeds"

You can also set your own seed loader: rails/database_tasks.rb at main · rails/rails · GitHub

Thanks Kir, I’ve looked into that a bit and it seems like it’d help from the application perspective, but coming from a gem, you still wouldn’t be able to hook into the application’s seed loading process.