Class: OnlineMigrations::BackgroundMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/online_migrations/background_migration.rb

Overview

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

Defined Under Namespace

Classes: NotFoundError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.named(name) ⇒ BackgroundMigration

Finds a Background Migration with the given name.

Parameters:

  • name (String)

    the name of the Background Migration to be found.

Returns:

Raises:

  • (NotFoundError)

    if a Background Migration with the given name does not exist.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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) if migration.nil?
  if !(migration.is_a?(Class) && migration < self)
    raise NotFoundError.new("#{name} is not a Background Migration", name)
  end

  migration
end

Instance Method Details

#countInteger, ...

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

Returns:

  • (Integer, nil, :no_count)


60
61
62
# File 'lib/online_migrations/background_migration.rb', line 60

def count
  :no_count
end

#process_batch(_relation) ⇒ void

This method returns an undefined value.

Processes one batch.

Parameters:

  • _relation (ActiveRecord::Relation)

    the current batch from the enumerator being iterated

Raises:

  • (NotImplementedError)

    with a message advising subclasses to implement an override for this method.



52
53
54
# 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

#relationActiveRecord::Relation

The relation to be iterated over.

Returns:

  • (ActiveRecord::Relation)

Raises:

  • (NotImplementedError)

    with a message advising subclasses to implement an override for this method.



40
41
42
# File 'lib/online_migrations/background_migration.rb', line 40

def relation
  raise NotImplementedError, "#{self.class.name} must implement a 'relation' method"
end