Sha256: 393959159833b773543365f2075344a7766ec3d5883bf66bc4e167fc90c3d744

Contents?: true

Size: 913 Bytes

Versions: 4

Compression:

Stored size: 913 Bytes

Contents

require 'apartment/database'

module Apartment
  module Migrator

    extend self

    # Migrate to latest
    def migrate(database)
      Database.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)
      Database.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)
      Database.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.24.3 lib/apartment/migrator.rb
apartment-0.24.2 lib/apartment/migrator.rb
apartment-0.24.1 lib/apartment/migrator.rb
apartment-0.24.0 lib/apartment/migrator.rb