diff options
author | Jasper Maes <jaspermaes.jm@gmail.com> | 2018-12-15 12:06:56 +0300 |
---|---|---|
committer | Jasper Maes <jaspermaes.jm@gmail.com> | 2018-12-16 12:48:41 +0300 |
commit | 56296f1edadf2bc5f7741cbb3f97cb41f090aac6 (patch) | |
tree | 5a21667acd7d431f155d12227181dcfc6d21cba8 /lib/gitlab/database | |
parent | 8b4602041cf2c4a8738a4796d78720017249249f (diff) |
Remove rails4 specific code
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/arel_methods.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/database/median.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/database/sha_attribute.rb | 37 | ||||
-rw-r--r-- | lib/gitlab/database/subquery.rb | 14 |
6 files changed, 14 insertions, 82 deletions
diff --git a/lib/gitlab/database/arel_methods.rb b/lib/gitlab/database/arel_methods.rb deleted file mode 100644 index 991e4152dcb..00000000000 --- a/lib/gitlab/database/arel_methods.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Database - module ArelMethods - private - - # In Arel 7.0.0 (Arel 7.1.4 is used in Rails 5.0) the `engine` parameter of `Arel::UpdateManager#initializer` - # was removed. - # Remove this file and inline this method when removing rails5? code. - def arel_update_manager - if Gitlab.rails5? - Arel::UpdateManager.new - else - Arel::UpdateManager.new(ActiveRecord::Base) - end - end - end - end -end diff --git a/lib/gitlab/database/median.rb b/lib/gitlab/database/median.rb index 0da5119a3ed..1455e410d4b 100644 --- a/lib/gitlab/database/median.rb +++ b/lib/gitlab/database/median.rb @@ -35,13 +35,7 @@ module Gitlab end def mysql_median_datetime_sql(arel_table, query_so_far, column_sym) - arel_from = if Gitlab.rails5? - arel_table.from - else - arel_table - end - - query = arel_from + query = arel_table.from .from(arel_table.project(Arel.sql('*')).order(arel_table[column_sym]).as(arel_table.table_name)) .project(average([arel_table[column_sym]], 'median')) .where( @@ -151,13 +145,8 @@ module Gitlab .order(arel_table[column_sym]) ).as('row_id') - arel_from = if Gitlab.rails5? - arel_table.from.from(arel_table.alias) - else - arel_table.from(arel_table.alias) - end - - count = arel_from.project('COUNT(*)') + count = arel_table.from.from(arel_table.alias) + .project('COUNT(*)') .where(arel_table[partition_column].eq(arel_table.alias[partition_column])) .as('ct') diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index d9578852db6..3abd0600e9d 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -3,8 +3,6 @@ module Gitlab module Database module MigrationHelpers - include Gitlab::Database::ArelMethods - BACKGROUND_MIGRATION_BATCH_SIZE = 1000 # Number of rows to process per job BACKGROUND_MIGRATION_JOB_BUFFER_SIZE = 1000 # Number of jobs to bulk queue at a time @@ -361,7 +359,7 @@ module Gitlab stop_arel = yield table, stop_arel if block_given? stop_row = exec_query(stop_arel.to_sql).to_hash.first - update_arel = arel_update_manager + update_arel = Arel::UpdateManager.new .table(table) .set([[table[column], value]]) .where(table[:id].gteq(start_id)) diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb index a5b42bbfdd9..60afa4bcd52 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb @@ -5,8 +5,6 @@ module Gitlab module RenameReservedPathsMigration module V1 class RenameBase - include Gitlab::Database::ArelMethods - attr_reader :paths, :migration delegate :update_column_in_batches, @@ -66,7 +64,7 @@ module Gitlab old_full_path, new_full_path) - update = arel_update_manager + update = Arel::UpdateManager.new .table(routes) .set([[routes[:path], replace_statement]]) .where(Arel::Nodes::SqlLiteral.new(filter)) diff --git a/lib/gitlab/database/sha_attribute.rb b/lib/gitlab/database/sha_attribute.rb index 6516d6e648d..8d97adaff99 100644 --- a/lib/gitlab/database/sha_attribute.rb +++ b/lib/gitlab/database/sha_attribute.rb @@ -8,14 +8,7 @@ module Gitlab # behaviour from the default Binary type. ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bytea else - # In Rails 5.0 `Type` has been moved from `ActiveRecord` to `ActiveModel` - # https://github.com/rails/rails/commit/9cc8c6f3730df3d94c81a55be9ee1b7b4ffd29f6#diff-f8ba7983a51d687976e115adcd95822b - # Remove this method and leave just `ActiveModel::Type::Binary` when removing Gitlab.rails5? code. - if Gitlab.rails5? - ActiveModel::Type::Binary - else - ActiveRecord::Type::Binary - end + ActiveModel::Type::Binary end # Class for casting binary data to hexadecimal SHA1 hashes (and vice-versa). @@ -26,31 +19,9 @@ module Gitlab class ShaAttribute < BINARY_TYPE PACK_FORMAT = 'H*'.freeze - # It is called from activerecord-4.2.10/lib/active_record internal methods. - # Remove this method when removing Gitlab.rails5? code. - def type_cast_from_database(value) - unpack_sha(super) - end - - # It is called from activerecord-4.2.10/lib/active_record internal methods. - # Remove this method when removing Gitlab.rails5? code. - def type_cast_for_database(value) - serialize(value) - end - - # It is called from activerecord-5.0.6/lib/active_record/attribute.rb - # Remove this method when removing Gitlab.rails5? code.. - def deserialize(value) - value = Gitlab.rails5? ? super : method(:type_cast_from_database).super_method.call(value) - - unpack_sha(value) - end - - # Rename this method to `deserialize(value)` removing Gitlab.rails5? code. # Casts binary data to a SHA1 in hexadecimal. - def unpack_sha(value) - # Uncomment this line when removing Gitlab.rails5? code. - # value = super + def deserialize(value) + value = super(value) value ? value.unpack(PACK_FORMAT)[0] : nil end @@ -58,7 +29,7 @@ module Gitlab def serialize(value) arg = value ? [value].pack(PACK_FORMAT) : nil - Gitlab.rails5? ? super(arg) : method(:type_cast_for_database).super_method.call(arg) + super(arg) end end end diff --git a/lib/gitlab/database/subquery.rb b/lib/gitlab/database/subquery.rb index 36e4559b554..10971d2b274 100644 --- a/lib/gitlab/database/subquery.rb +++ b/lib/gitlab/database/subquery.rb @@ -6,15 +6,11 @@ module Gitlab class << self def self_join(relation) t = relation.arel_table - t2 = if !Gitlab.rails5? - relation.arel.as('t2') - else - # Work around a bug in Rails 5, where LIMIT causes trouble - # See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729 - r = relation.limit(nil).arel - r.take(relation.limit_value) if relation.limit_value - r.as('t2') - end + # Work around a bug in Rails 5, where LIMIT causes trouble + # See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729 + r = relation.limit(nil).arel + r.take(relation.limit_value) if relation.limit_value + t2 = r.as('t2') relation.unscoped.joins(t.join(t2).on(t[:id].eq(t2[:id])).join_sources.first) end |