Class: Gitlab::Database::PartitioningMigrationHelpers::BulkCopy
- Inherits:
-
Object
- Object
- Gitlab::Database::PartitioningMigrationHelpers::BulkCopy
- Defined in:
- lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb
Overview
Helper class to copy data between two tables via upserts
Constant Summary collapse
- DELIMITER =
', '
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#destination_table ⇒ Object
readonly
Returns the value of attribute destination_table.
-
#source_column ⇒ Object
readonly
Returns the value of attribute source_column.
-
#source_table ⇒ Object
readonly
Returns the value of attribute source_table.
Instance Method Summary collapse
- #copy_between(start_id, stop_id) ⇒ Object
- #copy_relation(relation) ⇒ Object
-
#initialize(source_table, destination_table, source_column, connection:) ⇒ BulkCopy
constructor
A new instance of BulkCopy.
Constructor Details
#initialize(source_table, destination_table, source_column, connection:) ⇒ BulkCopy
Returns a new instance of BulkCopy.
12 13 14 15 16 17 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 12 def initialize(source_table, destination_table, source_column, connection:) @source_table = source_table @destination_table = destination_table @source_column = source_column @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 10 def connection @connection end |
#destination_table ⇒ Object (readonly)
Returns the value of attribute destination_table.
10 11 12 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 10 def destination_table @destination_table end |
#source_column ⇒ Object (readonly)
Returns the value of attribute source_column.
10 11 12 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 10 def source_column @source_column end |
#source_table ⇒ Object (readonly)
Returns the value of attribute source_table.
10 11 12 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 10 def source_table @source_table end |
Instance Method Details
#copy_between(start_id, stop_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 19 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 |
#copy_relation(relation) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/database/partitioning_migration_helpers/bulk_copy.rb', line 30 def copy_relation(relation) connection.execute(<<~SQL) INSERT INTO #{destination_table} (#{column_listing}) #{relation.select(column_listing).to_sql} FOR UPDATE ON CONFLICT (#{conflict_targets}) DO NOTHING SQL end |