Commit 415bf587 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'blackst0ne-rails5-fix-arel-update-manager' into 'master'

[Rails5] Fix Arel::UpdateManager

See merge request gitlab-org/gitlab-ce!18641
parents 3f9bfb0c 54124fc6
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
module Gitlab module Gitlab
module Database module Database
module MigrationHelpers module MigrationHelpers
include Gitlab::Database::ArelMethods
BACKGROUND_MIGRATION_BATCH_SIZE = 1000 # Number of rows to process per job 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 BACKGROUND_MIGRATION_JOB_BUFFER_SIZE = 1000 # Number of jobs to bulk queue at a time
...@@ -314,7 +316,7 @@ module Gitlab ...@@ -314,7 +316,7 @@ module Gitlab
stop_arel = yield table, stop_arel if block_given? stop_arel = yield table, stop_arel if block_given?
stop_row = exec_query(stop_arel.to_sql).to_hash.first stop_row = exec_query(stop_arel.to_sql).to_hash.first
update_arel = Arel::UpdateManager.new(ActiveRecord::Base) update_arel = arel_update_manager
.table(table) .table(table)
.set([[table[column], value]]) .set([[table[column], value]])
.where(table[:id].gteq(start_id)) .where(table[:id].gteq(start_id))
......
...@@ -3,6 +3,8 @@ module Gitlab ...@@ -3,6 +3,8 @@ module Gitlab
module RenameReservedPathsMigration module RenameReservedPathsMigration
module V1 module V1
class RenameBase class RenameBase
include Gitlab::Database::ArelMethods
attr_reader :paths, :migration attr_reader :paths, :migration
delegate :update_column_in_batches, delegate :update_column_in_batches,
...@@ -62,7 +64,7 @@ module Gitlab ...@@ -62,7 +64,7 @@ module Gitlab
old_full_path, old_full_path,
new_full_path) new_full_path)
update = Arel::UpdateManager.new(ActiveRecord::Base) update = arel_update_manager
.table(routes) .table(routes)
.set([[routes[:path], replace_statement]]) .set([[routes[:path], replace_statement]])
.where(Arel::Nodes::SqlLiteral.new(filter)) .where(Arel::Nodes::SqlLiteral.new(filter))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment