Class: OnlineMigrations::BackgroundMigrations::DeleteOrphanedRecords
- Inherits:
-
OnlineMigrations::BackgroundMigration
- Object
- OnlineMigrations::BackgroundMigration
- OnlineMigrations::BackgroundMigrations::DeleteOrphanedRecords
- Defined in:
- lib/online_migrations/background_migrations/delete_orphaned_records.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(model_name, associations, _options = {}) ⇒ DeleteOrphanedRecords
constructor
A new instance of DeleteOrphanedRecords.
- #process_batch(relation) ⇒ Object
- #relation ⇒ Object
Methods inherited from OnlineMigrations::BackgroundMigration
Constructor Details
#initialize(model_name, associations, _options = {}) ⇒ DeleteOrphanedRecords
Returns a new instance of DeleteOrphanedRecords.
9 10 11 12 |
# File 'lib/online_migrations/background_migrations/delete_orphaned_records.rb', line 9 def initialize(model_name, associations, = {}) @model = Object.const_get(model_name, false) @associations = associations.map(&:to_sym) end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
7 8 9 |
# File 'lib/online_migrations/background_migrations/delete_orphaned_records.rb', line 7 def associations @associations end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/online_migrations/background_migrations/delete_orphaned_records.rb', line 7 def model @model end |
Instance Method Details
#count ⇒ Object
22 23 24 |
# File 'lib/online_migrations/background_migrations/delete_orphaned_records.rb', line 22 def count Utils.estimated_count(model.connection, model.table_name) end |
#process_batch(relation) ⇒ Object
18 19 20 |
# File 'lib/online_migrations/background_migrations/delete_orphaned_records.rb', line 18 def process_batch(relation) relation.delete_all end |
#relation ⇒ Object
14 15 16 |
# File 'lib/online_migrations/background_migrations/delete_orphaned_records.rb', line 14 def relation model.unscoped.where.missing(*associations) end |