pgsync 0.7.1 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +26 -5
- data/lib/pgsync/data_source.rb +12 -2
- data/lib/pgsync/schema_sync.rb +12 -5
- data/lib/pgsync/sync.rb +2 -2
- data/lib/pgsync/table_sync.rb +2 -2
- data/lib/pgsync/task.rb +6 -2
- data/lib/pgsync/utils.rb +4 -0
- data/lib/pgsync/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b57c0423d780695d7379788efa869966318b23e3d8b9d92c8218ffb4cdee8609
|
4
|
+
data.tar.gz: 8e07cdad5a540c72df19ebdcbcc0e1c0e9930b6c4b1eb46f0bf318cada503bdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b91a30483535b049852ef679fe5944f065db7c56825a147775a904290c4a1e6221bfde512d7509cd475d97e5c8586c1107870cea4f19407782cd2f7caba88fc7
|
7
|
+
data.tar.gz: fbd6e09e5231a89824098c193d58f2debd90005df01fa432aff546e72ffc0b7ec6b951a237fb65f09ce640f28f6c660b29c77bc231744378055fe8b53e643b34
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 0.7.3 (2022-11-09)
|
2
|
+
|
3
|
+
- Fixed issue with pg 1.4.4
|
4
|
+
- Fixed output when `pg_restore` not found
|
5
|
+
|
6
|
+
## 0.7.2 (2022-09-19)
|
7
|
+
|
8
|
+
- Improved error message when a primary key is required
|
9
|
+
- Switched to monotonic time
|
10
|
+
- Fixed schema sync with Homebrew Postgres 14.5
|
11
|
+
|
1
12
|
## 0.7.1 (2022-07-06)
|
2
13
|
|
3
14
|
- Fixed random letter data rule generating non-letter
|
data/README.md
CHANGED
@@ -19,7 +19,13 @@ 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.
|
22
|
+
This will give you the `pgsync` command. If installation fails, you may need to install [dependencies](#dependencies).
|
23
|
+
|
24
|
+
You can also install it with Homebrew:
|
25
|
+
|
26
|
+
```sh
|
27
|
+
brew install pgsync
|
28
|
+
```
|
23
29
|
|
24
30
|
## Setup
|
25
31
|
|
@@ -347,14 +353,17 @@ Bundler.with_unbundled_env do
|
|
347
353
|
end
|
348
354
|
```
|
349
355
|
|
350
|
-
##
|
356
|
+
## Docker
|
351
357
|
|
352
|
-
|
358
|
+
Get the [Docker image](https://hub.docker.com/r/ankane/pgsync) with:
|
353
359
|
|
354
360
|
```sh
|
355
|
-
|
361
|
+
docker pull ankane/pgsync
|
362
|
+
alias pgsync="docker run -ti ankane/pgsync"
|
356
363
|
```
|
357
364
|
|
365
|
+
This will give you the `pgsync` command.
|
366
|
+
|
358
367
|
## Dependencies
|
359
368
|
|
360
369
|
If installation fails, your system may be missing Ruby or libpq.
|
@@ -362,7 +371,7 @@ If installation fails, your system may be missing Ruby or libpq.
|
|
362
371
|
On Mac, run:
|
363
372
|
|
364
373
|
```sh
|
365
|
-
brew install
|
374
|
+
brew install libpq
|
366
375
|
```
|
367
376
|
|
368
377
|
On Ubuntu, run:
|
@@ -386,6 +395,18 @@ gem install specific_install
|
|
386
395
|
gem specific_install https://github.com/ankane/pgsync.git
|
387
396
|
```
|
388
397
|
|
398
|
+
With Homebrew, run:
|
399
|
+
|
400
|
+
```sh
|
401
|
+
brew upgrade pgsync
|
402
|
+
```
|
403
|
+
|
404
|
+
With Docker, run:
|
405
|
+
|
406
|
+
```sh
|
407
|
+
docker pull ankane/pgsync
|
408
|
+
```
|
409
|
+
|
389
410
|
## Related Projects
|
390
411
|
|
391
412
|
Also check out:
|
data/lib/pgsync/data_source.rb
CHANGED
@@ -19,11 +19,11 @@ module PgSync
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def host
|
22
|
-
@host ||= conninfo[:host]
|
22
|
+
@host ||= dedup_localhost(conninfo[:host])
|
23
23
|
end
|
24
24
|
|
25
25
|
def port
|
26
|
-
@port ||= conninfo[:port]
|
26
|
+
@port ||= dedup_localhost(conninfo[:port])
|
27
27
|
end
|
28
28
|
|
29
29
|
def dbname
|
@@ -189,5 +189,15 @@ module PgSync
|
|
189
189
|
conn.conninfo_hash
|
190
190
|
end
|
191
191
|
end
|
192
|
+
|
193
|
+
# for pg 1.4.4
|
194
|
+
# https://github.com/ged/ruby-pg/issues/490
|
195
|
+
def dedup_localhost(value)
|
196
|
+
if conninfo[:host] == "localhost,localhost" && conninfo[:port].to_s.split(",").uniq.size == 1
|
197
|
+
value.split(",")[0]
|
198
|
+
else
|
199
|
+
value
|
200
|
+
end
|
201
|
+
end
|
192
202
|
end
|
193
203
|
end
|
data/lib/pgsync/schema_sync.rb
CHANGED
@@ -17,6 +17,11 @@ module PgSync
|
|
17
17
|
raise Error, "Cannot use --preserve with --schema-first or --schema-only"
|
18
18
|
end
|
19
19
|
|
20
|
+
# generate commands before starting spinner
|
21
|
+
# for better error output if pg_restore not found
|
22
|
+
dump_command = dump_command()
|
23
|
+
restore_command = restore_command()
|
24
|
+
|
20
25
|
show_spinner = output.tty? && !opts[:debug]
|
21
26
|
|
22
27
|
if show_spinner
|
@@ -29,7 +34,7 @@ module PgSync
|
|
29
34
|
# if spinner, capture lines to show on error
|
30
35
|
lines = []
|
31
36
|
success =
|
32
|
-
run_command do |line|
|
37
|
+
run_command(dump_command, restore_command) do |line|
|
33
38
|
if show_spinner
|
34
39
|
lines << line
|
35
40
|
else
|
@@ -51,7 +56,7 @@ module PgSync
|
|
51
56
|
|
52
57
|
private
|
53
58
|
|
54
|
-
def run_command
|
59
|
+
def run_command(dump_command, restore_command)
|
55
60
|
err_r, err_w = IO.pipe
|
56
61
|
Open3.pipeline_start(dump_command, restore_command, err: err_w) do |wait_thrs|
|
57
62
|
err_w.close
|
@@ -62,8 +67,10 @@ module PgSync
|
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
|
-
|
66
|
-
|
70
|
+
# --if-exists introduced in Postgres 9.4
|
71
|
+
# not ideal, but simpler than trying to parse version
|
72
|
+
def supports_if_exists?
|
73
|
+
`pg_restore --help`.include?("--if-exists")
|
67
74
|
rescue Errno::ENOENT
|
68
75
|
raise Error, "pg_restore not found"
|
69
76
|
end
|
@@ -80,7 +87,7 @@ module PgSync
|
|
80
87
|
|
81
88
|
def restore_command
|
82
89
|
cmd = ["pg_restore", "--verbose", "--no-owner", "--no-acl", "--clean"]
|
83
|
-
cmd << "--if-exists" if
|
90
|
+
cmd << "--if-exists" if supports_if_exists?
|
84
91
|
cmd.concat(["-d", @destination.url])
|
85
92
|
end
|
86
93
|
|
data/lib/pgsync/sync.rb
CHANGED
@@ -8,7 +8,7 @@ module PgSync
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def perform
|
11
|
-
started_at =
|
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 =
|
132
|
+
time = monotonic_time - started_at
|
133
133
|
message = "Completed in #{time.round(1)}s"
|
134
134
|
log colorize(message, :green)
|
135
135
|
end
|
data/lib/pgsync/table_sync.rb
CHANGED
@@ -189,11 +189,11 @@ module PgSync
|
|
189
189
|
log message.sub(":spinner", "⠋")
|
190
190
|
end
|
191
191
|
|
192
|
-
started_at[task] =
|
192
|
+
started_at[task] = monotonic_time
|
193
193
|
end
|
194
194
|
|
195
195
|
finish = lambda do |task, i, result|
|
196
|
-
time = (
|
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, "
|
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
|
-
|
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
data/lib/pgsync/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.3
|
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-
|
11
|
+
date: 2022-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|