diff options
Diffstat (limited to 'config/initializers')
5 files changed, 17 insertions, 57 deletions
diff --git a/config/initializers/active_record_avoid_type_casting_in_uniqueness_validator.rb b/config/initializers/active_record_avoid_type_casting_in_uniqueness_validator.rb index 3e765469995..228ced32188 100644 --- a/config/initializers/active_record_avoid_type_casting_in_uniqueness_validator.rb +++ b/config/initializers/active_record_avoid_type_casting_in_uniqueness_validator.rb @@ -20,7 +20,7 @@ # # This bug was fixed in Rails 5.1 by https://github.com/rails/rails/pull/24745/commits/aa062318c451512035c10898a1af95943b1a3803 -if Rails.version.start_with?("5.1") +if Rails.gem_version >= Gem::Version.new("5.1") raise "Remove this monkey patch: #{__FILE__}" end diff --git a/config/initializers/active_record_locking.rb b/config/initializers/active_record_locking.rb index bfe41e6029a..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)] diff --git a/config/initializers/carrierwave_patch.rb b/config/initializers/carrierwave_patch.rb deleted file mode 100644 index c361784491d..00000000000 --- a/config/initializers/carrierwave_patch.rb +++ /dev/null @@ -1,42 +0,0 @@ -# This monkey patches CarrierWave 1.2.3 to make Google Cloud Storage work with -# extra query parameters: -# https://github.com/carrierwaveuploader/carrierwave/pull/2332/files -module CarrierWave - module Storage - class Fog < Abstract - class File - def authenticated_url(options = {}) - if %w(AWS Google Rackspace OpenStack).include?(@uploader.fog_credentials[:provider]) - # avoid a get by using local references - local_directory = connection.directories.new(key: @uploader.fog_directory) - local_file = local_directory.files.new(key: path) - expire_at = ::Fog::Time.now + @uploader.fog_authenticated_url_expiration - case @uploader.fog_credentials[:provider] - when 'AWS', 'Google' - local_file.url(expire_at, options) - when 'Rackspace' - connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options) - when 'OpenStack' - connection.get_object_https_url(@uploader.fog_directory, path, expire_at) - else - local_file.url(expire_at) - end - end - end - - # Fix for https://github.com/carrierwaveuploader/carrierwave/pull/2356 - def acl_header - if fog_provider == 'AWS' - { 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' } - else - {} - end - end - - def fog_provider - @uploader.fog_credentials[:provider].to_s - end - end - end - end -end diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index 5adb9f7a4b4..a1e0667bc6f 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -22,6 +22,3 @@ ActiveSupport.to_time_preserves_timezone = false # Require `belongs_to` associations by default. Previous versions had false. Rails.application.config.active_record.belongs_to_required_by_default = false - -# Do not halt callback chains when a callback returns false. Previous versions had true. -ActiveSupport.halt_callback_chains_on_return_false = true diff --git a/config/initializers/postgresql_opclasses_support.rb b/config/initializers/postgresql_opclasses_support.rb index 70b530415f5..b066f3788ec 100644 --- a/config/initializers/postgresql_opclasses_support.rb +++ b/config/initializers/postgresql_opclasses_support.rb @@ -130,9 +130,12 @@ module ActiveRecord where = inddef.scan(/WHERE (.+)$/).flatten[0] using = inddef.scan(/USING (.+?) /).flatten[0].to_sym opclasses = Hash[inddef.scan(/\((.+?)\)(?:$| WHERE )/).flatten[0].split(',').map do |column_and_opclass| - column, opclass = column_and_opclass.split(' ').map(&:strip) - [column, opclass] if opclass - end.compact] + column, opclass = column_and_opclass.split(' ').map(&:strip) + end.reject do |column, opclass| + ['desc', 'asc'].include?(opclass&.downcase) + end.map do |column, opclass| + [column, opclass] if opclass + end.compact] index_attrs = [table_name, index_name, unique, column_names, [], orders, where, nil, using, nil, opclasses] @@ -151,6 +154,9 @@ module ActiveRecord def quoted_columns_for_index(column_names, options = {}) column_opclasses = options[:opclasses] || {} column_names.map {|name| "#{quote_column_name(name)} #{column_opclasses[name]}"} + + quoted_columns = Hash[column_names.map { |name| [name.to_sym, "#{quote_column_name(name)} #{column_opclasses[name]}"] }] + add_options_for_index_columns(quoted_columns, options).values end end end |