From b3095251c4bd620e85cb22f9fc8b8c75bcbed4d4 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 23 May 2017 00:25:26 +0800 Subject: Make sure that Arel.sql would work for update_column_in_batches --- spec/lib/gitlab/database/migration_helpers_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'spec/lib/gitlab/database/migration_helpers_spec.rb') diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index dfa3ae9142e..bd5ac6142be 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -247,6 +247,14 @@ describe Gitlab::Database::MigrationHelpers, lib: true do expect(Project.where(archived: true).count).to eq(1) end end + + context 'when the value is Arel.sql (Arel::Nodes::SqlLiteral)' do + it 'updates the value as a SQL expression' do + model.update_column_in_batches(:projects, :star_count, Arel.sql('1+1')) + + expect(Project.sum(:star_count)).to eq(2 * Project.count) + end + end end describe '#add_column_with_default' do -- cgit v1.2.1 From eb21f93267f3d911b40cace81a4f63f857a1243a Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 25 May 2017 12:10:34 +0100 Subject: Only use DROP INDEX CONCURRENTLY on postgreql 9.2+ --- spec/lib/gitlab/database/migration_helpers_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'spec/lib/gitlab/database/migration_helpers_spec.rb') diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index bd5ac6142be..3fdafd867da 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -66,16 +66,23 @@ describe Gitlab::Database::MigrationHelpers, lib: true do context 'using PostgreSQL' do before do - allow(Gitlab::Database).to receive(:postgresql?).and_return(true) + allow(model).to receive(:supports_drop_index_concurrently?).and_return(true) allow(model).to receive(:disable_statement_timeout) end - it 'removes the index concurrently' do + it 'removes the index concurrently by column name' do expect(model).to receive(:remove_index). with(:users, { algorithm: :concurrently, column: :foo }) model.remove_concurrent_index(:users, :foo) end + + it 'removes the index concurrently by index name' do + expect(model).to receive(:remove_index). + with(:users, { algorithm: :concurrently, name: "index_x_by_y" }) + + model.remove_concurrent_index_by_name(:users, "index_x_by_y") + end end context 'using MySQL' do -- cgit v1.2.1