class ActiveRecord::DataIntegrity::Accordance::PrimaryKey

Checks the primary key integer has 8 bytes length

Public Instance Methods

call() click to toggle source
# File lib/active_record/data_integrity/cop/accordance/primary_key.rb, line 10
def call
  log('has short integer primary key') unless valid?
  progress(valid?, 'P')
  valid?
end

Private Instance Methods

column_valid?(name) click to toggle source
# File lib/active_record/data_integrity/cop/accordance/primary_key.rb, line 26
def column_valid?(name)
  column = connection.columns(model.table_name).find { |c| c.name == name }
  column.type == :integer && column.limit.present? && column.limit >= 8
end
valid?() click to toggle source
# File lib/active_record/data_integrity/cop/accordance/primary_key.rb, line 18
def valid?
  return true unless connection.table_exists?(model.table_name)

  @valid ||= !connection.primary_keys(model.table_name).map! do |pk|
    column_valid?(pk)
  end.include?(false)
end