pgsync 0.6.7 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/LICENSE.txt +1 -1
- data/README.md +10 -2
- data/lib/pgsync/client.rb +5 -3
- data/lib/pgsync/data_source.rb +17 -0
- data/lib/pgsync/schema_sync.rb +16 -1
- data/lib/pgsync/sync.rb +10 -1
- data/lib/pgsync/table_sync.rb +3 -3
- data/lib/pgsync/task.rb +4 -2
- data/lib/pgsync/version.rb +1 -1
- data/lib/pgsync.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 042c6ef2c6e17c85523588c23fb7d92dc23c625eeffd9f2988e56e346b6a46ec
|
4
|
+
data.tar.gz: 567458066a079635a0a887941d0c8da492acacae24f79f44d48195425a397d32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c065a560b972175c371552ca69e7824d81d4bd1ebe72ed045ef5a5a59bcc28b738993019ca58231792f711a1f1acae4b42cb7ef68b73de83505c007a015e833d
|
7
|
+
data.tar.gz: c38db8ae37eca93353a5f354035fcb604e3e423b4b3fd58719b95c955fad7970990549109454f49392133860903d34d6ac0ca477f82ea1824b23435a9ae6db7e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 0.7.1 (2022-07-06)
|
2
|
+
|
3
|
+
- Fixed random letter data rule generating non-letter
|
4
|
+
|
5
|
+
## 0.7.0 (2022-03-10)
|
6
|
+
|
7
|
+
- Changed `--defer-constraints` to `--defer-constraints-v1`
|
8
|
+
- Changed `--defer-constraints-v2` to `--defer-constraints`
|
9
|
+
- Fixed unknown alias error with Ruby 3.1
|
10
|
+
- Dropped support for Ruby < 2.5
|
11
|
+
|
12
|
+
## 0.6.8 (2021-09-21)
|
13
|
+
|
14
|
+
- Fixed error when schema missing in destination with `--schema-first` and `--schema-only`
|
15
|
+
|
1
16
|
## 0.6.7 (2021-04-26)
|
2
17
|
|
3
18
|
- Fixed connection security for `--schema-first` and `--schema-only` - [more info](https://github.com/ankane/pgsync/issues/121)
|
data/LICENSE.txt
CHANGED
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. 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). If installation fails, you may need to install [dependencies](#dependencies).
|
23
23
|
|
24
24
|
## Setup
|
25
25
|
|
@@ -205,7 +205,7 @@ Foreign keys can make it difficult to sync data. Three options are:
|
|
205
205
|
To defer constraints, use:
|
206
206
|
|
207
207
|
```sh
|
208
|
-
pgsync --defer-constraints
|
208
|
+
pgsync --defer-constraints
|
209
209
|
```
|
210
210
|
|
211
211
|
To manually specify the order of tables, use `--jobs 1` so tables are synced one-at-a-time.
|
@@ -347,6 +347,14 @@ Bundler.with_unbundled_env do
|
|
347
347
|
end
|
348
348
|
```
|
349
349
|
|
350
|
+
## Homebrew
|
351
|
+
|
352
|
+
On Mac, you can use:
|
353
|
+
|
354
|
+
```sh
|
355
|
+
brew install ankane/brew/pgsync
|
356
|
+
```
|
357
|
+
|
350
358
|
## Dependencies
|
351
359
|
|
352
360
|
If installation fails, your system may be missing Ruby or libpq.
|
data/lib/pgsync/client.rb
CHANGED
@@ -11,6 +11,7 @@ module PgSync
|
|
11
11
|
result = Slop::Parser.new(slop_options).parse(@args)
|
12
12
|
arguments = result.arguments
|
13
13
|
options = result.to_h
|
14
|
+
options[:defer_constraints_v2] ||= options[:defer_constraints]
|
14
15
|
|
15
16
|
raise Error, "Specify either --db or --config, not both" if options[:db] && options[:config]
|
16
17
|
raise Error, "Cannot use --overwrite with --in-batches" if options[:overwrite] && options[:in_batches]
|
@@ -59,12 +60,13 @@ module PgSync
|
|
59
60
|
|
60
61
|
o.separator ""
|
61
62
|
o.separator "Foreign key options:"
|
62
|
-
o.boolean "--defer-constraints
|
63
|
+
o.boolean "--defer-constraints", "defer constraints", default: false
|
63
64
|
o.boolean "--disable-integrity", "disable foreign key triggers", default: false
|
64
65
|
o.integer "-j", "--jobs", "number of tables to sync at a time"
|
65
66
|
|
66
|
-
#
|
67
|
-
o.boolean "--defer-constraints", "defer constraints", default: false, help: false
|
67
|
+
# legacy
|
68
|
+
o.boolean "--defer-constraints-v1", "defer constraints", default: false, help: false
|
69
|
+
o.boolean "--defer-constraints-v2", "defer constraints", default: false, help: false
|
68
70
|
# private, for testing
|
69
71
|
o.boolean "--disable-integrity-v2", "disable foreign key triggers", default: false, help: false
|
70
72
|
|
data/lib/pgsync/data_source.rb
CHANGED
@@ -68,6 +68,23 @@ module PgSync
|
|
68
68
|
execute("TRUNCATE #{quote_ident_full(table)} CASCADE")
|
69
69
|
end
|
70
70
|
|
71
|
+
def schemas
|
72
|
+
@schemas ||= begin
|
73
|
+
query = <<~SQL
|
74
|
+
SELECT
|
75
|
+
schema_name
|
76
|
+
FROM
|
77
|
+
information_schema.schemata
|
78
|
+
ORDER BY 1
|
79
|
+
SQL
|
80
|
+
execute(query).map { |row| row["schema_name"] }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def create_schema(schema)
|
85
|
+
execute("CREATE SCHEMA #{quote_ident(schema)}")
|
86
|
+
end
|
87
|
+
|
71
88
|
def triggers(table)
|
72
89
|
query = <<~SQL
|
73
90
|
SELECT
|
data/lib/pgsync/schema_sync.rb
CHANGED
@@ -24,6 +24,8 @@ module PgSync
|
|
24
24
|
spinner.auto_spin
|
25
25
|
end
|
26
26
|
|
27
|
+
create_schemas if specify_tables?
|
28
|
+
|
27
29
|
# if spinner, capture lines to show on error
|
28
30
|
lines = []
|
29
31
|
success =
|
@@ -68,7 +70,7 @@ module PgSync
|
|
68
70
|
|
69
71
|
def dump_command
|
70
72
|
cmd = ["pg_dump", "-Fc", "--verbose", "--schema-only", "--no-owner", "--no-acl"]
|
71
|
-
if
|
73
|
+
if specify_tables?
|
72
74
|
@tasks.each do |task|
|
73
75
|
cmd.concat(["-t", task.quoted_table])
|
74
76
|
end
|
@@ -81,5 +83,18 @@ module PgSync
|
|
81
83
|
cmd << "--if-exists" if Gem::Version.new(pg_restore_version) >= Gem::Version.new("9.4.0")
|
82
84
|
cmd.concat(["-d", @destination.url])
|
83
85
|
end
|
86
|
+
|
87
|
+
# pg_dump -t won't create schemas (even with -n)
|
88
|
+
# not ideal that this happens outside restore transaction
|
89
|
+
def create_schemas
|
90
|
+
schemas = @tasks.map { |t| t.table.schema }.uniq - @destination.schemas
|
91
|
+
schemas.sort.each do |schema|
|
92
|
+
@destination.create_schema(schema)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def specify_tables?
|
97
|
+
!opts[:all_schemas] || opts[:tables] || opts[:groups] || args[0] || opts[:exclude] || opts[:schemas]
|
98
|
+
end
|
84
99
|
end
|
85
100
|
end
|
data/lib/pgsync/sync.rb
CHANGED
@@ -78,7 +78,16 @@ module PgSync
|
|
78
78
|
file = config_file
|
79
79
|
if file
|
80
80
|
begin
|
81
|
-
YAML.load_file
|
81
|
+
# same options as YAML.load_file
|
82
|
+
File.open(file, "r:bom|utf-8") do |f|
|
83
|
+
# changed to keyword arguments in 3.1.0.pre1
|
84
|
+
# https://github.com/ruby/psych/commit/c79ed445b4b3f8c9adf3da13bca3c976ddfae258
|
85
|
+
if Psych::VERSION.to_f >= 3.1
|
86
|
+
YAML.safe_load(f, aliases: true, filename: file) || {}
|
87
|
+
else
|
88
|
+
YAML.safe_load(f, [], [], true, file) || {}
|
89
|
+
end
|
90
|
+
end
|
82
91
|
rescue Psych::SyntaxError => e
|
83
92
|
raise Error, e.message
|
84
93
|
rescue Errno::ENOENT
|
data/lib/pgsync/table_sync.rb
CHANGED
@@ -125,7 +125,7 @@ module PgSync
|
|
125
125
|
end
|
126
126
|
|
127
127
|
# for non-deferrable constraints
|
128
|
-
if opts[:
|
128
|
+
if opts[:defer_constraints_v1]
|
129
129
|
constraints = non_deferrable_constraints(destination)
|
130
130
|
constraints = tasks.flat_map { |t| constraints[t.table] || [] }
|
131
131
|
warning "Non-deferrable constraints: #{constraints.join(", ")}" if constraints.any?
|
@@ -230,7 +230,7 @@ module PgSync
|
|
230
230
|
|
231
231
|
# disable multiple jobs for defer constraints and disable integrity
|
232
232
|
# so we can use a transaction to ensure a consistent snapshot
|
233
|
-
if opts[:debug] || opts[:in_batches] || opts[:
|
233
|
+
if opts[:debug] || opts[:in_batches] || opts[:defer_constraints_v1] || opts[:defer_constraints_v2] || opts[:disable_integrity] || opts[:disable_integrity_v2]
|
234
234
|
warning "--jobs ignored" if jobs
|
235
235
|
jobs = 0
|
236
236
|
end
|
@@ -268,7 +268,7 @@ module PgSync
|
|
268
268
|
source.transaction do
|
269
269
|
yield
|
270
270
|
end
|
271
|
-
elsif opts[:
|
271
|
+
elsif opts[:defer_constraints_v1] || opts[:defer_constraints_v2]
|
272
272
|
destination.transaction do
|
273
273
|
if opts[:defer_constraints_v2]
|
274
274
|
table_constraints = non_deferrable_constraints(destination)
|
data/lib/pgsync/task.rb
CHANGED
@@ -149,7 +149,7 @@ module PgSync
|
|
149
149
|
destination.execute("INSERT INTO #{quoted_table} (#{fields}) (SELECT #{fields} FROM #{quote_ident_full(temp_table)}) ON CONFLICT (#{on_conflict}) DO #{action}")
|
150
150
|
else
|
151
151
|
# use delete instead of truncate for foreign keys
|
152
|
-
if opts[:
|
152
|
+
if opts[:defer_constraints_v1] || opts[:defer_constraints_v2]
|
153
153
|
destination.execute("DELETE FROM #{quoted_table}")
|
154
154
|
else
|
155
155
|
destination.truncate(table)
|
@@ -256,9 +256,11 @@ module PgSync
|
|
256
256
|
when "random_time"
|
257
257
|
"NOW() - (RANDOM() * 100000000)::int * INTERVAL '1 second'"
|
258
258
|
when "random_ip"
|
259
|
+
# casting double to int rounds
|
259
260
|
"(1 + RANDOM() * 254)::int::text || '.0.0.1'"
|
260
261
|
when "random_letter"
|
261
|
-
|
262
|
+
# casting double to int rounds
|
263
|
+
"chr(65 + (RANDOM() * 25)::int)"
|
262
264
|
when "random_string"
|
263
265
|
"RIGHT(MD5(RANDOM()::text), 10)"
|
264
266
|
when "null", nil
|
data/lib/pgsync/version.rb
CHANGED
data/lib/pgsync.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.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description:
|
70
|
-
email: andrew@
|
70
|
+
email: andrew@ankane.org
|
71
71
|
executables:
|
72
72
|
- pgsync
|
73
73
|
extensions: []
|
@@ -103,14 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '2.
|
106
|
+
version: '2.5'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.3.7
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Sync Postgres data between databases
|