Module: Apartment::Migrator

Extended by:
Migrator
Included in:
Migrator
Defined in:
lib/apartment/migrator.rb

Instance Method Summary collapse

Instance Method Details

#migrate(database) ⇒ Object

Migrate to latest



9
10
11
12
13
14
15
16
17
# File 'lib/apartment/migrator.rb', line 9

def migrate(database)
  Tenant.switch(database) do
    version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil

    ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, version) do |migration|
      ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
    end
  end
end

#rollback(database, step = 1) ⇒ Object

rollback latest migration ‘step` number of times



27
28
29
30
31
# File 'lib/apartment/migrator.rb', line 27

def rollback(database, step = 1)
  Tenant.switch(database) do
    ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
  end
end

#run(direction, database, version) ⇒ Object

Migrate up/down to a specific version



20
21
22
23
24
# File 'lib/apartment/migrator.rb', line 20

def run(direction, database, version)
  Tenant.switch(database) do
    ActiveRecord::Migrator.run(direction, ActiveRecord::Migrator.migrations_paths, version)
  end
end