lib/pgsync/client.rb in pgsync-0.3.9 vs lib/pgsync/client.rb in pgsync-0.4.0

- old
+ new

@@ -1,20 +1,21 @@ module PgSync class Client def initialize(args) $stdout.sync = true + $stderr.sync = true @exit = false @arguments, @options = parse_args(args) @mutex = windows? ? Mutex.new : MultiProcessing::Mutex.new end # TODO clean up this mess def perform return if @exit args, opts = @arguments, @options - [:to, :from, :to_safe, :exclude].each do |opt| + [:to, :from, :to_safe, :exclude, :schemas].each do |opt| opts[opt] ||= config[opt.to_s] end map_deprecations(args, opts) if opts[:setup] @@ -39,17 +40,26 @@ raise PgSync::Error, "No source" unless source.exists? destination = DataSource.new(opts[:to]) raise PgSync::Error, "No destination" unless destination.exists? - unless opts[:to_safe] || destination.local? - raise PgSync::Error, "Danger! Add `to_safe: true` to `.pgsync.yml` if the destination is not localhost or 127.0.0.1" - end + begin + # start connections + source.host + destination.host - print_description("From", source) - print_description("To", destination) + unless opts[:to_safe] || destination.local? + raise PgSync::Error, "Danger! Add `to_safe: true` to `.pgsync.yml` if the destination is not localhost or 127.0.0.1" + end + print_description("From", source) + print_description("To", destination) + ensure + source.close + destination.close + end + tables = nil begin tables = TableList.new(args, opts, source, config).tables ensure source.close @@ -80,26 +90,26 @@ unless opts[:schema_only] confirm_tables_exist(destination, tables, "destination") in_parallel(tables) do |table, table_opts| - TableSync.new.sync_with_benchmark(@mutex, config, table, opts.merge(table_opts), source.url, destination.url) + TableSync.new.sync(@mutex, config, table, opts.merge(table_opts), source.url, destination.url, source.search_path.find { |sp| sp != "pg_catalog" }) end end log_completed(start_time) end end - def confirm_tables_exist(destination, tables, description) + def confirm_tables_exist(data_source, tables, description) tables.keys.each do |table| - unless destination.table_exists?(table) + unless data_source.table_exists?(table) raise PgSync::Error, "Table does not exist in #{description}: #{table}" end end ensure - destination.close + data_source.close end def map_deprecations(args, opts) command = args[0] @@ -213,10 +223,11 @@ return unless db ".pgsync-#{db}.yml" end def print_description(prefix, source) - log "#{prefix}: #{source.uri.path.sub(/\A\//, '')} on #{source.uri.host}:#{source.uri.port}" + location = " on #{source.host}:#{source.port}" if source.host + log "#{prefix}: #{source.dbname}#{location}" end def search_tree(file) path = Dir.pwd # prevent infinite loop