summaryrefslogtreecommitdiff
path: root/app/models/concerns/sha_attribute.rb
blob: 703a72c355cfd4efa0e4471e1b1088d1ba0888ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module ShaAttribute
  extend ActiveSupport::Concern

  module ClassMethods
    def sha_attribute(name)
      return if ENV['STATIC_VERIFICATION']
      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