Class: Lhm::ChunkInsert

Inherits:
Object
  • Object
show all
Defined in:
lib/lhm/chunk_insert.rb

Constant Summary collapse

LOG_PREFIX =
"ChunkInsert"

Instance Method Summary collapse

Constructor Details

#initialize(migration, connection, lowest, highest, retry_options = {}) ⇒ ChunkInsert

Returns a new instance of ChunkInsert.



9
10
11
12
13
14
15
# File 'lib/lhm/chunk_insert.rb', line 9

def initialize(migration, connection, lowest, highest, retry_options = {})
  @migration = migration
  @connection = connection
  @lowest = lowest
  @highest = highest
  @retry_options = retry_options
end

Instance Method Details

#insert_and_return_count_of_rows_createdObject



17
18
19
# File 'lib/lhm/chunk_insert.rb', line 17

def insert_and_return_count_of_rows_created
  @connection.update(sql, should_retry: true, log_prefix: LOG_PREFIX)
end

#sqlObject



21
22
23
24
25
# File 'lib/lhm/chunk_insert.rb', line 21

def sql
  "insert ignore into `#{ @migration.destination_name }` (#{ @migration.destination_columns }) " \
  "select #{ @migration.origin_columns } from `#{ @migration.origin_name }` " \
  "#{ conditions } `#{ @migration.origin_name }`.`id` between #{ @lowest } and #{ @highest }"
end