Class: PgLogicalReplicator::SchemaTransfer
- Inherits:
-
Object
- Object
- PgLogicalReplicator::SchemaTransfer
- Defined in:
- lib/pg_logical_replicator/schema_transfer.rb
Instance Method Summary collapse
-
#initialize(source_host:, source_port:, source_database:, target_host:, target_port:, target_database:, source_username:, source_password:, target_username:, target_password:) ⇒ SchemaTransfer
constructor
A new instance of SchemaTransfer.
- #transfer ⇒ Object
Constructor Details
#initialize(source_host:, source_port:, source_database:, target_host:, target_port:, target_database:, source_username:, source_password:, target_username:, target_password:) ⇒ SchemaTransfer
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pg_logical_replicator/schema_transfer.rb', line 8 def initialize(source_host:, source_port:, source_database:, target_host:, target_port:, target_database:, source_username:, source_password:, target_username:, target_password:) @source_host = source_host @source_port = source_port @source_database = source_database @source_username = source_username @source_password = source_password @target_host = target_host @target_port = target_port @target_database = target_database @target_username = target_username @target_password = target_password end |
Instance Method Details
#transfer ⇒ Object
21 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 |
# File 'lib/pg_logical_replicator/schema_transfer.rb', line 21 def transfer puts 'Starting schema transfer...' ENV['PGPASSWORD_SOURCE'] = @source_password ENV['PGPASSWORD_TARGET'] = @target_password Tempfile.create('db_dump') do |tempfile| pg_dump_command = [ "pg_dump", "-s", "--no-owner", "--no-acl", "--no-privileges", "-h", @source_host, "-p", @source_port, "-d", @source_database, "-U", @source_username, "> #{tempfile.path}" ].join(' ') psql_command = [ "psql", "-h", @target_host, "-p", @target_port, "-d", @target_database, "-U", @target_username, "< #{tempfile.path}" ].join(' ') system({ "PGPASSWORD" => ENV['PGPASSWORD_SOURCE'] }, pg_dump_command) system({ "PGPASSWORD" => ENV['PGPASSWORD_TARGET'] }, psql_command) end ENV.delete('PGPASSWORD_SOURCE') ENV.delete('PGPASSWORD_TARGET') puts 'Schema transfer completed successfully.' end |