pg_online_schema_change 0.8.1 → 0.9.1

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: 49e57a6481ac80c845becf6dfae0191a14437b8687c02952353c8b64ae584221
4
- data.tar.gz: 9a19a05b26c944beac56cb298a56e3d345cc3a31dde105c3058e694fe7dc166a
3
+ metadata.gz: c13a6a65723fdd06f0de41359026198f3ea60907b7bf839c1d61e9eb9bbceb42
4
+ data.tar.gz: 6259bbb428ffe9a824da3d68289502322db71a26c394c87d1fa37483cb142666
5
5
  SHA512:
6
- metadata.gz: f08b73035281a35a173eb5f704e94742b851be7b932c212295d70396f93c3c6b6a68847811f9bd98ecdd142b175e41f970e1df1e04fd0b2956450ae79d50e517
7
- data.tar.gz: 274afb75e3ba0dd6fdbe4c7a35029f285e5c8fccca6509e0e5cce3fdedf06cfd91c68980037ac4ae811b51fbc901451dbfd75120abaaef92d688eaa2003acb5f
6
+ metadata.gz: 367222a59e33bac35dd4778658d23c5acfbb68585fceb439d986f7846123bec295c2d831441891d0e59b1d3ee2feb438f6fc694fe4f498b02696d39492227079
7
+ data.tar.gz: 13baa1524266424fba9f25db9b308af2c3cb2c24e21f55fec7fb601e2915382f703430130fe8338534a3ce7a20dfe19334e04465877b4db6c76c6386baa54124
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.9.0] - 2023-05-22
2
+
3
+ - Fix typo in README.md https://github.com/shayonj/pg-osc/pull/87
4
+ - Support for views https://github.com/shayonj/pg-osc/pull/88
5
+
6
+ ## [0.8.1] - 2023-05-13
7
+
8
+ - Gem path and CI fixes
9
+
1
10
  ## [0.8.0] - 2023-05-13
2
11
 
3
12
  - Ruby 3.1.3 and prettier/ruby https://github.com/shayonj/pg-osc/pull/83
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:3.0
2
2
 
3
- ARG VERSION=0.2.0
3
+ ARG VERSION
4
4
 
5
- RUN gem install pg_online_schema_change -v $VERSION
5
+ RUN gem install pg_online_schema_change -v $VERSION
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_online_schema_change (0.8.1)
4
+ pg_online_schema_change (0.9.1)
5
5
  ougai (~> 2.0.0)
6
- pg (~> 1.3.2)
7
- pg_query (~> 2.1.3)
6
+ pg (>= 1.3.2, < 1.6.0)
7
+ pg_query (>= 2.1.3, < 4.3.0)
8
8
  thor (~> 1.2.1)
9
9
 
10
10
  GEM
@@ -13,7 +13,8 @@ GEM
13
13
  ast (2.4.2)
14
14
  coderay (1.1.3)
15
15
  diff-lcs (1.5.0)
16
- google-protobuf (3.23.0-arm64-darwin)
16
+ google-protobuf (3.23.3-arm64-darwin)
17
+ google-protobuf (3.23.3-x86_64-linux)
17
18
  haml (6.1.1)
18
19
  temple (>= 0.8.2)
19
20
  thor
@@ -24,19 +25,21 @@ GEM
24
25
  ougai (2.0.0)
25
26
  oj (~> 3.10)
26
27
  parallel (1.23.0)
27
- parser (3.2.2.1)
28
+ parser (3.2.2.3)
28
29
  ast (~> 2.4.1)
29
- pg (1.3.5)
30
- pg_query (2.1.4)
31
- google-protobuf (>= 3.19.2)
30
+ racc
31
+ pg (1.5.3)
32
+ pg_query (4.2.1)
33
+ google-protobuf (>= 3.22.3)
32
34
  prettier_print (1.2.1)
33
35
  pry (0.14.2)
34
36
  coderay (~> 1.1)
35
37
  method_source (~> 1.0)
38
+ racc (1.7.1)
36
39
  rainbow (3.1.1)
37
40
  rake (13.0.6)
38
41
  rbs (3.1.0)
39
- regexp_parser (2.8.0)
42
+ regexp_parser (2.8.1)
40
43
  rexml (3.2.5)
41
44
  rspec (3.12.0)
42
45
  rspec-core (~> 3.12.0)
@@ -51,17 +54,17 @@ GEM
51
54
  diff-lcs (>= 1.2.0, < 2.0)
52
55
  rspec-support (~> 3.12.0)
53
56
  rspec-support (3.12.0)
54
- rubocop (1.51.0)
57
+ rubocop (1.52.1)
55
58
  json (~> 2.3)
56
59
  parallel (~> 1.10)
57
- parser (>= 3.2.0.0)
60
+ parser (>= 3.2.2.3)
58
61
  rainbow (>= 2.2.2, < 4.0)
59
62
  regexp_parser (>= 1.8, < 3.0)
60
63
  rexml (>= 3.2.5, < 4.0)
61
64
  rubocop-ast (>= 1.28.0, < 2.0)
62
65
  ruby-progressbar (~> 1.7)
63
66
  unicode-display_width (>= 2.4.0, < 3.0)
64
- rubocop-ast (1.28.1)
67
+ rubocop-ast (1.29.0)
65
68
  parser (>= 3.2.1.0)
66
69
  rubocop-capybara (2.18.0)
67
70
  rubocop (~> 1.41)
@@ -69,7 +72,7 @@ GEM
69
72
  rubocop (~> 1.33)
70
73
  rubocop-packaging (0.5.2)
71
74
  rubocop (>= 1.33, < 2.0)
72
- rubocop-performance (1.17.1)
75
+ rubocop-performance (1.18.0)
73
76
  rubocop (>= 1.7.0, < 2.0)
74
77
  rubocop-ast (>= 0.4.0)
75
78
  rubocop-rake (0.6.0)
@@ -66,6 +66,7 @@ module PgOnlineSchemaChange
66
66
  replay_and_swap!
67
67
  run_analyze!
68
68
  validate_constraints!
69
+ replace_views!
69
70
  drop_and_cleanup!
70
71
 
71
72
  logger.info("All tasks successfully completed")
@@ -297,6 +298,21 @@ module PgOnlineSchemaChange
297
298
  Query.run(client.connection, validate_statements)
298
299
  end
299
300
 
301
+ def replace_views!
302
+ view_definitions = Query.view_definitions_for(client, old_primary_table)
303
+ view_definitions.each do |definition|
304
+ definition.each do |view_name, view_definition|
305
+ view_definition = view_definition.gsub(old_primary_table, client.table)
306
+
307
+ logger.info("Replacing view #{view_name}")
308
+ sql = <<~SQL
309
+ CREATE OR REPLACE VIEW #{view_name} AS #{view_definition}
310
+ SQL
311
+ Query.run(client.connection, sql)
312
+ end
313
+ end
314
+ end
315
+
300
316
  def drop_and_cleanup!
301
317
  primary_drop = client.drop ? "DROP TABLE IF EXISTS #{old_primary_table};" : ""
302
318
  audit_table_drop = audit_table ? "DROP TABLE IF EXISTS #{audit_table}" : ""
@@ -301,6 +301,27 @@ module PgOnlineSchemaChange
301
301
  columns.first
302
302
  end
303
303
 
304
+ def view_definitions_for(client, table)
305
+ query = <<~SQL
306
+ SELECT DISTINCT dependent_view.relname as view_name, pg_get_viewdef(dependent_view.relname::regclass) as view_definition
307
+ FROM pg_depend
308
+ JOIN pg_rewrite ON pg_depend.objid = pg_rewrite.oid
309
+ JOIN pg_class as dependent_view ON pg_rewrite.ev_class = dependent_view.oid
310
+ JOIN pg_class as source_table ON pg_depend.refobjid = source_table.oid
311
+ JOIN pg_namespace source_ns ON source_ns.oid = source_table.relnamespace
312
+ WHERE
313
+ source_ns.nspname = '#{client.schema}'
314
+ AND source_table.relname = '#{table}'
315
+ SQL
316
+
317
+ definitions = []
318
+ run(client.connection, query) do |result|
319
+ definitions = result.map { |row| {row["view_name"] => row["view_definition"].strip} }
320
+ end
321
+
322
+ definitions
323
+ end
324
+
304
325
  # This function acquires the lock and keeps the transaction
305
326
  # open. If a lock is acquired, its upon the caller
306
327
  # to call COMMIT to end the transaction. If a lock
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgOnlineSchemaChange
4
- VERSION = "0.8.1"
4
+ VERSION = "0.9.1"
5
5
  end
data/scripts/release.sh CHANGED
@@ -1,28 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+
1
5
  export VERSION=$1
2
6
  echo "VERSION: ${VERSION}"
3
7
 
4
- echo "=== Pushing tags to github ===="
5
- git tag v$VERSION
6
- git push origin --tags
7
-
8
8
  echo "=== Building Gem ===="
9
9
  gem build pg_online_schema_change.gemspec
10
10
 
11
11
  echo "=== Pushing gem ===="
12
- gem push pg_online_schema_change-$VERSION.gem
12
+ gem push pg_online_schema_change-"$VERSION".gem
13
13
 
14
- echo "=== Sleeping for 5s ===="
15
- sleep 5
14
+ echo "=== Sleeping for 15s ===="
15
+ sleep 15
16
16
 
17
- echo "=== Building Image ===="
18
- docker build . --build-arg VERSION=$VERSION -t shayonj/pg-osc:$VERSION
19
-
20
- echo "=== Tagging Image ===="
21
- docker image tag shayonj/pg-osc:$VERSION shayonj/pg-osc:latest
22
-
23
- echo "=== Pushing Image ===="
24
- docker push shayonj/pg-osc:$VERSION
25
- docker push shayonj/pg-osc:latest
17
+ echo "=== Pushing tags to github ===="
18
+ git tag v"$VERSION"
19
+ git push origin --tags
26
20
 
27
21
  echo "=== Cleaning up ===="
28
- rm pg_online_schema_change-$VERSION.gem
22
+ rm pg_online_schema_change-"$VERSION".gem
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.8.1
4
+ version: 0.9.1
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-05-13 00:00:00.000000000 Z
11
+ date: 2023-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai
@@ -28,30 +28,42 @@ dependencies:
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.3.2
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: 1.6.0
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: 1.3.2
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.6.0
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: pg_query
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">="
46
52
  - !ruby/object:Gem::Version
47
53
  version: 2.1.3
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: 4.3.0
48
57
  type: :runtime
49
58
  prerelease: false
50
59
  version_requirements: !ruby/object:Gem::Requirement
51
60
  requirements:
52
- - - "~>"
61
+ - - ">="
53
62
  - !ruby/object:Gem::Version
54
63
  version: 2.1.3
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: 4.3.0
55
67
  - !ruby/object:Gem::Dependency
56
68
  name: thor
57
69
  requirement: !ruby/object:Gem::Requirement