Commit 9b752791 authored by Stan Hu's avatar Stan Hu

Always use internal ID tables in development and production

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
parent 84a1e37f
...@@ -87,12 +87,16 @@ class InternalId < ApplicationRecord ...@@ -87,12 +87,16 @@ class InternalId < ApplicationRecord
end end
def available? 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 end
# Flushes cached information about schema # Flushes cached information about schema
def reset_column_information def reset_column_information
@available_flag = nil Gitlab::SafeRequestStore[:internal_ids_available_flag] = nil
super super
end end
end end
......
---
title: Always use internal ID tables in development and production
merge_request: 27544
author:
type: fixed
...@@ -93,7 +93,7 @@ describe InternalId do ...@@ -93,7 +93,7 @@ describe InternalId do
before do before do
described_class.reset_column_information described_class.reset_column_information
# Project factory will also call the current_version # 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 end
let(:init) { double('block') } let(:init) { double('block') }
...@@ -104,6 +104,15 @@ describe InternalId do ...@@ -104,6 +104,15 @@ describe InternalId do
expect(init).to receive(:call).with(issue).and_return(val) expect(init).to receive(:call).with(issue).and_return(val)
expect(subject).to eq(val + 1) expect(subject).to eq(val + 1)
end 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
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