Sha256: 6a64e78c6b2e47377b0879428425cf8604f6d27261d03830a4febeb40a642983

Contents?: true

Size: 902 Bytes

Versions: 7

Compression:

Stored size: 902 Bytes

Contents

require 'apartment/tenant'

module Apartment
  module Migrator

    extend self

    # Migrate to latest
    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

    # Migrate up/down to a specific version
    def run(direction, database, version)
      Tenant.switch(database) do
        ActiveRecord::Migrator.run(direction, ActiveRecord::Migrator.migrations_paths, version)
      end
    end

    # rollback latest migration `step` number of times
    def rollback(database, step = 1)
      Tenant.switch(database) do
        ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
apartment-2.1.0 lib/apartment/migrator.rb
apartment-2.0.0 lib/apartment/migrator.rb
apartment-1.2.0 lib/apartment/migrator.rb
apartment-1.1.0 lib/apartment/migrator.rb
apartment-1.0.2 lib/apartment/migrator.rb
apartment-1.0.1 lib/apartment/migrator.rb
apartment-1.0.0 lib/apartment/migrator.rb