diff options
author | Stan Hu <stanhu@gmail.com> | 2019-04-22 00:24:57 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-04-22 10:48:16 -0700 |
commit | 9b752791624ce618810b9d65251582e56c37dee7 (patch) | |
tree | d495612c25e2c7b4a9a8db4ea3cb00ee5e5be1aa | |
parent | 84a1e37f4a889c6b7558f101dc0ecf2932d0a0c6 (diff) | |
download | gitlab-ce-sh-disable-internal-ids-available-check.tar.gz |
Always use internal ID tables in development and productionsh-disable-internal-ids-available-check
To avoid quiet failures that cause consistency errors in the database,
we should now assume that the internal_ids table is available since
we've had this table for close to a year.
For tests that have migrations, we make this check thread-safe via
SafeRequestStore.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/60718
-rw-r--r-- | app/models/internal_id.rb | 8 | ||||
-rw-r--r-- | changelogs/unreleased/sh-disable-internal-ids-available-check.yml | 5 | ||||
-rw-r--r-- | spec/models/internal_id_spec.rb | 11 |
3 files changed, 21 insertions, 3 deletions
diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb index 401b94d36e5..237401899db 100644 --- a/app/models/internal_id.rb +++ b/app/models/internal_id.rb @@ -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 diff --git a/changelogs/unreleased/sh-disable-internal-ids-available-check.yml b/changelogs/unreleased/sh-disable-internal-ids-available-check.yml new file mode 100644 index 00000000000..069a9ba7d69 --- /dev/null +++ b/changelogs/unreleased/sh-disable-internal-ids-available-check.yml @@ -0,0 +1,5 @@ +--- +title: Always use internal ID tables in development and production +merge_request: 27544 +author: +type: fixed diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb index 0ed4e146caa..806b4f61bd8 100644 --- a/spec/models/internal_id_spec.rb +++ b/spec/models/internal_id_spec.rb @@ -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 |