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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pg_easy_replicate/version.rb +1 -1
- data/lib/pg_easy_replicate.rb +30 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5298b91d476da44069b1aac55bf32b8feb4bedbb07238d3588de101884f259b5
|
4
|
+
data.tar.gz: 6d083008edd3843635b691326d103eb9ee7a1d9eeccca4c62da6c15648d426ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2789ca7abafaeab46264f5bdd1d633340c783b2a062e844d4d97e09a3b53af1023a20a66a1751caea781ce535a13f7563d9023ca98bbe1f723d95297e2462b87
|
7
|
+
data.tar.gz: a344c89598dfc0cc1980b18adb003e7e61191dcdeefd1a2dc23e399320b9ade642c46ee1317299acf24201840242a7fcfa7af0f2cf7265dc7451e22956cbb5ea
|
data/Gemfile.lock
CHANGED
data/lib/pg_easy_replicate.rb
CHANGED
@@ -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
|
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
|
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:,
|
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(
|
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(
|
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
|