Class: MigrateSafely::MigrationOutliner

Inherits:
Object
  • Object
show all
Defined in:
lib/migrate_safely/migration_outliner.rb

Defined Under Namespace

Classes: Action

Class Method Summary collapse

Class Method Details

.pending_actions(target_version = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/migrate_safely/migration_outliner.rb', line 5

def self.pending_actions(target_version = nil)
  current_version = ActiveRecord::Migrator.current_version
  return [] if current_version == 0 && target_version == 0

  direction = case
  when target_version.nil?
    :up
  when current_version > target_version
    :down
  else
    :up
  end

  migrations = ActiveRecord::Migrator.migrations(ActiveRecord::Migrator.migrations_paths)
  runnable_migrations = ActiveRecord::Migrator.new(direction, migrations, target_version).runnable
  action = direction == :up ? "apply" : "revert"

  runnable_migrations.map do |m|
    Action.new(m.version, action, m.name)
  end
end