-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure db:seed runs before spree_sample:load #4907
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your collaboration, @lsizani 🙌 🙌 It's a great and long-due improvement 🙂
I left some suggestions. We can probably take the occasion to leverage the new flexibility also in the installer by removing the && @load_seed_data
check here:
@load_sample_data = options[:sample] && @run_migrations && @load_seed_data |
cecf524
to
858e37f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left a comment. Also, I'm curious about what happens if db:seed
and sample:load
are run independently, one after the other. Is db:seed
executed twice in that case?
It will run |
858e37f
to
f20a8b1
Compare
@lsizani do you know if we have any spec that verify we can run seeds multiple times without breaking or creating duplicate records? |
We do not... But I'm sure I can write one |
bb272d4
to
e191991
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Great change! LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it's perfect! ❤️ Last ask, could you please rebase from master so that CI runs? 🙏
397224f
to
320235f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that with this change in the solidus installer, we are executing seeds twice: once during the seeds step and another during the samples step.
I think this is not ideal, no matter if it's safe to run seeds multiple times. Maybe we can merge populate_seed_data
and load_sample_data
to call a single rake command in case we want both?
6a4fdff
to
64a4c0f
Compare
64a4c0f
to
a14fcd0
Compare
Hey @lsizani! I lost track of this PR, I didn't notice you updated it following my suggestions. I will re-review it now, in the meantime there are some conflict with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some questions, thanks again Lunga!
describe "Load seeds multiple times" do | ||
it "doesn't duplicate records" do | ||
4.times do | ||
pid = fork { Spree::Core::Engine.load_seed } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this local variable be overridden at each cycle? Might this interfere with the process killing in the ensure block (it only always kills the last process but previous ones might still be executing)?
@@ -3,8 +3,11 @@ | |||
begin | |||
north_america = Spree::Zone.find_by!(name: "North America") | |||
rescue ActiveRecord::RecordNotFound | |||
puts "Couldn't find 'North America' zone. Did you run `rake db:seed` first?" | |||
puts "That task will set up the countries, states and zones required for Spree." | |||
puts <<~TEXT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this DX, thanks!
expect { | ||
Spree::Core::Engine.load_seed | ||
expect do | ||
pid = fork { Spree::Core::Engine.load_seed } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a separate process here instead of just running load_seed
and load_sample
one after the other?
Summary
When running
bundle exec rake spree_sample:load
against an empty database, an exception is raised indb/samples/tax_rates.rb
on account of missing aSpree::Zone
with the name "North America.In this PR we:
db:seed
as a dependent task ofspree_sample:load
Spree::Zone
"North America" is present indb/samples/tax_rates.rb
before running the rest of the seed file. This makes it consistent with db/samples/shipping_methods.rbChecklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed:
I have updated the README to account for my changes.