pg_easy_replicate 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d45fb127cf497feec36832e91ca67a54878d9fcf783cab3059aad366b0e99026
4
- data.tar.gz: 989e3900bebfb04cb9af6037bf849da4f2ea9c6da9a9c6899d64a193ab507b93
3
+ metadata.gz: 6d7321dd7ea830328c42f49d3e12c14df7f2b7d9cf1448fd61a46b2236847239
4
+ data.tar.gz: d3aad658eab7c86766c4528c89bcd8718376504d97ca7d1cb356f7b7faa116d2
5
5
  SHA512:
6
- metadata.gz: a5e5a55884a847b5bcfbaee5252704a60e2969c7dba7813fd35e875b2e381c65a7be5088c3042d4473acde9205b0423c59d22e0c9792178c9fd2e49e86b4ef4d
7
- data.tar.gz: 17af5a3e97dc562970e3f84f1aa2eb4878159cf5bf8f4d1d7cccd3948ded00c7f2c2f003024281409e07a2d9e19bee1eab8aa7c9a5959eb7ebdc8d9c1da75f33
6
+ metadata.gz: 7cd29a4307b130f291007dec2f9a9e5abb5227cd892349181391fce74d9c032dc9c823e44e90ba07959d3630c191f16968d6442689849199e7f98268dc5e0244
7
+ data.tar.gz: efff8b0ea2b1c9890a70306e83d75c6e35fa78645658d914c92a8142842834fd731cd2b707ab150e4ef043f7d3e85291eaa320b14db56a8f0867b8db94824b67
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.12)
5
5
  ougai (~> 2.0.0)
6
6
  pg (~> 1.5.3)
7
7
  sequel (>= 5.69, < 5.76)
@@ -76,8 +76,8 @@ GEM
76
76
  rubocop-ast (>= 0.4.0)
77
77
  rubocop-rake (0.6.0)
78
78
  rubocop (~> 1.0)
79
- rubocop-rspec (2.24.1)
80
- rubocop (~> 1.33)
79
+ rubocop-rspec (2.25.0)
80
+ rubocop (~> 1.40)
81
81
  rubocop-capybara (~> 2.17)
82
82
  rubocop-factory_bot (~> 2.22)
83
83
  ruby-progressbar (1.13.0)
data/docker-compose.yml CHANGED
@@ -7,7 +7,7 @@ services:
7
7
  environment:
8
8
  POSTGRES_USER: james-bond
9
9
  POSTGRES_PASSWORD: james-bond123@7!'3aaR
10
- POSTGRES_DB: postgres
10
+ POSTGRES_DB: postgres-db
11
11
  command: >
12
12
  -c wal_level=logical
13
13
  -c ssl=on
@@ -23,7 +23,7 @@ services:
23
23
  environment:
24
24
  POSTGRES_USER: james-bond
25
25
  POSTGRES_PASSWORD: james-bond123@7!'3aaR
26
- POSTGRES_DB: postgres
26
+ POSTGRES_DB: postgres-db
27
27
  command: >
28
28
  -c wal_level=logical
29
29
  -c ssl=on
@@ -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.12"
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 #{quote_ident(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
@@ -3,13 +3,13 @@
3
3
  set -eo pipefail
4
4
 
5
5
  if [[ -z ${GITHUB_WORKFLOW} ]]; then
6
- export SECONDARY_SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@source_db/postgres"
6
+ export SECONDARY_SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@source_db/postgres-db"
7
7
  fi
8
8
 
9
- export SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5432/postgres"
10
- export TARGET_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres"
9
+ export SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5432/postgres-db"
10
+ export TARGET_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres-db"
11
11
  export PGPASSWORD='james-bond123@7!'"'"'3aaR'
12
12
 
13
- pgbench --initialize -s 5 --foreign-keys --host localhost -U james-bond -d postgres
13
+ pgbench --initialize -s 5 --foreign-keys --host localhost -U james-bond -d postgres-db
14
14
 
15
15
  bundle exec bin/pg_easy_replicate config_check --copy-schema
data/scripts/e2e-start.sh CHANGED
@@ -3,11 +3,11 @@
3
3
  set -eo pipefail
4
4
 
5
5
  if [[ -z ${GITHUB_WORKFLOW} ]]; then
6
- export SECONDARY_SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@source_db/postgres"
6
+ export SECONDARY_SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@source_db/postgres-db"
7
7
  fi
8
8
 
9
- export SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5432/postgres"
10
- export TARGET_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres"
9
+ export SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5432/postgres-db"
10
+ export TARGET_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@localhost:5433/postgres-db"
11
11
  export PGPASSWORD='james-bond123@7!'"'"''"'"'3aaR'
12
12
 
13
13
  # Bootstrap and cleanup
metadata CHANGED
@@ -1,14 +1,14 @@
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.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shayon Mukherjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-13 00:00:00.000000000 Z
11
+ date: 2023-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai