class YeetDba::VerifyData

Attributes

column[RW]

Public Class Methods

new(column:) click to toggle source
# File lib/yeet_dba/verify_data.rb, line 5
def initialize(column:)
  @column = column
end

Public Instance Methods

orphaned_rows() click to toggle source
# File lib/yeet_dba/verify_data.rb, line 21
def orphaned_rows
  association = column.association

  column_name = column.db_column.name
  table_name = column.table_name
  association_table = column.association_table_name
  model = column.model

  # Check to see there could be rows with bad data
  model.joins("left join #{association_table} as association_table on association_table.id = #{table_name}.#{column_name}")
       .where.not(column_name => nil)
       .where('association_table.id is null')
end
orphaned_rows?() click to toggle source
# File lib/yeet_dba/verify_data.rb, line 9
def orphaned_rows?
  orphaned_rows.first
end
orphaned_rows_count() click to toggle source
# File lib/yeet_dba/verify_data.rb, line 13
def orphaned_rows_count
  orphaned_rows.count
end
query() click to toggle source
# File lib/yeet_dba/verify_data.rb, line 17
def query
  orphaned_rows.to_sql
end