Sha256: 0ab9cfc4c8d9d68bd76ca7ceb5e2ab85cf6b5d4098ae6fc5fdd6f2bc5e72a11d

Contents?: true

Size: 905 Bytes

Versions: 4

Compression:

Stored size: 905 Bytes

Contents

require 'apartment/tenant'

module Apartment
  module Migrator

    extend self

    # Migrate to latest
    def migrate(database)
      Tenant.process(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.process(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.process(database) do
        ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apartment-0.26.1 lib/apartment/migrator.rb
apartment-0.26.0 lib/apartment/migrator.rb
apartment-0.25.2 lib/apartment/migrator.rb
apartment-0.25.1 lib/apartment/migrator.rb