diff options
Diffstat (limited to 'config/initializers/active_record_locking.rb')
-rw-r--r-- | config/initializers/active_record_locking.rb | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/config/initializers/active_record_locking.rb b/config/initializers/active_record_locking.rb index 21ff323927b..1bd1a12e4b7 100644 --- a/config/initializers/active_record_locking.rb +++ b/config/initializers/active_record_locking.rb @@ -1,7 +1,10 @@ # rubocop:disable Lint/RescueException -# Remove this monkey-patch when all lock_version values are converted from NULLs to zeros. -# See https://gitlab.com/gitlab-org/gitlab-ce/issues/25228 +# Remove this monkey patch when we move to Rails 5.1, because the bug has been fixed in https://github.com/rails/rails/pull/26050. +if Rails.gem_version >= Gem::Version.new("5.1") + raise "Remove this monkey patch: #{__FILE__}" +end + module ActiveRecord module Locking module Optimistic @@ -16,12 +19,7 @@ module ActiveRecord return 0 if attribute_names.empty? lock_col = self.class.locking_column - previous_lock_value = send(lock_col).to_i - - # This line is added as a patch - previous_lock_value = nil if previous_lock_value == '0' || previous_lock_value == 0 - increment_lock attribute_names += [lock_col] @@ -32,7 +30,8 @@ module ActiveRecord affected_rows = relation.where( self.class.primary_key => id, - lock_col => previous_lock_value + # Patched because when `lock_version` is read as `0`, it may actually be `NULL` in the DB. + lock_col => previous_lock_value == 0 ? [nil, 0] : previous_lock_value ).update_all( attributes_for_update(attribute_names).map do |name| [name, _read_attribute(name)] @@ -64,21 +63,13 @@ module ActiveRecord # This is patched because we want `lock_version` default to `NULL` # rather than `0` - if Gitlab.rails5? - class LockingType - def deserialize(value) - super - end - - def serialize(value) - super - end + class LockingType + def deserialize(value) + super end - else - class LockingType < SimpleDelegator - def type_cast_from_database(value) - super - end + + def serialize(value) + super end end end |