lib/pgsync/task.rb in pgsync-0.7.1 vs lib/pgsync/task.rb in pgsync-0.7.2

- old
+ new

@@ -86,11 +86,11 @@ copy_fields = shared_fields.map { |f| f2 = bad_fields.to_a.find { |bf, _| rule_match?(table, f, bf) }; f2 ? "#{apply_strategy(f2[1], table, f, primary_key)} AS #{quote_ident(f)}" : "#{quoted_table}.#{quote_ident(f)}" }.join(", ") fields = shared_fields.map { |f| quote_ident(f) }.join(", ") copy_to_command = "COPY (SELECT #{copy_fields} FROM #{quoted_table}#{sql_clause}) TO STDOUT" if opts[:in_batches] - raise Error, "No primary key" if primary_key.empty? + raise Error, "Primary key required for --in-batches" if primary_key.empty? primary_key = primary_key.first destination.truncate(table) if opts[:truncate] from_max_id = source.max_id(table, primary_key) @@ -123,10 +123,14 @@ if opts[:sleep] && starting_id <= from_max_id sleep(opts[:sleep]) end end elsif !opts[:truncate] && (opts[:overwrite] || opts[:preserve] || !sql_clause.empty?) - raise Error, "No primary key" if primary_key.empty? + if primary_key.empty? + raise Error, "Primary key required for --overwrite" if opts[:overwrite] + raise Error, "Primary key required for --preserve" if opts[:preserve] + raise Error, "Primary key required to sync specific rows" + end # create a temp table temp_table = "pgsync_#{rand(1_000_000_000)}" destination.execute("CREATE TEMPORARY TABLE #{quote_ident_full(temp_table)} AS TABLE #{quoted_table} WITH NO DATA")