Class: OnlineMigrations::DataMigration
- Inherits:
-
Object
- Object
- OnlineMigrations::DataMigration
- Defined in:
- lib/online_migrations/data_migration.rb
Overview
Base class that is inherited by the host application’s data migration classes.
Direct Known Subclasses
BackgroundDataMigrations::BackfillColumn, BackgroundDataMigrations::CopyColumn, BackgroundDataMigrations::DeleteAssociatedRecords, BackgroundDataMigrations::DeleteOrphanedRecords, BackgroundDataMigrations::PerformActionOnRelation, BackgroundDataMigrations::ResetCounters
Defined Under Namespace
Classes: NotFoundError
Class Attribute Summary collapse
Class Method Summary collapse
-
.collection_batch_size(size) ⇒ Object
Limit the number of records that will be fetched in a single query when iterating over an Active Record collection migration.
-
.named(name) ⇒ DataMigration
Finds a Data Migration with the given name.
Instance Method Summary collapse
-
#after_cancel ⇒ Object
A hook to override that will be called when the migration is cancelled.
-
#after_complete ⇒ Object
A hook to override that will be called when the migration finished its work.
-
#after_pause ⇒ Object
A hook to override that will be called when the migration is paused.
-
#after_resume ⇒ Object
A hook to override that will be called when the migration resumes its work.
-
#after_start ⇒ Object
A hook to override that will be called when the migration starts running.
-
#after_stop ⇒ Object
A hook to override that will be called each time the migration is interrupted.
-
#around_process ⇒ Object
A hook to override that will be called around ‘process’ each time.
-
#build_enumerator(cursor:) ⇒ Enumerator
Enumerator builder.
-
#collection ⇒ ActiveRecord::Relation, ...
The collection to be processed.
-
#count ⇒ Integer?
Total count of iterations to be performed (optional, to be able to show progress).
-
#process(_item) ⇒ Object
The action to be performed on each item from the collection.
Class Attribute Details
.active_record_enumerator_batch_size ⇒ Object
36 37 38 |
# File 'lib/online_migrations/data_migration.rb', line 36 def active_record_enumerator_batch_size @active_record_enumerator_batch_size end |
Class Method Details
.collection_batch_size(size) ⇒ Object
Limit the number of records that will be fetched in a single query when iterating over an Active Record collection migration.
43 44 45 |
# File 'lib/online_migrations/data_migration.rb', line 43 def collection_batch_size(size) self.active_record_enumerator_batch_size = size end |
.named(name) ⇒ DataMigration
Finds a Data Migration with the given name.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/online_migrations/data_migration.rb', line 20 def named(name) namespace = OnlineMigrations.config.background_data_migrations.migrations_module.constantize internal_namespace = ::OnlineMigrations::BackgroundDataMigrations migration = "#{namespace}::#{name}".safe_constantize || "#{internal_namespace}::#{name}".safe_constantize raise NotFoundError.new("Data Migration #{name} not found", name) if migration.nil? if !(migration.is_a?(Class) && migration < self) raise NotFoundError.new("#{name} is not a Data Migration", name) end migration end |
Instance Method Details
#after_cancel ⇒ Object
A hook to override that will be called when the migration is cancelled.
85 86 |
# File 'lib/online_migrations/data_migration.rb', line 85 def after_cancel end |
#after_complete ⇒ Object
A hook to override that will be called when the migration finished its work.
75 76 |
# File 'lib/online_migrations/data_migration.rb', line 75 def after_complete end |
#after_pause ⇒ Object
A hook to override that will be called when the migration is paused.
80 81 |
# File 'lib/online_migrations/data_migration.rb', line 80 def after_pause end |
#after_resume ⇒ Object
A hook to override that will be called when the migration resumes its work.
63 64 |
# File 'lib/online_migrations/data_migration.rb', line 63 def after_resume end |
#after_start ⇒ Object
A hook to override that will be called when the migration starts running.
50 51 |
# File 'lib/online_migrations/data_migration.rb', line 50 def after_start end |
#after_stop ⇒ Object
A hook to override that will be called each time the migration is interrupted.
This can be due to interruption or sidekiq stopping.
70 71 |
# File 'lib/online_migrations/data_migration.rb', line 70 def after_stop end |
#around_process ⇒ Object
A hook to override that will be called around ‘process’ each time.
Can be useful for some metrics collection, performance tracking etc.
57 58 59 |
# File 'lib/online_migrations/data_migration.rb', line 57 def around_process yield end |
#build_enumerator(cursor:) ⇒ Enumerator
Enumerator builder. You may override this method to return any Enumerator yielding pairs of ‘[item, item_cursor]`, instead of using `collection`.
It is useful when it is not practical or impossible to define an explicit collection in the ‘collection` method.
124 125 |
# File 'lib/online_migrations/data_migration.rb', line 124 def build_enumerator(cursor:) end |
#collection ⇒ ActiveRecord::Relation, ...
The collection to be processed.
94 95 96 |
# File 'lib/online_migrations/data_migration.rb', line 94 def collection raise NotImplementedError, "#{self.class.name} must implement a 'collection' method" end |
#count ⇒ Integer?
Total count of iterations to be performed (optional, to be able to show progress).
111 112 |
# File 'lib/online_migrations/data_migration.rb', line 111 def count end |
#process(_item) ⇒ Object
The action to be performed on each item from the collection.
103 104 105 |
# File 'lib/online_migrations/data_migration.rb', line 103 def process(_item) raise NotImplementedError, "#{self.class.name} must implement a 'process' method" end |