-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support ActiveRecord
7.2
#53
Conversation
We need to accomodate the changes in this commit: rails/rails@85742ce `#query_cache` used to return a `Hash`, but it now returns a custom class. Fortunately, both `Hash` and this custom class implement a `#size` method which works the same as doing `keys.size`.
`ActiveRecord::Base` now has the `with_connection` method, which is like the old `connection` method on `ActiveRecord::Base` but it yields the connection to a block instead of returning it: rails/rails@22f41a1 This new method is now used for transactions, so in order for transactions to work we need to implement an equivalent in Replica Pools.
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.
looks good, but one minor change + question
|
||
# Just helping out the bundler resolver: | ||
gem "rails", "> 6.0" | ||
end |
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.
would it make more sense to make different groups instead of using ENV?
eg
group :rails7_1 do
# ...
end
group :rails7_2 do
# ...
end
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.
The nice thing about the ENV variable is that we can set it to any version of ActiveRecord without having to update the Gemfile. But happy to switch it to this if you prefer!
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.
With this diff:
diff --git a/Gemfile b/Gemfile
index 1c249f6..0170d9d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,15 +2,21 @@ source "https://rubygems.org"
gemspec
group :development do
- # This allows us to easily switch between different versions of ActiveRecord.
- # To use this in local dev, you can do:
- # ```
- # rm Gemfile.lock
- # ACTIVE_RECORD_VERSION="7.1" bundle install
- # ```
- active_record_version = ENV.fetch("ACTIVE_RECORD_VERSION", nil)
- gem "activerecord", "~> #{active_record_version}.0" if active_record_version&.length&.positive?
-
# Just helping out the bundler resolver:
gem "rails", "> 6.0"
end
+
+# This allows us to easily switch between different versions of ActiveRecord.
+# To use this in local dev, you can do:
+# ```
+# rm Gemfile.lock
+# bundle config set --local with activerecord_7_1
+# bundle install
+# ```
+group :activerecord_7_1, optional: true do
+ gem "activerecord", "~> 7.1.0"
+end
+
+group :activerecord_7_2, optional: true do
+ gem "activerecord", "~> 7.2.0"
+end
after running:
rm Gemfile.lock
bundle install
I'm getting this error
[!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.
You specified: activerecord (~> 7.1.0) and activerecord (~> 7.2.0). Bundler cannot continue.
# from /Users/aidanlavis/git/replica_pools/Gemfile:21
# -------------------------------------------
# group :activerecord_7_2, optional: true do
> gem "activerecord", "~> 7.2.0"
# end
# -------------------------------------------
Running:
bundle config set --local with activerecord_7_1
does not help
ActiveRecord
. Test 7.1 and 7.2 on CI.:focus
metadata for ease of testing.#query_cache
used to return aHash
, but it now returns a custom class. Fortunately, bothHash
and this custom class implement a#size
method which works the same as doingkeys.size
.with_connection_proxy
method.ActiveRecord::Base
now has thewith_connection
method, which is like the oldconnection
method onActiveRecord::Base
but it yields the connection to a block instead of returning it: rails/rails@22f41a1This new method is now used for transactions, so in order for transactions to work we need to implement an equivalent in Replica Pools.