evanthegrayt / planter

🪴 Framework for seeding your rails application.
MIT License
4 stars 0 forks source link

Add progress bar. #24

Open evanthegrayt opened 3 years ago

evanthegrayt commented 3 years ago

I've seen @hkn34 implement a nice progress bar in some of our work projects. This feature would be a great addition.

There should be a config option to enable/disable it. Probably default to true.

Planter.configure do |config|
  config.progress_bar = true
end

It would also be nice to have a flag for the command line that can also enable/disable it at runtime, in case you want to change it for one run only. It would be a pain to edit the initializer every time. If not a flag, than an environmental variable?

rails planter:seed --progress
# or
rails planter:seed PROGRESS=true
evanthegrayt commented 3 years ago

This is an interesting issue. I've got it mostly done on #25, but when seeding from a parent record, there is a progress bar for every parent record. This is unacceptable. I've tried to hack it, but there are issues. Honestly, it's making me re-think how we're even accomplishing seeding from parent records. Why are we doing all the work through associations, when we could pluck all the parent model's IDs, and create records directly in the current table using those IDs? Then, to solve the weirdness with the progress bar, we build the list of records via code (multiply each parent record by number_of_records), store them in the RecordList object, and then initiate the progress bar normally.

evanthegrayt commented 3 years ago

Also, just realized that we need a super easy way for the user to implement the progress bar when they have a custom seeding method. There's definitely some things to consider here, but it's fun problems to solve, and it's having the nice effect of shedding light on holes in my design.