gitlab-org--gitlab-foss/app/models/concerns/sha_attribute.rb
Sean McGivern 38fd773bd3 Fix ShaAttribute concern when there is no table
When this is added to a new model, it would fail before the migrations were run
- including when trying to run migrations in production mode!
2017-07-07 12:42:38 +01:00

20 lines
587 B
Ruby

module ShaAttribute
extend ActiveSupport::Concern
module ClassMethods
def sha_attribute(name)
return unless table_exists?
column = columns.find { |c| c.name == name.to_s }
# In case the table doesn't exist we won't be able to find the column,
# thus we will only check the type if the column is present.
if column && column.type != :binary
raise ArgumentError,
"sha_attribute #{name.inspect} is invalid since the column type is not :binary"
end
attribute(name, Gitlab::Database::ShaAttribute.new)
end
end
end