Skip to content
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

Add option to skip call to purge_before_load in parallel::load_schema and parallel::load_structure #529

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Tolsto
Copy link

@Tolsto Tolsto commented Oct 7, 2016

It should be possible to skip the call to purge_before_load in the parallel::load_schema and parallel::load_structure tasks as this resembles the behaviour of db:structure:load and db:schema:load tasks.

@grosser
Copy link
Owner

grosser commented Oct 7, 2016

  • why do you want to disable that ?
  • any idea why this was added ... I'd guess convenience helper to make test runs not fail ... but maybe it should be disabled by default ?
  • I'd prefer an ENV var to switch this since having purge as the second argument does not feel very intuitive to me ...

@Tolsto
Copy link
Author

Tolsto commented Oct 10, 2016

  • We run a Rails setup in which we use both schema.rb and structure.sql. It requires us to load the structure directly after the schema. We therefore cannot purge the DB before loading the structure file.
  • I agree that an ENV var is the cleaner approach, I've updated the pull request.
  • I don't know why the functionality was added in the first place. Disabling it by default would make sense because it is also the expected behaviour of db:schema:load and db:structure:load. However, I feel that such a change should be announced at least one version on advance.

@grosser
Copy link
Owner

grosser commented Oct 10, 2016

announcing things does not help anyone ... nobody is reading 'updates' :D

@grosser
Copy link
Owner

grosser commented Oct 10, 2016

errored: NoMethodError: undefined methodlowercase' for "nil":String`

ideally also add a test that fails without this ...

def purge_before_load
"db:test:purge" if Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0')
"db:test:purge" if purge_before_load? && Gem::Version.new(Rails.version) > Gem::Version.new('4.2.0')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot use Rails.version since this might be used without rails ... ActiveRecord::Version::STRING should work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be used without Rails? All tasks that call this method depend on Rails' rake tasks

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always though as this only needing ActiveRecord to work ... tasks come from https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake ... which is a railtie ... adding rails to the mix seems to still be unnecessary to me ... maybe ActiveRecord.version => #<Gem::Version "5.0.0.1">

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah ... does not work on rails 3 ... maybe ActiveRecord::VERSION::STRING is best ...

subject { ParallelTests::Tasks.purge_before_load }
context 'Rails version is 4.3.1' do
before do
class Rails; end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defining a class at runtime is a bad idea :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you stub the call to Rails.version instead?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define it global ... and then either add it there or stub it ...

@@ -29,6 +29,42 @@
end
end

describe '.purge_before_load?' do
subject { ParallelTests::Tasks.purge_before_load? }
context "PURGE_BEFORE_LOAD is set to 'false'" do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'd test this like so: (less nesting / context switching and 1 change per test)

it "is true" do
  exoect(subject).to eq true
end

it "is false when set to false" do
  with_env(PURGE_BEFORE_LOAD: 'false') do
    expect(subject).to eq false
  end
end

it "is true when set to true" do
  with_env(PURGE_BEFORE_LOAD: 'true') do
    expect(subject).to eq true
  end
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll refactor it. However, I prefer to use expect(ENV) to set envs because it will fail if the env doesn't get used anymore because someone changed the code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just FYI either way works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants