class Lhm::ChunkFinder

Attributes

limit[RW]
start[RW]

Public Class Methods

new(migration, connection = nil, options = {}) click to toggle source
# File lib/lhm/chunk_finder.rb, line 3
def initialize(migration, connection = nil, options = {})
  @migration = migration
  @connection = connection
  @start = options[:start] || select_start_from_db
  @limit = options[:limit] || select_limit_from_db
end

Public Instance Methods

table_empty?() click to toggle source
# File lib/lhm/chunk_finder.rb, line 12
def table_empty?
  start.nil? && limit.nil?
end
validate() click to toggle source
# File lib/lhm/chunk_finder.rb, line 16
def validate
  if start > limit
    raise ArgumentError, "impossible chunk options (limit (#{limit.inspect} must be greater than start (#{start.inspect})"
  end
end

Private Instance Methods

select_limit_from_db() click to toggle source
# File lib/lhm/chunk_finder.rb, line 28
def select_limit_from_db
  @connection.select_value("select max(id) from `#{ @migration.origin_name }`")
end
select_start_from_db() click to toggle source
# File lib/lhm/chunk_finder.rb, line 24
def select_start_from_db
  @connection.select_value("select min(id) from `#{ @migration.origin_name }`")
end