Sha256: d9a72738c11e436245e4abec11c3923636997202eda9cb02e8a0b2f56f7805aa

Contents?: true

Size: 819 Bytes

Versions: 22

Compression:

Stored size: 819 Bytes

Contents

module Lhm
  class ChunkFinder
    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

    attr_accessor :start, :limit

    def table_empty?
      start.nil? && limit.nil?
    end

    def validate
      if start > limit
        raise ArgumentError, "impossible chunk options (limit (#{limit.inspect} must be greater than start (#{start.inspect})"
      end
    end

    private

    def select_start_from_db
      @connection.select_value("select min(id) from `#{ @migration.origin_name }`")
    end

    def select_limit_from_db
      @connection.select_value("select max(id) from `#{ @migration.origin_name }`")
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
lhm-shopify-4.4.2 lib/lhm/chunk_finder.rb
lhm-shopify-4.4.1 lib/lhm/chunk_finder.rb
lhm-shopify-4.4.0 lib/lhm/chunk_finder.rb
lhm-shopify-4.3.0 lib/lhm/chunk_finder.rb
lhm-shopify-4.2.3 lib/lhm/chunk_finder.rb
lhm-shopify-4.2.2 lib/lhm/chunk_finder.rb
lhm-shopify-4.2.1 lib/lhm/chunk_finder.rb
lhm-shopify-4.2.0 lib/lhm/chunk_finder.rb
lhm-shopify-4.1.1 lib/lhm/chunk_finder.rb
lhm-shopify-4.1.0 lib/lhm/chunk_finder.rb
lhm-shopify-4.0.0 lib/lhm/chunk_finder.rb
lhm-shopify-3.5.5 lib/lhm/chunk_finder.rb
lhm-shopify-3.5.4 lib/lhm/chunk_finder.rb
lhm-shopify-3.5.3 lib/lhm/chunk_finder.rb
lhm-shopify-3.5.2 lib/lhm/chunk_finder.rb
lhm-shopify-3.5.0 lib/lhm/chunk_finder.rb
lhm-shopify-3.5.1 lib/lhm/chunk_finder.rb
lhm-shopify-3.4.2 lib/lhm/chunk_finder.rb
lhm-shopify-3.4.1 lib/lhm/chunk_finder.rb
lhm-shopify-3.4.0 lib/lhm/chunk_finder.rb