Class: YeetDba::VerifyData
- Inherits:
-
Object
- Object
- YeetDba::VerifyData
- Defined in:
- lib/yeet_dba/verify_data.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
Instance Method Summary collapse
-
#initialize(column:) ⇒ VerifyData
constructor
A new instance of VerifyData.
- #orphaned_rows ⇒ Object
- #orphaned_rows? ⇒ Boolean
- #orphaned_rows_count ⇒ Object
- #query ⇒ Object
Constructor Details
#initialize(column:) ⇒ VerifyData
Returns a new instance of VerifyData.
5 6 7 |
# File 'lib/yeet_dba/verify_data.rb', line 5 def initialize(column:) @column = column end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
3 4 5 |
# File 'lib/yeet_dba/verify_data.rb', line 3 def column @column end |
Instance Method Details
#orphaned_rows ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 if model 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') else [] end end |
#orphaned_rows? ⇒ Boolean
9 10 11 |
# File 'lib/yeet_dba/verify_data.rb', line 9 def orphaned_rows? orphaned_rows.first end |
#orphaned_rows_count ⇒ Object
13 14 15 |
# File 'lib/yeet_dba/verify_data.rb', line 13 def orphaned_rows_count orphaned_rows.count end |
#query ⇒ Object
17 18 19 |
# File 'lib/yeet_dba/verify_data.rb', line 17 def query orphaned_rows.to_sql end |