pg_online_schema_change 0.7.2 → 0.7.4

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: d9b2ebcfd1944ac2ddba65466ca474751637d6fdb2db7abcf3a5d587e716c617
4
- data.tar.gz: 3a6ac8b49967e9483f75359006097865de640c3ce414dad5bd0e07e766d4a3c3
3
+ metadata.gz: 2a765e9fe8c466b43b05b45401a6f0bbfc1d6ec3825dbc030308e1c7701ee436
4
+ data.tar.gz: 5cb07a199e35f6fe1ad2dfb3cad11dded9f6e4b519af2d67a08fad850fdd715d
5
5
  SHA512:
6
- metadata.gz: a0a7d0bf9bf030859d6b7cb36b1d69770d3af9c7721c5e5042732887959bc1664e1c8bd4f09f076cdafcb1b272a57f49ddf1fbb5d86aad60a4b0b81d79378804
7
- data.tar.gz: bb12999f436c8d93591c17b97f5f508d7234355ef25780834565a8222da4c43dd3dfd52450210007bc3f0a32cd0231958a3e7645af538d1af67cc3e620582f14
6
+ metadata.gz: a39814cfedba956f26f083a5fbbeeeced80818b6273656761e146d244e245627033ffbf48c5b69dc1a5bb4d5c9e3c9e01f10ec9ddbf95a7da9b8e36af60ada6d
7
+ data.tar.gz: 87e06bd100570d1a18e11ec279894a7a417713237ee4134bace9fc5f62acbffd35d31e668b3b88c5031841d816a9eb8fe30faa546baae5e3027f432bb6567ecc
data/.rubocop.yml CHANGED
@@ -24,7 +24,7 @@ Layout/SpaceAroundEqualsInParameterDefault:
24
24
 
25
25
  Metrics/AbcSize:
26
26
  Enabled: true
27
- Max: 40
27
+ Max: 45
28
28
  Exclude:
29
29
  - "spec/**/*"
30
30
 
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-03-13 19:35:49 UTC using RuboCop version 1.23.0.
3
+ # on 2022-09-24 14:22:44 UTC using RuboCop version 1.23.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -9,7 +9,7 @@
9
9
  # Offense count: 2
10
10
  # Configuration parameters: CountComments, CountAsOne.
11
11
  Metrics/ClassLength:
12
- Max: 250
12
+ Max: 266
13
13
 
14
14
  # Offense count: 2
15
15
  # Configuration parameters: IgnoredMethods.
@@ -26,7 +26,7 @@ Packaging/GemspecGit:
26
26
  Exclude:
27
27
  - 'pg_online_schema_change.gemspec'
28
28
 
29
- # Offense count: 67
29
+ # Offense count: 68
30
30
  # Configuration parameters: CountAsOne.
31
31
  RSpec/ExampleLength:
32
32
  Max: 55
data/CHANGELOG.md CHANGED
@@ -1,4 +1,14 @@
1
1
 
2
+ ## [0.7.3] - 2022-09-24
3
+ * Update primary key sequence on shadow table https://github.com/shayonj/pg-osc/pull/72
4
+ - Thanks to @brycethornton for the report
5
+ * Only refresh primary key when a sequence is attached https://github.com/shayonj/pg-osc/pull/73
6
+
7
+ ## [0.7.2] - 2022-09-17
8
+ **NOTE: Skip to 0.7.3. 0.7.2 release missed the change.**
9
+ * Update primary key sequence on shadow table https://github.com/shayonj/pg-osc/pull/72
10
+ - Thanks to @brycethornton for the report
11
+
2
12
  ## [0.7.1] - 2022-03-13
3
13
  * Bump pg to `1.3.4` https://github.com/shayonj/pg-osc/commit/d086c19d4f273dc960491cbedf9e0602d812896b
4
14
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_online_schema_change (0.7.2)
4
+ pg_online_schema_change (0.7.4)
5
5
  ougai (~> 2.0.0)
6
6
  pg (~> 1.3.2)
7
7
  pg_query (~> 2.1.3)
@@ -13,37 +13,37 @@ GEM
13
13
  ast (2.4.2)
14
14
  coderay (1.1.3)
15
15
  diff-lcs (1.5.0)
16
- google-protobuf (3.19.4)
16
+ google-protobuf (3.21.6)
17
17
  method_source (1.0.0)
18
- oj (3.13.11)
18
+ oj (3.13.21)
19
19
  ougai (2.0.0)
20
20
  oj (~> 3.10)
21
- parallel (1.21.0)
22
- parser (3.0.3.2)
21
+ parallel (1.22.1)
22
+ parser (3.1.2.1)
23
23
  ast (~> 2.4.1)
24
- pg (1.3.4)
25
- pg_query (2.1.3)
24
+ pg (1.3.5)
25
+ pg_query (2.1.4)
26
26
  google-protobuf (>= 3.19.2)
27
27
  pry (0.14.1)
28
28
  coderay (~> 1.1)
29
29
  method_source (~> 1.0)
30
- rainbow (3.0.0)
30
+ rainbow (3.1.1)
31
31
  rake (13.0.6)
32
- regexp_parser (2.2.0)
32
+ regexp_parser (2.5.0)
33
33
  rexml (3.2.5)
34
- rspec (3.10.0)
35
- rspec-core (~> 3.10.0)
36
- rspec-expectations (~> 3.10.0)
37
- rspec-mocks (~> 3.10.0)
38
- rspec-core (3.10.1)
39
- rspec-support (~> 3.10.0)
40
- rspec-expectations (3.10.1)
34
+ rspec (3.11.0)
35
+ rspec-core (~> 3.11.0)
36
+ rspec-expectations (~> 3.11.0)
37
+ rspec-mocks (~> 3.11.0)
38
+ rspec-core (3.11.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-expectations (3.11.1)
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.10.0)
43
- rspec-mocks (3.10.2)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-mocks (3.11.1)
44
44
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.10.0)
46
- rspec-support (3.10.3)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-support (3.11.1)
47
47
  rubocop (1.23.0)
48
48
  parallel (~> 1.10)
49
49
  parser (>= 3.0.0.0)
@@ -53,8 +53,8 @@ GEM
53
53
  rubocop-ast (>= 1.12.0, < 2.0)
54
54
  ruby-progressbar (~> 1.7)
55
55
  unicode-display_width (>= 1.4.0, < 3.0)
56
- rubocop-ast (1.15.1)
57
- parser (>= 3.0.1.1)
56
+ rubocop-ast (1.21.0)
57
+ parser (>= 3.1.1.0)
58
58
  rubocop-packaging (0.5.1)
59
59
  rubocop (>= 0.89, < 2.0)
60
60
  rubocop-performance (1.12.0)
@@ -66,7 +66,7 @@ GEM
66
66
  rubocop (~> 1.19)
67
67
  ruby-progressbar (1.11.0)
68
68
  thor (1.2.1)
69
- unicode-display_width (2.1.0)
69
+ unicode-display_width (2.3.0)
70
70
 
71
71
  PLATFORMS
72
72
  arm64-darwin-20
data/README.md CHANGED
@@ -260,6 +260,16 @@ rvm use 3.0.0
260
260
 
261
261
  To install this gem onto your local machine, run `bundle exec rake install`.
262
262
 
263
+ ### Local testing
264
+ ```
265
+ docker compose up
266
+
267
+ pgbench --initialize -s 10 --foreign-keys --host localhost -U jamesbond -d postgres
268
+ pgbench -T 60000 -c 5 --host localhost -U jamesbond -d postgres
269
+
270
+ bundle exec bin/pg-online-schema-change perform -a 'ALTER TABLE pgbench_accounts ALTER COLUMN aid TYPE BIGINT' -d "postgres" -h "localhost" -u "jamesbond" -w "password"
271
+ ```
272
+
263
273
  ## Releasing
264
274
 
265
275
  - Bump version in `version.rb`
@@ -238,7 +238,10 @@ module PgOnlineSchemaChange
238
238
  rows = Replay.rows_to_play(opened)
239
239
  Replay.play!(rows, opened)
240
240
 
241
+ query_for_primary_key_refresh = Query.query_for_primary_key_refresh(shadow_table, primary_key, client.table, opened)
242
+
241
243
  sql = <<~SQL
244
+ #{query_for_primary_key_refresh};
242
245
  ALTER TABLE #{client.table} RENAME to #{old_primary_table};
243
246
  ALTER TABLE #{shadow_table} RENAME to #{client.table};
244
247
  #{referential_foreign_key_statements}
@@ -319,6 +319,28 @@ module PgOnlineSchemaChange
319
319
  FROM ONLY #{client.table}
320
320
  SQL
321
321
  end
322
+
323
+ def primary_key_sequence(shadow_table, primary_key, opened)
324
+ query = <<~SQL
325
+ SELECT pg_get_serial_sequence(\'#{shadow_table}\', \'#{primary_key}\') as sequence_name
326
+ SQL
327
+
328
+ result = run(client.connection, query, opened)
329
+
330
+ result.map do |row|
331
+ row["sequence_name"]
332
+ end&.first
333
+ end
334
+
335
+ def query_for_primary_key_refresh(shadow_table, primary_key, table, opened)
336
+ sequence_name = primary_key_sequence(shadow_table, primary_key, opened)
337
+
338
+ return "" if sequence_name.nil?
339
+
340
+ <<~SQL
341
+ SELECT setval((select pg_get_serial_sequence(\'#{shadow_table}\', \'#{primary_key}\')), (SELECT max(#{primary_key}) FROM #{table}));
342
+ SQL
343
+ end
322
344
  end
323
345
  end
324
346
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgOnlineSchemaChange
4
- VERSION = "0.7.2"
4
+ VERSION = "0.7.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_online_schema_change
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shayon Mukherjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-17 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai