Fixes issues with update_all, increment, and decrement #282
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all, I'm well aware that this gem is abandoned, yet I'm submitting this PR in case someone runs into the same problem as me and comes here to the PRs section looking for answers.
This upstream PR #223 broke some usages of update_all. Both increment and decrement use update_all.
For example a call to
model.decrement!(:counter)generates an UPDATE query withSET "counter" = NULLinstead of the correctSET "counter" = COALESCE("counter", 0).@Laykou first noticed this problem https://github.com/citusdata/activerecord-multi-tenant/pull/223/files#r1743665204 and @Amit909Singh mentioned they fixed it in #223 (comment).
In this PR, I cherry-picked his commit Amit909Singh@c08b636 and added tests for the
incrementanddecrementcases.All tests are passing for Rails/ActiveRecord versions 7.0, 7.1, 7.2, and 8.0.
The tests are failing for 6.0 and 6.1, but I didn't care much since they are old versions.
The tests are also failing for 8.1, I didn't look into it either since I'm still on 7.2.
I ran the tests manually instead of using Github actions, like so: