Class: Sequent::Migrations::MigrateEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/migrations/migrate_events.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ MigrateEvents

Returns a new instance of MigrateEvents.

Parameters:

  • env

    The string representing the current environment. E.g. “development”, “production”



26
27
28
# File 'lib/sequent/migrations/migrate_events.rb', line 26

def initialize(env)
  @env = env
end

Instance Method Details

#execute_migrations(current_version, new_version, &after_migration_block) ⇒ Object

Parameters:

  • current_version

    The current version of the application. E.g. 10

  • new_version

    The version to migrate to. E.g. 11

  • &after_migration_block

    an optional block to run after the migrations run. E.g. close resources



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sequent/migrations/migrate_events.rb', line 36

def execute_migrations(current_version, new_version, &after_migration_block)
  if current_version != new_version and current_version > 0
    ((current_version + 1)..new_version).each do |upgrade_to_version|
      migration_class = "MigrateToVersion#{upgrade_to_version}".to_sym
      if Kernel.const_defined?(migration_class)
        begin
          Kernel.const_get(migration_class).new(@env).migrate
        ensure
          after_migration_block.call if after_migration_block
        end
      end
    end
  end
end