Class: NeonPostgres::InterDatabaseCopy::MatterDocumentsCopier
- Inherits:
-
Object
- Object
- NeonPostgres::InterDatabaseCopy::MatterDocumentsCopier
- Defined in:
- lib/neon_postgres/inter_database_copy/matter_documents_copier.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy ⇒ Object
-
#initialize(from_connection:, to_connection:) ⇒ MatterDocumentsCopier
constructor
A new instance of MatterDocumentsCopier.
Constructor Details
#initialize(from_connection:, to_connection:) ⇒ MatterDocumentsCopier
Returns a new instance of MatterDocumentsCopier.
17 18 19 20 |
# File 'lib/neon_postgres/inter_database_copy/matter_documents_copier.rb', line 17 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
7 8 9 10 11 12 13 14 15 |
# File 'lib/neon_postgres/inter_database_copy/matter_documents_copier.rb', line 7 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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/neon_postgres/inter_database_copy/matter_documents_copier.rb', line 22 def copy from_dataset.each do |row| to_connection[:documents].insert_conflict( target: :id, update: { filename: Sequel[:excluded][:filename], gcp_url: Sequel[:excluded][:gcp_url], document_template_id: Sequel[:excluded][:document_template_id], documentable_table_name: Sequel[:excluded][ :documentable_table_name ], created_at: Sequel[:excluded][:created_at] } ).insert({ id: row.fetch(:document_id), filename: row.fetch(:filename), gcp_url: row.fetch(:gcp_url), documentable_table_name: row.fetch(:documentable_table_name), document_template_id: row.fetch(:document_template_id), created_at: row.fetch(:created_at) }) matter_id = to_connection[:matters].select(:id).all.sample.fetch(:id) = to_connection[:people].select(:id).all.sample.fetch(:id) to_connection[:matter_documents].insert_conflict({ target: :document_id, update: { matter_id: Sequel[:excluded][:matter_id], author_id: Sequel[:excluded][:author_id] } }).insert({ document_id: row.fetch(:document_id), matter_id: matter_id, author_id: }) end end |