class OnlineMigrations::BackgroundMigration

Base class that is inherited by the host application’s background migration classes.

Public Class Methods

named(name) click to toggle source

Finds a Background Migration with the given name.

@param name [String] the name of the Background Migration to be found.

@return [BackgroundMigration] the Background Migration with the given name.

@raise [NotFoundError] if a Background Migration with the given name does not exist.

# File lib/online_migrations/background_migration.rb, line 17
def named(name)
  namespace = OnlineMigrations.config.background_migrations.migrations_module.constantize
  internal_namespace = ::OnlineMigrations::BackgroundMigrations

  migration = "#{namespace}::#{name}".safe_constantize ||
              "#{internal_namespace}::#{name}".safe_constantize

  raise NotFoundError.new("Background Migration #{name} not found", name) unless migration
  unless migration.is_a?(Class) && migration < self
    raise NotFoundError.new("#{name} is not a Background Migration", name)
  end

  migration
end

Public Instance Methods

count() click to toggle source

Returns the count of rows that will be iterated over (optional, to be able to show progress).

@return [Integer, nil, :no_count]

# File lib/online_migrations/background_migration.rb, line 60
def count
  :no_count
end
process_batch(_relation) click to toggle source

Processes one batch.

@param _relation [ActiveRecord::Relation] the current batch from the enumerator being iterated @return [void]

@raise [NotImplementedError] with a message advising subclasses to

implement an override for this method.
# File lib/online_migrations/background_migration.rb, line 52
def process_batch(_relation)
  raise NotImplementedError, "#{self.class.name} must implement a 'process_batch' method"
end
relation() click to toggle source

The relation to be iterated over.

@return [ActiveRecord::Relation]

@raise [NotImplementedError] with a message advising subclasses to

implement an override for this method.
# File lib/online_migrations/background_migration.rb, line 40
def relation
  raise NotImplementedError, "#{self.class.name} must implement a 'relation' method"
end