Commit 23800552 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'ag-fix-geo-warning' into 'master'

Validate binary column exists, in dev when geo is enabled

See merge request gitlab-org/gitlab!38276
parents 59cd61bd a84476b5
......@@ -7,7 +7,7 @@ module ShaAttribute
def sha_attribute(name)
return if ENV['STATIC_VERIFICATION']
validate_binary_column_exists!(name) unless Rails.env.production?
validate_binary_column_exists!(name) if Rails.env.development?
attribute(name, Gitlab::Database::ShaAttribute.new)
end
......@@ -17,18 +17,11 @@ module ShaAttribute
# See https://gitlab.com/gitlab-org/gitlab/merge_requests/5502 for more discussion
def validate_binary_column_exists!(name)
return unless database_exists?
unless table_exists?
warn "WARNING: sha_attribute #{name.inspect} is invalid since the table doesn't exist - you may need to run database migrations"
return
end
return unless table_exists?
column = columns.find { |c| c.name == name.to_s }
unless column
warn "WARNING: sha_attribute #{name.inspect} is invalid since the column doesn't exist - you may need to run database migrations"
return
end
return unless column
unless column.type == :binary
raise ArgumentError.new("sha_attribute #{name.inspect} is invalid since the column type is not :binary")
......
......@@ -15,7 +15,7 @@ RSpec.describe ShaAttribute do
end
describe '#sha_attribute' do
context 'when in non-production' do
context 'when in development' do
before do
stub_rails_env('development')
end
......@@ -38,24 +38,22 @@ RSpec.describe ShaAttribute do
end
context 'when the table does not exist' do
it 'allows the attribute to be added and issues a warning' do
it 'allows the attribute to be added' do
allow(model).to receive(:table_exists?).and_return(false)
expect(model).not_to receive(:columns)
expect(model).to receive(:attribute)
expect(model).to receive(:warn)
model.sha_attribute(:name)
end
end
context 'when the column does not exist' do
it 'allows the attribute to be added and issues a warning' do
it 'allows the attribute to be added' do
allow(model).to receive(:table_exists?).and_return(true)
expect(model).to receive(:columns)
expect(model).to receive(:attribute)
expect(model).to receive(:warn)
model.sha_attribute(:no_name)
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