Class: Gitlab::Database::PartitioningMigrationHelpers::BackfillPartitionedTable::BulkCopy

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb

Overview

Helper class to copy data between two tables via upserts

Constant Summary collapse

DELIMITER =
', '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_table, destination_table, source_column) ⇒ BulkCopy

Returns a new instance of BulkCopy.


71
72
73
74
75
# File 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb', line 71

def initialize(source_table, destination_table, source_column)
  @source_table = source_table
  @destination_table = destination_table
  @source_column = source_column
end

Instance Attribute Details

#destination_tableObject (readonly)

Returns the value of attribute destination_table


69
70
71
# File 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb', line 69

def destination_table
  @destination_table
end

#source_columnObject (readonly)

Returns the value of attribute source_column


69
70
71
# File 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb', line 69

def source_column
  @source_column
end

#source_tableObject (readonly)

Returns the value of attribute source_table


69
70
71
# File 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb', line 69

def source_table
  @source_table
end

Instance Method Details

#copy_between(start_id, stop_id) ⇒ Object


77
78
79
80
81
82
83
84
85
86
# File 'lib/gitlab/database/partitioning_migration_helpers/backfill_partitioned_table.rb', line 77

def copy_between(start_id, stop_id)
  connection.execute(<<~SQL)
    INSERT INTO #{destination_table} (#{column_listing})
    SELECT #{column_listing}
    FROM #{source_table}
    WHERE #{source_column} BETWEEN #{start_id} AND #{stop_id}
    FOR UPDATE
    ON CONFLICT (#{conflict_targets}) DO NOTHING
  SQL
end