pg_easy_replicate 0.1.8 → 0.1.9

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: 73d97a0f8505fef3ac73849e6964d1204c72545eb52fb4059d2c1119ea62228d
4
- data.tar.gz: 8ad93a08e70da1945e091110064a9b4be569c2a77328f9960cd7ce52c6becefa
3
+ metadata.gz: 02ca1ab51b854644e7a44fcb9a166a363b608784f4c38a6872cc6be5d35b21f3
4
+ data.tar.gz: dfb7b875e61b5c032940af84417ce7cf35b75897039ba4efd400513d7da5de20
5
5
  SHA512:
6
- metadata.gz: 895ca04cdabbf15a082b1623890d55e650398f07eb144b2a0c8cf2877557a857926e24bfc336046afdd5097dbd5042d43d344e095338d6ffdb8f259797536c10
7
- data.tar.gz: 41dd6428dd0f8c54de4d4b97931d573a0b2ae5fd4f5d61e2908d2e88e7fff0a97ed13c841a8fa2b924bacda0e8ae4c496d3f533d1398be7b15ffe0aa0ba6304a
6
+ metadata.gz: 698b38142b8f8a8c9a64623d9a3bb06791a3a5bc174c4abffc49a480787d6cf33a002b75e9e6a61c23f443c962818544ef3c98fab5970bc1bccf1224ebaa8cb6
7
+ data.tar.gz: f6942a91cade0e60c9c5e245f4cabe9a7d0e698316855c7eacbd53bc1b2769a3d465e12dc7e1cda34f10149b24b3bfde35a585ab6b8583f9645b9faae5439021
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_easy_replicate (0.1.8)
4
+ pg_easy_replicate (0.1.9)
5
5
  ougai (~> 2.0.0)
6
6
  pg (~> 1.5.3)
7
7
  sequel (>= 5.69, < 5.71)
@@ -37,7 +37,7 @@ GEM
37
37
  rake (13.0.6)
38
38
  rbs (3.1.0)
39
39
  regexp_parser (2.8.1)
40
- rexml (3.2.5)
40
+ rexml (3.2.6)
41
41
  rspec (3.12.0)
42
42
  rspec-core (~> 3.12.0)
43
43
  rspec-expectations (~> 3.12.0)
@@ -51,7 +51,7 @@ GEM
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.12.0)
53
53
  rspec-support (3.12.0)
54
- rubocop (1.54.2)
54
+ rubocop (1.55.0)
55
55
  json (~> 2.3)
56
56
  language_server-protocol (>= 3.17.0)
57
57
  parallel (~> 1.10)
@@ -59,7 +59,7 @@ GEM
59
59
  rainbow (>= 2.2.2, < 4.0)
60
60
  regexp_parser (>= 1.8, < 3.0)
61
61
  rexml (>= 3.2.5, < 4.0)
62
- rubocop-ast (>= 1.28.0, < 2.0)
62
+ rubocop-ast (>= 1.28.1, < 2.0)
63
63
  ruby-progressbar (~> 1.7)
64
64
  unicode-display_width (>= 2.4.0, < 3.0)
65
65
  rubocop-ast (1.29.0)
@@ -75,7 +75,7 @@ GEM
75
75
  rubocop-ast (>= 0.4.0)
76
76
  rubocop-rake (0.6.0)
77
77
  rubocop (~> 1.0)
78
- rubocop-rspec (2.22.0)
78
+ rubocop-rspec (2.23.0)
79
79
  rubocop (~> 1.33)
80
80
  rubocop-capybara (~> 2.17)
81
81
  rubocop-factory_bot (~> 2.22)
data/docker-compose.yml CHANGED
@@ -5,8 +5,8 @@ services:
5
5
  ports:
6
6
  - "5432:5432"
7
7
  environment:
8
- POSTGRES_USER: jamesbond
9
- POSTGRES_PASSWORD: jamesbond123@7!'3aaR
8
+ POSTGRES_USER: james-bond
9
+ POSTGRES_PASSWORD: james-bond123@7!'3aaR
10
10
  POSTGRES_DB: postgres
11
11
  command: >
12
12
  -c wal_level=logical
@@ -21,8 +21,8 @@ services:
21
21
  ports:
22
22
  - "5433:5432"
23
23
  environment:
24
- POSTGRES_USER: jamesbond
25
- POSTGRES_PASSWORD: jamesbond123@7!'3aaR
24
+ POSTGRES_USER: james-bond
25
+ POSTGRES_PASSWORD: james-bond123@7!'3aaR
26
26
  POSTGRES_DB: postgres
27
27
  command: >
28
28
  -c wal_level=logical
@@ -43,6 +43,10 @@ module PgEasyReplicate
43
43
  .downcase
44
44
  end
45
45
 
46
+ def quote_ident(sql_ident)
47
+ PG::Connection.quote_ident(sql_ident)
48
+ end
49
+
46
50
  def test_env?
47
51
  ENV.fetch("RACK_ENV", nil) == "test"
48
52
  end
@@ -94,7 +94,8 @@ module PgEasyReplicate
94
94
  .map do |table_name|
95
95
  Query.run(
96
96
  query:
97
- "ALTER PUBLICATION #{publication_name(group_name)} ADD TABLE \"#{table_name}\"",
97
+ "ALTER PUBLICATION #{quote_ident(publication_name(group_name))}
98
+ ADD TABLE #{quote_ident(table_name)}",
98
99
  connection_url: conn_string,
99
100
  schema: schema,
100
101
  )
@@ -107,7 +108,11 @@ module PgEasyReplicate
107
108
  Query
108
109
  .run(
109
110
  query:
110
- "SELECT table_name FROM information_schema.tables WHERE table_schema = '#{schema}' ORDER BY table_name",
111
+ "SELECT table_name
112
+ FROM information_schema.tables
113
+ WHERE table_schema = '#{schema}' AND
114
+ table_type = 'BASE TABLE'
115
+ ORDER BY table_name",
111
116
  connection_url: conn_string,
112
117
  )
113
118
  .map(&:values)
@@ -121,7 +126,8 @@ module PgEasyReplicate
121
126
  { publication_name: publication_name(group_name) },
122
127
  )
123
128
  Query.run(
124
- query: "DROP PUBLICATION IF EXISTS #{publication_name(group_name)}",
129
+ query:
130
+ "DROP PUBLICATION IF EXISTS #{quote_ident(publication_name(group_name))}",
125
131
  connection_url: conn_string,
126
132
  user: db_user(conn_string),
127
133
  )
@@ -144,7 +150,9 @@ module PgEasyReplicate
144
150
 
145
151
  Query.run(
146
152
  query:
147
- "CREATE SUBSCRIPTION #{subscription_name(group_name)} CONNECTION '#{source_conn_string}' PUBLICATION #{publication_name(group_name)}",
153
+ "CREATE SUBSCRIPTION #{quote_ident(subscription_name(group_name))}
154
+ CONNECTION '#{source_conn_string}'
155
+ PUBLICATION #{quote_ident(publication_name(group_name))}",
148
156
  connection_url: target_conn_string,
149
157
  user: db_user(target_conn_string),
150
158
  transaction: false,
@@ -282,7 +290,7 @@ module PgEasyReplicate
282
290
  )
283
291
 
284
292
  alter_sql =
285
- "ALTER USER #{db_user(source_db_url)} set default_transaction_read_only = true"
293
+ "ALTER USER #{quote_ident(db_user(source_db_url))} set default_transaction_read_only = true"
286
294
  Query.run(query: alter_sql, connection_url: source_db_url)
287
295
 
288
296
  kill_sql =
@@ -297,7 +305,7 @@ module PgEasyReplicate
297
305
  logger.info("Restoring connections")
298
306
 
299
307
  alter_sql =
300
- "ALTER USER #{db_user(source_db_url)} set default_transaction_read_only = false"
308
+ "ALTER USER #{quote_ident(db_user(source_db_url))} set default_transaction_read_only = false"
301
309
  Query.run(query: alter_sql, connection_url: source_db_url)
302
310
  end
303
311
 
@@ -17,12 +17,12 @@ module PgEasyReplicate
17
17
  if transaction
18
18
  r =
19
19
  conn.transaction do
20
- conn.run("SET search_path to #{schema}") if schema
20
+ conn.run("SET search_path to #{quote_ident(schema)}") if schema
21
21
  conn.run("SET statement_timeout to '5s'")
22
22
  conn.fetch(query).to_a
23
23
  end
24
24
  else
25
- conn.run("SET search_path to #{schema}") if schema
25
+ conn.run("SET search_path to #{quote_ident(schema)}") if schema
26
26
  conn.run("SET statement_timeout to '5s'")
27
27
  r = conn.fetch(query).to_a
28
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEasyReplicate
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
@@ -5,6 +5,7 @@ require "ougai"
5
5
  require "pg"
6
6
  require "sequel"
7
7
  require "open3"
8
+ require "English"
8
9
 
9
10
  require "pg_easy_replicate/helper"
10
11
  require "pg_easy_replicate/version"
@@ -152,7 +153,8 @@ module PgEasyReplicate
152
153
 
153
154
  def drop_internal_schema
154
155
  Query.run(
155
- query: "DROP SCHEMA IF EXISTS #{internal_schema_name} CASCADE",
156
+ query:
157
+ "DROP SCHEMA IF EXISTS #{quote_ident(internal_schema_name)} CASCADE",
156
158
  connection_url: source_db_url,
157
159
  schema: internal_schema_name,
158
160
  user: db_user(target_db_url),
@@ -163,9 +165,9 @@ module PgEasyReplicate
163
165
 
164
166
  def setup_internal_schema
165
167
  sql = <<~SQL
166
- create schema if not exists #{internal_schema_name};
167
- grant usage on schema #{internal_schema_name} to #{db_user(source_db_url)};
168
- grant create on schema #{internal_schema_name} to #{db_user(source_db_url)};
168
+ create schema if not exists #{quote_ident(internal_schema_name)};
169
+ grant usage on schema #{quote_ident(internal_schema_name)} to #{quote_ident(db_user(source_db_url))};
170
+ grant create on schema #{quote_ident(internal_schema_name)} to #{quote_ident(db_user(source_db_url))};
169
171
  SQL
170
172
 
171
173
  Query.run(
@@ -273,9 +275,9 @@ module PgEasyReplicate
273
275
  password = connection_info(conn_string)[:password].gsub("'") { "''" }
274
276
 
275
277
  sql = <<~SQL
276
- drop role if exists #{internal_user_name};
277
- create role #{internal_user_name} with password '#{password}' login createdb createrole;
278
- grant all privileges on database #{db_name(conn_string)} TO #{internal_user_name};
278
+ drop role if exists #{quote_ident(internal_user_name)};
279
+ create role #{quote_ident(internal_user_name)} with password '#{password}' login createdb createrole;
280
+ grant all privileges on database #{quote_ident(db_name(conn_string))} TO #{quote_ident(internal_user_name)};
279
281
  SQL
280
282
 
281
283
  Query.run(
@@ -287,9 +289,9 @@ module PgEasyReplicate
287
289
 
288
290
  sql =
289
291
  if special_user_role
290
- "grant #{special_user_role} to #{internal_user_name};"
292
+ "grant #{quote_ident(special_user_role)} to #{quote_ident(internal_user_name)};"
291
293
  else
292
- "alter user #{internal_user_name} with superuser;"
294
+ "alter user #{quote_ident(internal_user_name)} with superuser;"
293
295
  end
294
296
 
295
297
  Query.run(
@@ -302,7 +304,7 @@ module PgEasyReplicate
302
304
  return unless grant_permissions_on_schema
303
305
  Query.run(
304
306
  query:
305
- "grant all on schema #{internal_schema_name} to #{internal_user_name}",
307
+ "grant all on schema #{quote_ident(internal_schema_name)} to #{quote_ident(internal_user_name)}",
306
308
  connection_url: conn_string,
307
309
  user: db_user(conn_string),
308
310
  transaction: false,
@@ -313,7 +315,7 @@ module PgEasyReplicate
313
315
 
314
316
  def drop_user(conn_string:, group_name:)
315
317
  sql = <<~SQL
316
- revoke all privileges on database #{db_name(conn_string)} from #{internal_user_name};
318
+ revoke all privileges on database #{db_name(conn_string)} from #{quote_ident(internal_user_name)};
317
319
  SQL
318
320
  Query.run(
319
321
  query: sql,
@@ -322,7 +324,7 @@ module PgEasyReplicate
322
324
  )
323
325
 
324
326
  sql = <<~SQL
325
- drop role if exists #{internal_user_name};
327
+ drop role if exists #{quote_ident(internal_user_name)};
326
328
  SQL
327
329
 
328
330
  Query.run(
@@ -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://jamesbond:jamesbond123%407%21%273aaR@source_db/postgres"
6
+ export SECONDARY_SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@source_db/postgres"
7
7
  fi
8
8
 
9
- export SOURCE_DB_URL="postgres://jamesbond:jamesbond123%407%21%273aaR@localhost:5432/postgres"
10
- export TARGET_DB_URL="postgres://jamesbond:jamesbond123%407%21%273aaR@localhost:5433/postgres"
11
- export PGPASSWORD='jamesbond123@7!'"'"'3aaR'
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"
11
+ export PGPASSWORD='james-bond123@7!'"'"'3aaR'
12
12
 
13
- pgbench --initialize -s 5 --foreign-keys --host localhost -U jamesbond -d postgres
13
+ pgbench --initialize -s 5 --foreign-keys --host localhost -U james-bond -d postgres
14
14
 
15
15
  bundle exec bin/pg_easy_replicate config_check --copy-schema
data/scripts/e2e-start.sh CHANGED
@@ -3,12 +3,12 @@
3
3
  set -eo pipefail
4
4
 
5
5
  if [[ -z ${GITHUB_WORKFLOW} ]]; then
6
- export SECONDARY_SOURCE_DB_URL="postgres://jamesbond:jamesbond123%407%21%273aaR@source_db/postgres"
6
+ export SECONDARY_SOURCE_DB_URL="postgres://james-bond:james-bond123%407%21%273aaR@source_db/postgres"
7
7
  fi
8
8
 
9
- export SOURCE_DB_URL="postgres://jamesbond:jamesbond123%407%21%273aaR@localhost:5432/postgres"
10
- export TARGET_DB_URL="postgres://jamesbond:jamesbond123%407%21%273aaR@localhost:5433/postgres"
11
- export PGPASSWORD='jamesbond123@7!'"'"''"'"'3aaR'
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"
11
+ export PGPASSWORD='james-bond123@7!'"'"''"'"'3aaR'
12
12
 
13
13
  # Bootstrap and cleanup
14
14
  echo "===== Performing 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.8
4
+ version: 0.1.9
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-07-23 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai