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 support for multiple DBs in Rails >= 6.1 #930

Merged
merged 7 commits into from Feb 6, 2024

Conversation

joshwestbrook
Copy link
Contributor

@joshwestbrook joshwestbrook commented Jan 29, 2024

Added support for performing create, migrate, drop, and load_schema on individual databases when using multiple databases in Rails >= 6.1

NOTE: Will add integration tests if desired by maintainer

Checklist

  • Feature branch is up-to-date with master (if not - rebase it).
  • Added tests.
  • Added an entry to the Changelog if the new
    code introduces user-observable changes.
  • Update Readme.md when cli options are changed

@joshwestbrook joshwestbrook marked this pull request as ready for review January 29, 2024 19:37
Comment on lines 138 to 139
return unless configured_databases.present? && block_given?

Copy link
Owner

Choose a reason for hiding this comment

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

can just remove this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the configured_databases.present? piece is fine since it'll just be empty otherwise 😄 Since this is an internal API, if you're comfortable not having the safety of block_given? then I can yoink that out as well!

Copy link
Owner

Choose a reason for hiding this comment

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

👍

Comment on lines 197 to 211
# drop individual databases in multi DB setups
ParallelTests::Tasks.for_each_database do |name|
desc "Drop test #{name} database via db:drop:#{name} --> parallel:drop:#{name}[num_cpus]"
task "drop:#{name}".to_sym, :count do |_, args|
ParallelTests::Tasks.run_in_parallel(
[
$0,
"db:drop:#{name}",
"RAILS_ENV=#{ParallelTests::Tasks.rails_env}",
"DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
],
args
)
end
end
Copy link
Owner

Choose a reason for hiding this comment

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

can we reduce the copy paste by making for_each_database also return nil for the base db ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So just to be clear, for this example db:drop drops all databases, not the primary/default DB in a multi-DB setup. But I can definitely adjust this a bit so we don't need two separate blocks to define the "drop all" and the "drop individual" tasks!

Copy link
Owner

Choose a reason for hiding this comment

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

that sounds good :)

@grosser
Copy link
Owner

grosser commented Feb 6, 2024

nice!

@grosser
Copy link
Owner

grosser commented Feb 6, 2024

looks like it's needs a if defined?(ActiveRecord) check

@@ -135,6 +135,8 @@ def configured_databases
end

def for_each_database(&block)
return unless defined?(ActiveRecord)

# Use nil to represent all databases
block&.call(nil)
Copy link
Owner

Choose a reason for hiding this comment

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

needs to be after this to preserve original behavior ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh gosh, nice catch 😄 0f8e6a8

@grosser grosser merged commit f776f62 into grosser:master Feb 6, 2024
11 of 13 checks passed
@grosser
Copy link
Owner

grosser commented Feb 6, 2024

FYI cleanup

@grosser
Copy link
Owner

grosser commented Feb 6, 2024

4.5.0

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.

None yet

2 participants