pgsync 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 042c6ef2c6e17c85523588c23fb7d92dc23c625eeffd9f2988e56e346b6a46ec
4
- data.tar.gz: 567458066a079635a0a887941d0c8da492acacae24f79f44d48195425a397d32
3
+ metadata.gz: 2005fe5d8c3aa978ebb5f85d2076e81ee1022564382a6401437c5c683a4968a2
4
+ data.tar.gz: 333ac51419e6e6ee8091a14ee78e4e8d1aa7559bdbd13384a27352f35641e9e9
5
5
  SHA512:
6
- metadata.gz: c065a560b972175c371552ca69e7824d81d4bd1ebe72ed045ef5a5a59bcc28b738993019ca58231792f711a1f1acae4b42cb7ef68b73de83505c007a015e833d
7
- data.tar.gz: c38db8ae37eca93353a5f354035fcb604e3e423b4b3fd58719b95c955fad7970990549109454f49392133860903d34d6ac0ca477f82ea1824b23435a9ae6db7e
6
+ metadata.gz: 0a90323a6a4d2829c0e62c2d3d78245e9978a1c051da7c0913ce1f9a91a4f01bd0a6d80d14d2dbc49b63a0943c492e71d0191a458d3a2e16f0480c59078b7ee4
7
+ data.tar.gz: 8d9fa803daf091baa26afc26eba40bdc720b5836651c101bd53ce0e24f9fa9179f49577b61426e1a3315a5bb7fd90c815bfab54a40fb90376756c10392cccef4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.7.2 (2022-09-19)
2
+
3
+ - Improved error message when a primary key is required
4
+ - Switched to monotonic time
5
+ - Fixed schema sync with Homebrew Postgres 14.5
6
+
1
7
  ## 0.7.1 (2022-07-06)
2
8
 
3
9
  - Fixed random letter data rule generating non-letter
data/README.md CHANGED
@@ -19,7 +19,7 @@ pgsync is a command line tool. To install, run:
19
19
  gem install pgsync
20
20
  ```
21
21
 
22
- This will give you the `pgsync` command. You can also install it with [Homebrew](#homebrew). If installation fails, you may need to install [dependencies](#dependencies).
22
+ This will give you the `pgsync` command. You can also install it with [Homebrew](#homebrew) or [Docker](#docker). If installation fails, you may need to install [dependencies](#dependencies).
23
23
 
24
24
  ## Setup
25
25
 
@@ -347,14 +347,27 @@ Bundler.with_unbundled_env do
347
347
  end
348
348
  ```
349
349
 
350
- ## Homebrew
350
+ ## Additional Installation Methods
351
351
 
352
- On Mac, you can use:
352
+ ### Homebrew
353
+
354
+ With Homebrew, you can use:
353
355
 
354
356
  ```sh
355
357
  brew install ankane/brew/pgsync
356
358
  ```
357
359
 
360
+ ### Docker
361
+
362
+ Get the [Docker image](https://hub.docker.com/r/ankane/pgsync) with:
363
+
364
+ ```sh
365
+ docker pull ankane/pgsync
366
+ alias pgsync="docker run --rm ankane/pgsync"
367
+ ```
368
+
369
+ This will give you the `pgsync` command.
370
+
358
371
  ## Dependencies
359
372
 
360
373
  If installation fails, your system may be missing Ruby or libpq.
@@ -362,7 +375,7 @@ If installation fails, your system may be missing Ruby or libpq.
362
375
  On Mac, run:
363
376
 
364
377
  ```sh
365
- brew install postgresql
378
+ brew install libpq
366
379
  ```
367
380
 
368
381
  On Ubuntu, run:
@@ -62,8 +62,10 @@ module PgSync
62
62
  end
63
63
  end
64
64
 
65
- def pg_restore_version
66
- `pg_restore --version`.lines[0].chomp.split(" ")[-1].split(/[^\d.]/)[0]
65
+ # --if-exists introduced in Postgres 9.4
66
+ # not ideal, but simpler than trying to parse version
67
+ def supports_if_exists?
68
+ `pg_restore --help`.include?("--if-exists")
67
69
  rescue Errno::ENOENT
68
70
  raise Error, "pg_restore not found"
69
71
  end
@@ -80,7 +82,7 @@ module PgSync
80
82
 
81
83
  def restore_command
82
84
  cmd = ["pg_restore", "--verbose", "--no-owner", "--no-acl", "--clean"]
83
- cmd << "--if-exists" if Gem::Version.new(pg_restore_version) >= Gem::Version.new("9.4.0")
85
+ cmd << "--if-exists" if supports_if_exists?
84
86
  cmd.concat(["-d", @destination.url])
85
87
  end
86
88
 
data/lib/pgsync/sync.rb CHANGED
@@ -8,7 +8,7 @@ module PgSync
8
8
  end
9
9
 
10
10
  def perform
11
- started_at = Time.now
11
+ started_at = monotonic_time
12
12
 
13
13
  args = @arguments
14
14
  opts = @options
@@ -129,7 +129,7 @@ module PgSync
129
129
  end
130
130
 
131
131
  def log_completed(started_at)
132
- time = Time.now - started_at
132
+ time = monotonic_time - started_at
133
133
  message = "Completed in #{time.round(1)}s"
134
134
  log colorize(message, :green)
135
135
  end
@@ -189,11 +189,11 @@ module PgSync
189
189
  log message.sub(":spinner", "⠋")
190
190
  end
191
191
 
192
- started_at[task] = Time.now
192
+ started_at[task] = monotonic_time
193
193
  end
194
194
 
195
195
  finish = lambda do |task, i, result|
196
- time = (Time.now - started_at[task]).round(1)
196
+ time = (monotonic_time - started_at[task]).round(1)
197
197
 
198
198
  success = result[:status] == "success"
199
199
 
data/lib/pgsync/task.rb CHANGED
@@ -88,7 +88,7 @@ module PgSync
88
88
 
89
89
  copy_to_command = "COPY (SELECT #{copy_fields} FROM #{quoted_table}#{sql_clause}) TO STDOUT"
90
90
  if opts[:in_batches]
91
- raise Error, "No primary key" if primary_key.empty?
91
+ raise Error, "Primary key required for --in-batches" if primary_key.empty?
92
92
  primary_key = primary_key.first
93
93
 
94
94
  destination.truncate(table) if opts[:truncate]
@@ -125,7 +125,11 @@ module PgSync
125
125
  end
126
126
  end
127
127
  elsif !opts[:truncate] && (opts[:overwrite] || opts[:preserve] || !sql_clause.empty?)
128
- raise Error, "No primary key" if primary_key.empty?
128
+ if primary_key.empty?
129
+ raise Error, "Primary key required for --overwrite" if opts[:overwrite]
130
+ raise Error, "Primary key required for --preserve" if opts[:preserve]
131
+ raise Error, "Primary key required to sync specific rows"
132
+ end
129
133
 
130
134
  # create a temp table
131
135
  temp_table = "pgsync_#{rand(1_000_000_000)}"
data/lib/pgsync/utils.rb CHANGED
@@ -83,5 +83,9 @@ module PgSync
83
83
  def quote_string(s)
84
84
  s.gsub(/\\/, '\&\&').gsub(/'/, "''")
85
85
  end
86
+
87
+ def monotonic_time
88
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
89
+ end
86
90
  end
87
91
  end
@@ -1,3 +1,3 @@
1
1
  module PgSync
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-06 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel