pg_online_schema_change 0.9.1 → 0.9.3

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: c13a6a65723fdd06f0de41359026198f3ea60907b7bf839c1d61e9eb9bbceb42
4
- data.tar.gz: 6259bbb428ffe9a824da3d68289502322db71a26c394c87d1fa37483cb142666
3
+ metadata.gz: d6adb7f29ff0c9da8f24fbf500607c09ade1dc317cfdf7b9f47adaea67b248e8
4
+ data.tar.gz: 12505a58953eab715727bc0aace93627ada9219b400e3d39136876eb2e61c4f6
5
5
  SHA512:
6
- metadata.gz: 367222a59e33bac35dd4778658d23c5acfbb68585fceb439d986f7846123bec295c2d831441891d0e59b1d3ee2feb438f6fc694fe4f498b02696d39492227079
7
- data.tar.gz: 13baa1524266424fba9f25db9b308af2c3cb2c24e21f55fec7fb601e2915382f703430130fe8338534a3ce7a20dfe19334e04465877b4db6c76c6386baa54124
6
+ metadata.gz: '085f9daeb48c1a4ca457b83c6b83a0c18ca03cd316afbdc9db66bfd071a0766327406607c0ce8ab8be2dc2cf2b84d9e815b40e73d67b492397b64496da86333d'
7
+ data.tar.gz: 53da477897552e78dbf4fb9f10742d8f8d7f1a9a9bbd498128a61b7df6f38d0376b1560b823fab433841a1d67b705935c77c447efb760c128cf4245a20fb29a8
data/.rubocop.yml CHANGED
@@ -215,7 +215,7 @@ RSpec/DescribeClass:
215
215
  RSpec/DescribedClass:
216
216
  Enabled: false
217
217
 
218
- RSpec/FilePath:
218
+ RSpec/SpecFilePathFormat:
219
219
  Enabled: false
220
220
 
221
221
  RSpec/IdenticalEqualityAssertion:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.9.2] - 2023-07-03
2
+
3
+ - Dependency updates
4
+ - Create shadow and audit with auatovacuum default turned off. Should avoid lock queues when disabling vacuum on audit table. #97
5
+ ## [0.9.1] - 2023-06-24
6
+
7
+ - Dependency updates and refresh docker release process with multi-platform build
8
+
1
9
  ## [0.9.0] - 2023-05-22
2
10
 
3
11
  - Fix typo in README.md https://github.com/shayonj/pg-osc/pull/87
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_online_schema_change (0.9.1)
4
+ pg_online_schema_change (0.9.2)
5
5
  ougai (~> 2.0.0)
6
6
  pg (>= 1.3.2, < 1.6.0)
7
7
  pg_query (>= 2.1.3, < 4.3.0)
@@ -11,25 +11,27 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  ast (2.4.2)
14
+ base64 (0.1.1)
14
15
  coderay (1.1.3)
15
16
  diff-lcs (1.5.0)
16
- google-protobuf (3.23.3-arm64-darwin)
17
- google-protobuf (3.23.3-x86_64-linux)
17
+ google-protobuf (3.23.4-arm64-darwin)
18
+ google-protobuf (3.23.4-x86_64-linux)
18
19
  haml (6.1.1)
19
20
  temple (>= 0.8.2)
20
21
  thor
21
22
  tilt
22
23
  json (2.6.3)
24
+ language_server-protocol (3.17.0.3)
23
25
  method_source (1.0.0)
24
- oj (3.14.3)
26
+ oj (3.15.0)
25
27
  ougai (2.0.0)
26
28
  oj (~> 3.10)
27
29
  parallel (1.23.0)
28
30
  parser (3.2.2.3)
29
31
  ast (~> 2.4.1)
30
32
  racc
31
- pg (1.5.3)
32
- pg_query (4.2.1)
33
+ pg (1.5.4)
34
+ pg_query (4.2.3)
33
35
  google-protobuf (>= 3.22.3)
34
36
  prettier_print (1.2.1)
35
37
  pry (0.14.2)
@@ -40,7 +42,7 @@ GEM
40
42
  rake (13.0.6)
41
43
  rbs (3.1.0)
42
44
  regexp_parser (2.8.1)
43
- rexml (3.2.5)
45
+ rexml (3.2.6)
44
46
  rspec (3.12.0)
45
47
  rspec-core (~> 3.12.0)
46
48
  rspec-expectations (~> 3.12.0)
@@ -54,30 +56,32 @@ GEM
54
56
  diff-lcs (>= 1.2.0, < 2.0)
55
57
  rspec-support (~> 3.12.0)
56
58
  rspec-support (3.12.0)
57
- rubocop (1.52.1)
59
+ rubocop (1.56.3)
60
+ base64 (~> 0.1.1)
58
61
  json (~> 2.3)
62
+ language_server-protocol (>= 3.17.0)
59
63
  parallel (~> 1.10)
60
64
  parser (>= 3.2.2.3)
61
65
  rainbow (>= 2.2.2, < 4.0)
62
66
  regexp_parser (>= 1.8, < 3.0)
63
67
  rexml (>= 3.2.5, < 4.0)
64
- rubocop-ast (>= 1.28.0, < 2.0)
68
+ rubocop-ast (>= 1.28.1, < 2.0)
65
69
  ruby-progressbar (~> 1.7)
66
70
  unicode-display_width (>= 2.4.0, < 3.0)
67
71
  rubocop-ast (1.29.0)
68
72
  parser (>= 3.2.1.0)
69
73
  rubocop-capybara (2.18.0)
70
74
  rubocop (~> 1.41)
71
- rubocop-factory_bot (2.22.0)
75
+ rubocop-factory_bot (2.23.1)
72
76
  rubocop (~> 1.33)
73
77
  rubocop-packaging (0.5.2)
74
78
  rubocop (>= 1.33, < 2.0)
75
- rubocop-performance (1.18.0)
79
+ rubocop-performance (1.19.0)
76
80
  rubocop (>= 1.7.0, < 2.0)
77
81
  rubocop-ast (>= 0.4.0)
78
82
  rubocop-rake (0.6.0)
79
83
  rubocop (~> 1.0)
80
- rubocop-rspec (2.22.0)
84
+ rubocop-rspec (2.24.0)
81
85
  rubocop (~> 1.33)
82
86
  rubocop-capybara (~> 2.17)
83
87
  rubocop-factory_bot (~> 2.22)
@@ -105,6 +105,7 @@ module PgOnlineSchemaChange
105
105
  PgOnlineSchemaChange::Orchestrate.run!(client_options)
106
106
  end
107
107
 
108
+ map ['--version', '-v'] => :version
108
109
  desc "--version, -v", "print the version"
109
110
 
110
111
  def version
@@ -45,7 +45,7 @@ FUNC_CREATE_TABLE_ALL = <<~SQL
45
45
  rec record;
46
46
  begin
47
47
  EXECUTE format(
48
- 'CREATE TABLE %s (LIKE %s including all)',
48
+ 'CREATE TABLE %s (LIKE %s including all) WITH (autovacuum_enabled = false)',
49
49
  newsource_table, source_table);
50
50
  END
51
51
  $$;
@@ -35,8 +35,8 @@ module PgOnlineSchemaChange
35
35
  Store.set(:operation_type_column, "operation_type_#{pgosc_identifier}")
36
36
  Store.set(:trigger_time_column, "trigger_time_#{pgosc_identifier}")
37
37
  Store.set(:audit_table_pk, "at_#{pgosc_identifier}_id")
38
- Store.set(:audit_table_pk_sequence, "#{audit_table}_#{audit_table_pk}_seq")
39
38
  Store.set(:shadow_table, "pgosc_st_#{client.table.downcase}_#{pgosc_identifier}")
39
+ Store.set(:primary_table_storage_parameters, Query.storage_parameters_for(client, client.table_name, true) || "")
40
40
 
41
41
  Store.set(
42
42
  :referential_foreign_key_statements,
@@ -59,7 +59,6 @@ module PgOnlineSchemaChange
59
59
 
60
60
  setup_trigger!
61
61
  setup_shadow_table! # re-uses transaction with serializable
62
- disable_vacuum! # re-uses transaction with serializable
63
62
  run_alter_statement! # re-uses transaction with serializable
64
63
  copy_data! # re-uses transaction with serializable
65
64
  run_analyze!
@@ -105,10 +104,12 @@ module PgOnlineSchemaChange
105
104
  logger.info("Setting up audit table", { audit_table: audit_table })
106
105
 
107
106
  sql = <<~SQL
108
- CREATE TABLE #{audit_table} (#{audit_table_pk} SERIAL PRIMARY KEY, #{operation_type_column} text, #{trigger_time_column} timestamp, LIKE #{client.table_name});
107
+ CREATE TABLE #{audit_table} (#{audit_table_pk} SERIAL PRIMARY KEY, #{operation_type_column} text, #{trigger_time_column} timestamp, LIKE #{client.table_name}) WITH (autovacuum_enabled = false);
109
108
  SQL
110
109
 
111
110
  Query.run(client.connection, sql)
111
+
112
+ Store.set(:audit_table_pk_sequence, Query.get_sequence_name(client, audit_table, audit_table_pk))
112
113
  end
113
114
 
114
115
  def setup_trigger!
@@ -177,28 +178,6 @@ module PgOnlineSchemaChange
177
178
  )
178
179
  end
179
180
 
180
- def disable_vacuum!
181
- # re-uses transaction with serializable
182
- # Disabling vacuum to avoid any issues during the process
183
- result = Query.storage_parameters_for(client, client.table_name, true) || ""
184
- Store.set(:primary_table_storage_parameters, result)
185
-
186
- logger.debug(
187
- "Disabling vacuum on shadow and audit table",
188
- { shadow_table: shadow_table, audit_table: audit_table },
189
- )
190
- sql = <<~SQL
191
- ALTER TABLE #{shadow_table} SET (
192
- autovacuum_enabled = false, toast.autovacuum_enabled = false
193
- );
194
-
195
- ALTER TABLE #{audit_table} SET (
196
- autovacuum_enabled = false, toast.autovacuum_enabled = false
197
- );
198
- SQL
199
- Query.run(client.connection, sql, true)
200
- end
201
-
202
181
  def run_alter_statement!
203
182
  # re-uses transaction with serializable
204
183
  statement = Query.alter_statement_for(client, shadow_table)
@@ -81,7 +81,6 @@ module PgOnlineSchemaChange
81
81
  connection.block
82
82
  logger.info("Exception raised, rolling back query", { rollback: true, query: query })
83
83
  connection.async_exec("ROLLBACK;")
84
- connection.async_exec("COMMIT;")
85
84
  raise
86
85
  else
87
86
  connection.async_exec("COMMIT;") unless reuse_trasaction
@@ -135,6 +134,18 @@ module PgOnlineSchemaChange
135
134
  indexes
136
135
  end
137
136
 
137
+ # fetches the sequence name of a table and column combination
138
+ def get_sequence_name(client, table, column)
139
+ query = <<~SQL
140
+ SELECT pg_get_serial_sequence('#{table}', '#{column}');
141
+ SQL
142
+
143
+ run(client.connection, query) { |result| result.map { |row|
144
+ row["pg_get_serial_sequence"]
145
+ }
146
+ }.first
147
+ end
148
+
138
149
  def get_triggers_for(client, table)
139
150
  query = <<~SQL
140
151
  SELECT pg_get_triggerdef(oid) as tdef FROM pg_trigger
@@ -303,7 +314,7 @@ module PgOnlineSchemaChange
303
314
 
304
315
  def view_definitions_for(client, table)
305
316
  query = <<~SQL
306
- SELECT DISTINCT dependent_view.relname as view_name, pg_get_viewdef(dependent_view.relname::regclass) as view_definition
317
+ SELECT DISTINCT dependent_view.relname as view_name, pg_get_viewdef(format('%I.%I', '#{client.schema}', dependent_view.relname)::regclass) as view_definition
307
318
  FROM pg_depend
308
319
  JOIN pg_rewrite ON pg_depend.objid = pg_rewrite.oid
309
320
  JOIN pg_class as dependent_view ON pg_rewrite.ev_class = dependent_view.oid
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgOnlineSchemaChange
4
- VERSION = "0.9.1"
4
+ VERSION = "0.9.3"
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.9.1
4
+ version: 0.9.3
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-06-24 00:00:00.000000000 Z
11
+ date: 2023-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai