pgsync 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pgsync might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c4a582f7fd5b997ba91247f2b57ad68aae7b5fad282c32dca873d75667922af
4
- data.tar.gz: a7ae6518b84d28c8ad14786793b8d4257d898214b8071ccc6c91e9d4d144e316
3
+ metadata.gz: 531d7975b4942abc5670b8c4ad43717da1326eacacc3b95f5d5797236cb82bb3
4
+ data.tar.gz: e32dfb82469fa2ebeeea844f0a09e87b8068bd7a201111b90d374eef779381af
5
5
  SHA512:
6
- metadata.gz: f008b6d7114e3f11395479de0e85006c5eb48681b13ab613e1468d20a99acf0121566fe5499e236d1e8b07fdd12acc2c3a99399daac3e3e99269efac5e6bd4e5
7
- data.tar.gz: 536af357b17f35c7afb0e8efba5411a0ecbec67adbfe364d465a8831dd0e56d108055b1ccb55bc0203d92d9a3215a11d3a287f52e89b40b6526534ddfbc8371e
6
+ metadata.gz: 4a33a680baaf706ad25fed35eaee3a8c3b191c7a5f6600b4ada42e55143a12226b0e1be189cf4c29d4866982e4f8c7b4915c4517375913083f3210f5fb131598
7
+ data.tar.gz: a3825c52c5e96c869ea06ed0ec969e1835aec5614f8bd1eb9255995972bdb3e526dd2996802e4d467b1497cfe371509b8a973cc8e3b61988d55f7fb0824d5293
@@ -1,3 +1,8 @@
1
+ ## 0.6.2 (2020-06-09)
2
+
3
+ - Added support for `--disable-integrity` on Amazon RDS
4
+ - Fixed error when excluded table not found in source
5
+
1
6
  ## 0.6.1 (2020-06-07)
2
7
 
3
8
  - Added Django and Laravel integrations
data/README.md CHANGED
@@ -220,6 +220,8 @@ To disable foreign key triggers and potentially break referential integrity, use
220
220
  pgsync --disable-integrity
221
221
  ```
222
222
 
223
+ This requires superuser privileges on the `to` database. If syncing to (not from) Amazon RDS, use the `rds_superuser` role. If syncing to (not from) Heroku, there doesn’t appear to be a way to disable integrity.
224
+
223
225
  ## Triggers
224
226
 
225
227
  Disable user triggers with:
@@ -70,6 +70,8 @@ Options:}
70
70
  o.boolean "--defer-constraints", "defer constraints", default: false
71
71
  o.boolean "--disable-user-triggers", "disable non-system triggers", default: false
72
72
  o.boolean "--disable-integrity", "disable foreign key triggers", default: false
73
+ # private, for testing
74
+ o.boolean "--disable-integrity-v2", "disable foreign key triggers", default: false, help: false
73
75
  o.boolean "-v", "--version", "print the version"
74
76
  o.boolean "-h", "--help", "prints help"
75
77
  o
@@ -62,7 +62,7 @@ module PgSync
62
62
  end
63
63
 
64
64
  def django?
65
- (File.read("manage.py") =~ /django/i) rescue false
65
+ file_exists?("manage.py", /django/i)
66
66
  end
67
67
 
68
68
  def heroku?
@@ -70,11 +70,21 @@ module PgSync
70
70
  end
71
71
 
72
72
  def laravel?
73
- File.exist?("artisan")
73
+ file_exists?("artisan")
74
74
  end
75
75
 
76
76
  def rails?
77
- File.exist?("bin/rails")
77
+ file_exists?("bin/rails")
78
+ end
79
+
80
+ def file_exists?(path, contents = nil)
81
+ if contents
82
+ File.read(path).match(contents)
83
+ else
84
+ File.exist?(path)
85
+ end
86
+ rescue
87
+ false
78
88
  end
79
89
  end
80
90
  end
@@ -275,7 +275,7 @@ module PgSync
275
275
  end
276
276
 
277
277
  def maybe_disable_triggers
278
- if opts[:disable_integrity] || opts[:disable_user_triggers]
278
+ if opts[:disable_integrity] || opts[:disable_integrity_v2] || opts[:disable_user_triggers]
279
279
  destination.transaction do
280
280
  triggers = destination.triggers(table)
281
281
  triggers.select! { |t| t["enabled"] == "t" }
@@ -283,7 +283,17 @@ module PgSync
283
283
  integrity_triggers = internal_triggers.select { |t| t["integrity"] == "t" }
284
284
  restore_triggers = []
285
285
 
286
- if opts[:disable_integrity]
286
+ # both --disable-integrity options require superuser privileges
287
+ # however, only v2 works on Amazon RDS, which added specific support for it
288
+ # https://aws.amazon.com/about-aws/whats-new/2014/11/10/amazon-rds-postgresql-read-replicas/
289
+ #
290
+ # session_replication_role disables more than foreign keys (like triggers and rules)
291
+ # this is probably fine, but keep the current default for now
292
+ if opts[:disable_integrity_v2] || (opts[:disable_integrity] && rds?)
293
+ # SET LOCAL lasts until the end of the transaction
294
+ # https://www.postgresql.org/docs/current/sql-set.html
295
+ destination.execute("SET LOCAL session_replication_role = replica")
296
+ elsif opts[:disable_integrity]
287
297
  integrity_triggers.each do |trigger|
288
298
  destination.execute("ALTER TABLE #{quoted_table} DISABLE TRIGGER #{quote_ident(trigger["name"])}")
289
299
  end
@@ -311,5 +321,9 @@ module PgSync
311
321
  yield
312
322
  end
313
323
  end
324
+
325
+ def rds?
326
+ destination.execute("SELECT name, setting FROM pg_settings WHERE name LIKE 'rds.%'").any?
327
+ end
314
328
  end
315
329
  end
@@ -148,7 +148,7 @@ module PgSync
148
148
  regex = Regexp.new('\A' + Regexp.escape(value).gsub('\*','[^\.]*') + '\z')
149
149
  tables.reject! { |t| regex.match(t.full_name) || regex.match(t.name) }
150
150
  else
151
- tables -= [fully_resolve(to_table(value))]
151
+ tables -= [fully_resolve(to_table(value), error: false)].compact
152
152
  end
153
153
  end
154
154
 
@@ -181,9 +181,11 @@ module PgSync
181
181
  end
182
182
 
183
183
  # for tables without a schema, find the table in the search path
184
- def fully_resolve(table)
184
+ def fully_resolve(table, error: true)
185
185
  return table if table.schema
186
- no_schema_tables[table.name] || (raise Error, "Table not found in source: #{table.name}")
186
+ resolved_table = no_schema_tables[table.name]
187
+ raise Error, "Table not found in source: #{table.name}" if !resolved_table && error
188
+ resolved_table
187
189
  end
188
190
 
189
191
  # parse command line arguments and YAML
@@ -1,3 +1,3 @@
1
1
  module PgSync
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.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.6.1
4
+ version: 0.6.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: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel