Class: NeonPostgres::InterDatabaseCopy::DocumentTemplateCopier

Inherits:
Object
  • Object
show all
Defined in:
lib/neon_postgres/inter_database_copy/document_template_copier.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_connection:, to_connection:) ⇒ DocumentTemplateCopier

Returns a new instance of DocumentTemplateCopier.



16
17
18
19
# File 'lib/neon_postgres/inter_database_copy/document_template_copier.rb', line 16

def initialize(from_connection:, to_connection:)
  @from_connection = from_connection
  @to_connection = to_connection
end

Class Method Details

.copy(from_connection: NeonPostgres::Database.from_connection, to_connection: NeonPostgres::Database.to_connection) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/neon_postgres/inter_database_copy/document_template_copier.rb', line 6

def self.copy(
  from_connection: NeonPostgres::Database.from_connection,
  to_connection: NeonPostgres::Database.to_connection
)
  new(
    from_connection: from_connection,
    to_connection: to_connection
  ).copy
end

Instance Method Details

#copy ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/neon_postgres/inter_database_copy/document_template_copier.rb', line 21

def copy
  from_dataset.each do |row|
    to_dataset
      .insert_conflict(
        target: :id,
        update: {
          name: Sequel[:excluded][:name],
          description: Sequel[:excluded][:description],
          abbreviation: Sequel[:excluded][:abbreviation],
          jurisdiction: Sequel[:excluded][:jurisdiction]
        }
      ).insert(row)
  end
end