pg_easy_replicate 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d45fb127cf497feec36832e91ca67a54878d9fcf783cab3059aad366b0e99026
4
- data.tar.gz: 989e3900bebfb04cb9af6037bf849da4f2ea9c6da9a9c6899d64a193ab507b93
3
+ metadata.gz: 5298b91d476da44069b1aac55bf32b8feb4bedbb07238d3588de101884f259b5
4
+ data.tar.gz: 6d083008edd3843635b691326d103eb9ee7a1d9eeccca4c62da6c15648d426ec
5
5
  SHA512:
6
- metadata.gz: a5e5a55884a847b5bcfbaee5252704a60e2969c7dba7813fd35e875b2e381c65a7be5088c3042d4473acde9205b0423c59d22e0c9792178c9fd2e49e86b4ef4d
7
- data.tar.gz: 17af5a3e97dc562970e3f84f1aa2eb4878159cf5bf8f4d1d7cccd3948ded00c7f2c2f003024281409e07a2d9e19bee1eab8aa7c9a5959eb7ebdc8d9c1da75f33
6
+ metadata.gz: 2789ca7abafaeab46264f5bdd1d633340c783b2a062e844d4d97e09a3b53af1023a20a66a1751caea781ce535a13f7563d9023ca98bbe1f723d95297e2462b87
7
+ data.tar.gz: a344c89598dfc0cc1980b18adb003e7e61191dcdeefd1a2dc23e399320b9ade642c46ee1317299acf24201840242a7fcfa7af0f2cf7265dc7451e22956cbb5ea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_easy_replicate (0.1.10)
4
+ pg_easy_replicate (0.1.11)
5
5
  ougai (~> 2.0.0)
6
6
  pg (~> 1.5.3)
7
7
  sequel (>= 5.69, < 5.76)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEasyReplicate
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.11"
5
5
  end
@@ -140,10 +140,10 @@ module PgEasyReplicate
140
140
  if options[:everything]
141
141
  # Drop users at last
142
142
  logger.info("Dropping replication user on source database")
143
- drop_user(conn_string: source_db_url, group_name: options[:group_name])
143
+ drop_user(conn_string: source_db_url)
144
144
 
145
145
  logger.info("Dropping replication user on target database")
146
- drop_user(conn_string: target_db_url, group_name: options[:group_name])
146
+ drop_user(conn_string: target_db_url)
147
147
  end
148
148
  rescue => e
149
149
  abort_with("Unable to cleanup: #{e.message}")
@@ -266,8 +266,9 @@ module PgEasyReplicate
266
266
  )
267
267
  password = connection_info(conn_string)[:password].gsub("'") { "''" }
268
268
 
269
+ drop_user(conn_string: conn_string)
270
+
269
271
  sql = <<~SQL
270
- drop role if exists #{quote_ident(internal_user_name)};
271
272
  create role #{quote_ident(internal_user_name)} with password '#{password}' login createdb createrole;
272
273
  grant all privileges on database #{quote_ident(db_name(conn_string))} TO #{quote_ident(internal_user_name)};
273
274
  SQL
@@ -305,10 +306,13 @@ module PgEasyReplicate
305
306
  raise "Unable to create user: #{e.message}"
306
307
  end
307
308
 
308
- def drop_user(conn_string:, group_name:)
309
+ def drop_user(conn_string:, user: internal_user_name)
310
+ return unless user_exists?(conn_string: conn_string, user: user)
311
+
309
312
  sql = <<~SQL
310
- revoke all privileges on database #{db_name(conn_string)} from #{quote_ident(internal_user_name)};
313
+ revoke all privileges on database #{db_name(conn_string)} from #{quote_ident(user)};
311
314
  SQL
315
+
312
316
  Query.run(
313
317
  query: sql,
314
318
  connection_url: conn_string,
@@ -316,7 +320,7 @@ module PgEasyReplicate
316
320
  )
317
321
 
318
322
  sql = <<~SQL
319
- drop role if exists #{quote_ident(internal_user_name)};
323
+ drop role if exists #{quote_ident(user)};
320
324
  SQL
321
325
 
322
326
  Query.run(
@@ -327,5 +331,25 @@ module PgEasyReplicate
327
331
  rescue => e
328
332
  raise "Unable to drop user: #{e.message}"
329
333
  end
334
+
335
+ def user_exists?(conn_string:, user: internal_user_name)
336
+ sql = <<~SQL
337
+ SELECT r.rolname AS username,
338
+ r1.rolname AS "role"
339
+ FROM pg_catalog.pg_roles r
340
+ LEFT JOIN pg_catalog.pg_auth_members m ON (m.member = r.oid)
341
+ LEFT JOIN pg_roles r1 ON (m.roleid=r1.oid)
342
+ WHERE r.rolname = '#{user}'
343
+ ORDER BY 1;
344
+ SQL
345
+
346
+ Query
347
+ .run(
348
+ query: sql,
349
+ connection_url: conn_string,
350
+ user: db_user(conn_string),
351
+ )
352
+ .any? { |q| q[:username] == user }
353
+ end
330
354
  end
331
355
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_easy_replicate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shayon Mukherjee