Commit 816c4535 authored by Yorick Peterse's avatar Yorick Peterse

Don't update columns in batches in a transaction

This ensures that whatever locks are acquired aren't held onto until the
end of the transaction (= after _all_ rows have been updated). Timing
wise there's also no difference between using a transaction and not
using one.
parent 8966263e
...@@ -138,11 +138,9 @@ module Gitlab ...@@ -138,11 +138,9 @@ module Gitlab
end end
begin begin
transaction do
update_column_in_batches(table, column, default, &block) update_column_in_batches(table, column, default, &block)
change_column_null(table, column, false) unless allow_null change_column_null(table, column, false) unless allow_null
end
# We want to rescue _all_ exceptions here, even those that don't inherit # We want to rescue _all_ exceptions here, even those that don't inherit
# from StandardError. # from StandardError.
rescue Exception => error # rubocop: disable all rescue Exception => error # rubocop: disable all
......
...@@ -90,7 +90,7 @@ describe Gitlab::Database::MigrationHelpers, lib: true do ...@@ -90,7 +90,7 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
before do before do
expect(model).to receive(:transaction_open?).and_return(false) expect(model).to receive(:transaction_open?).and_return(false)
expect(model).to receive(:transaction).twice.and_yield expect(model).to receive(:transaction).and_yield
expect(model).to receive(:add_column). expect(model).to receive(:add_column).
with(:projects, :foo, :integer, default: nil) with(:projects, :foo, :integer, default: nil)
......
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