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
37 38 39 |
# File 'lib/online_migrations/data_migration.rb', line 37 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.
44 45 46 |
# File 'lib/online_migrations/data_migration.rb', line 44 def collection_batch_size(size) self.active_record_enumerator_batch_size = size end |
.named(name) ⇒ DataMigration
Finds a Data Migration with the given name.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/online_migrations/data_migration.rb', line 21 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 ArgumentError, "#{name} is not a Data Migration" end migration end |
Instance Method Details
#after_cancel ⇒ Object
A hook to override that will be called when the migration is cancelled.
86 87 |
# File 'lib/online_migrations/data_migration.rb', line 86 def after_cancel end |
#after_complete ⇒ Object
A hook to override that will be called when the migration finished its work.
76 77 |
# File 'lib/online_migrations/data_migration.rb', line 76 def after_complete end |
#after_pause ⇒ Object
A hook to override that will be called when the migration is paused.
81 82 |
# File 'lib/online_migrations/data_migration.rb', line 81 def after_pause end |
#after_resume ⇒ Object
A hook to override that will be called when the migration resumes its work.
64 65 |
# File 'lib/online_migrations/data_migration.rb', line 64 def after_resume end |
#after_start ⇒ Object
A hook to override that will be called when the migration starts running.
51 52 |
# File 'lib/online_migrations/data_migration.rb', line 51 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.
71 72 |
# File 'lib/online_migrations/data_migration.rb', line 71 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.
58 59 60 |
# File 'lib/online_migrations/data_migration.rb', line 58 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.
125 126 |
# File 'lib/online_migrations/data_migration.rb', line 125 def build_enumerator(cursor:) end |
#collection ⇒ ActiveRecord::Relation, ...
The collection to be processed.
95 96 97 |
# File 'lib/online_migrations/data_migration.rb', line 95 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).
112 113 |
# File 'lib/online_migrations/data_migration.rb', line 112 def count end |
#process(_item) ⇒ Object
The action to be performed on each item from the collection.
104 105 106 |
# File 'lib/online_migrations/data_migration.rb', line 104 def process(_item) raise NotImplementedError, "#{self.class.name} must implement a 'process' method" end |