Commit 6a605c08 authored by Andreas Brandl's avatar Andreas Brandl Committed by Adam Hegyi

Remove check for availability of PG upsert

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