Commit 66350720 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'ab/remove-upsert-check' into 'master'

Remove check for availability of PG upsert

See merge request gitlab-org/gitlab!36055
parents c0a40555 6a605c08
...@@ -107,10 +107,6 @@ module Gitlab ...@@ -107,10 +107,6 @@ module Gitlab
version.to_f >= MINIMUM_POSTGRES_VERSION version.to_f >= MINIMUM_POSTGRES_VERSION
end end
def self.upsert_supported?
version.to_f >= 9.5
end
def self.check_postgres_version_and_print_warning def self.check_postgres_version_and_print_warning
return if Gitlab::Database.postgresql_minimum_supported_version? return if Gitlab::Database.postgresql_minimum_supported_version?
return if Gitlab::Runtime.rails_runner? return if Gitlab::Runtime.rails_runner?
...@@ -221,9 +217,7 @@ module Gitlab ...@@ -221,9 +217,7 @@ module Gitlab
VALUES #{tuples.map { |tuple| "(#{tuple.join(', ')})" }.join(', ')} VALUES #{tuples.map { |tuple| "(#{tuple.join(', ')})" }.join(', ')}
EOF EOF
if upsert_supported? && on_conflict == :do_nothing sql = "#{sql} ON CONFLICT DO NOTHING" if on_conflict == :do_nothing
sql = "#{sql} ON CONFLICT DO NOTHING"
end
sql = "#{sql} RETURNING id" if return_ids sql = "#{sql} RETURNING id" if return_ids
......
...@@ -283,7 +283,6 @@ RSpec.describe Gitlab::Database do ...@@ -283,7 +283,6 @@ RSpec.describe Gitlab::Database do
describe '.bulk_insert' do describe '.bulk_insert' do
before do before do
allow(described_class).to receive(:connection).and_return(connection) allow(described_class).to receive(:connection).and_return(connection)
allow(described_class).to receive(:version).and_return(version)
allow(connection).to receive(:quote_column_name, &:itself) allow(connection).to receive(:quote_column_name, &:itself)
allow(connection).to receive(:quote, &:itself) allow(connection).to receive(:quote, &:itself)
allow(connection).to receive(:execute) allow(connection).to receive(:execute)
...@@ -298,8 +297,6 @@ RSpec.describe Gitlab::Database do ...@@ -298,8 +297,6 @@ RSpec.describe Gitlab::Database do
] ]
end end
let_it_be(:version) { 9.6 }
it 'does nothing with empty rows' do it 'does nothing with empty rows' do
expect(connection).not_to receive(:execute) expect(connection).not_to receive(:execute)
...@@ -366,28 +363,13 @@ RSpec.describe Gitlab::Database do ...@@ -366,28 +363,13 @@ RSpec.describe Gitlab::Database do
expect(ids).to eq([10]) expect(ids).to eq([10])
end end
context 'with version >= 9.5' do it 'allows setting the upsert to do nothing' do
it 'allows setting the upsert to do nothing' do expect(connection)
expect(connection) .to receive(:execute)
.to receive(:execute) .with(/ON CONFLICT DO NOTHING/)
.with(/ON CONFLICT DO NOTHING/)
described_class
.bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing)
end
end
context 'with version < 9.5' do
let(:version) { 9.4 }
it 'refuses setting the upsert' do
expect(connection)
.not_to receive(:execute)
.with(/ON CONFLICT/)
described_class described_class
.bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing) .bulk_insert('test', [{ number: 10 }], on_conflict: :do_nothing)
end
end end
end end
end end
......
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