Module: Apartment::Migrator
Instance Method Summary collapse
-
#migrate(database) ⇒ Object
Migrate to latest.
-
#rollback(database, step = 1) ⇒ Object
rollback latest migration ‘step` number of times.
-
#run(direction, database, version) ⇒ Object
Migrate up/down to a specific version.
Instance Method Details
#migrate(database) ⇒ Object
Migrate to latest
10 11 12 13 14 15 16 17 18 |
# File 'lib/apartment/migrator.rb', line 10 def migrate(database) Tenant.switch(database) do version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil migration_scope_block = ->(migration) { ENV['SCOPE'].blank? || (ENV['SCOPE'] == migration.scope) } ActiveRecord::Base.connection.migration_context.migrate(version, &migration_scope_block) end end |
#rollback(database, step = 1) ⇒ Object
rollback latest migration ‘step` number of times
28 29 30 31 32 |
# File 'lib/apartment/migrator.rb', line 28 def rollback(database, step = 1) Tenant.switch(database) do ActiveRecord::Base.connection.migration_context.rollback(step) end end |
#run(direction, database, version) ⇒ Object
Migrate up/down to a specific version
21 22 23 24 25 |
# File 'lib/apartment/migrator.rb', line 21 def run(direction, database, version) Tenant.switch(database) do ActiveRecord::Base.connection.migration_context.run(direction, version) end end |