Merge branch 'sh-disable-internal-ids-available-check' into 'master'

Always use internal ID tables in development and production

Closes #60718

See merge request gitlab-org/gitlab-ce!27544
This commit is contained in:
Sean McGivern 2019-04-24 14:08:20 +00:00
commit 5150802d0a
3 changed files with 21 additions and 3 deletions

View file

@ -87,12 +87,16 @@ class InternalId < ApplicationRecord
end
def available?
@available_flag ||= ActiveRecord::Migrator.current_version >= REQUIRED_SCHEMA_VERSION # rubocop:disable Gitlab/PredicateMemoization
return true unless Rails.env.test?
Gitlab::SafeRequestStore.fetch(:internal_ids_available_flag) do
ActiveRecord::Migrator.current_version >= REQUIRED_SCHEMA_VERSION
end
end
# Flushes cached information about schema
def reset_column_information
@available_flag = nil
Gitlab::SafeRequestStore[:internal_ids_available_flag] = nil
super
end
end

View file

@ -0,0 +1,5 @@
---
title: Always use internal ID tables in development and production
merge_request: 27544
author:
type: fixed

View file

@ -93,7 +93,7 @@ describe InternalId do
before do
described_class.reset_column_information
# Project factory will also call the current_version
expect(ActiveRecord::Migrator).to receive(:current_version).twice.and_return(InternalId::REQUIRED_SCHEMA_VERSION - 1)
expect(ActiveRecord::Migrator).to receive(:current_version).at_least(:once).and_return(InternalId::REQUIRED_SCHEMA_VERSION - 1)
end
let(:init) { double('block') }
@ -104,6 +104,15 @@ describe InternalId do
expect(init).to receive(:call).with(issue).and_return(val)
expect(subject).to eq(val + 1)
end
it 'always attempts to generate internal IDs in production mode' do
allow(Rails.env).to receive(:test?).and_return(false)
val = rand(1..100)
generator = double(generate: val)
expect(InternalId::InternalIdGenerator).to receive(:new).and_return(generator)
expect(subject).to eq(val)
end
end
end