class Combustion::Database::Migrate

Public Class Methods

call() click to toggle source
# File lib/combustion/database/migrate.rb, line 4
def self.call
  new.call
end

Public Instance Methods

call() click to toggle source
# File lib/combustion/database/migrate.rb, line 8
def call
  if ActiveRecord::VERSION::STRING.to_f >= 5.2
    migration_context.migrate
  elsif ActiveRecord::VERSION::STRING.to_f >= 3.1
    migrator.migrate paths, nil
  else
    paths.each { |path| migrator.migrate path, nil }
  end
end

Private Instance Methods

base_migration_paths() click to toggle source
# File lib/combustion/database/migrate.rb, line 20
def base_migration_paths
  if migrator.respond_to?(:migrations_paths)
    migrator.migrations_paths
  else
    Array("db/migrate/")
  end
end
engine_migration_paths() click to toggle source
# File lib/combustion/database/migrate.rb, line 28
def engine_migration_paths
  migration_paths = Rails.application.paths["db/migrate"].to_a

  if engine_paths_exist_in?(migration_paths)
    migration_paths
  else
    base_migration_paths + migration_paths
  end
end
engine_path() click to toggle source
# File lib/combustion/database/migrate.rb, line 38
def engine_path
  Rails.application.root.sub(::Combustion.path, "")
end
engine_paths_exist_in?(paths) click to toggle source
# File lib/combustion/database/migrate.rb, line 42
def engine_paths_exist_in?(paths)
  paths.include?(engine_path.join("db/migrate").to_s)
end
migration_context() click to toggle source
# File lib/combustion/database/migrate.rb, line 46
def migration_context
  if ActiveRecord::MigrationContext.instance_method(:initialize).arity <= 1
    ActiveRecord::MigrationContext.new paths
  else
    ActiveRecord::MigrationContext.new(
      paths, ActiveRecord::Base.connection.schema_migration
    )
  end
end
migrator() click to toggle source
# File lib/combustion/database/migrate.rb, line 56
def migrator
  @migrator ||= ActiveRecord::Migrator
end
paths() click to toggle source
# File lib/combustion/database/migrate.rb, line 60
def paths
  (engine_migration_paths + [File.join(Rails.root, "db/migrate")]).uniq
end