pgsync 0.7.0 → 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: ba1091cc780447fdf3369431b15d87cd3b6e47bb047f4a34e2a36a70bb873669
4
- data.tar.gz: bf343a9fd3e785cb077953654656d51191827216b741b844736043bfaa2b7d8b
3
+ metadata.gz: 2005fe5d8c3aa978ebb5f85d2076e81ee1022564382a6401437c5c683a4968a2
4
+ data.tar.gz: 333ac51419e6e6ee8091a14ee78e4e8d1aa7559bdbd13384a27352f35641e9e9
5
5
  SHA512:
6
- metadata.gz: f30e0cfdfa4a5f2f3d48db16d66dea9ff101025b8a95fd383f0eec8b60bce111d0f41cef64467c50df3d4820a55230e64f0f04e68ef09f40ea57d658b3584da6
7
- data.tar.gz: 7feb71d51de95fba8d32d0080a43432a11f96080782aad0515dade6ce6f2b81def36f7b060a30aeeadcea14cc16dbf34fc1f94b02ebdb53c2453d1ff0ba6dd30
6
+ metadata.gz: 0a90323a6a4d2829c0e62c2d3d78245e9978a1c051da7c0913ce1f9a91a4f01bd0a6d80d14d2dbc49b63a0943c492e71d0191a458d3a2e16f0480c59078b7ee4
7
+ data.tar.gz: 8d9fa803daf091baa26afc26eba40bdc720b5836651c101bd53ce0e24f9fa9179f49577b61426e1a3315a5bb7fd90c815bfab54a40fb90376756c10392cccef4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
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
+
7
+ ## 0.7.1 (2022-07-06)
8
+
9
+ - Fixed random letter data rule generating non-letter
10
+
1
11
  ## 0.7.0 (2022-03-10)
2
12
 
3
13
  - Changed `--defer-constraints` to `--defer-constraints-v1`
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)}"
@@ -256,9 +260,11 @@ module PgSync
256
260
  when "random_time"
257
261
  "NOW() - (RANDOM() * 100000000)::int * INTERVAL '1 second'"
258
262
  when "random_ip"
263
+ # casting double to int rounds
259
264
  "(1 + RANDOM() * 254)::int::text || '.0.0.1'"
260
265
  when "random_letter"
261
- "chr(65 + (RANDOM() * 26)::int)"
266
+ # casting double to int rounds
267
+ "chr(65 + (RANDOM() * 25)::int)"
262
268
  when "random_string"
263
269
  "RIGHT(MD5(RANDOM()::text), 10)"
264
270
  when "null", nil
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.0"
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.0
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-03-11 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