pg_online_schema_change 0.8.1 → 0.9.0

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: 3b959611ab7bbaabb457ac51ee7b25c7449962d8a3ff39986251bfaf2c890a4f
4
+ data.tar.gz: a8cff6b404a625b2f1e3099d5ccec6d35ad4e0346e0016bc7837dced67664f88
5
5
  SHA512:
6
- metadata.gz: f08b73035281a35a173eb5f704e94742b851be7b932c212295d70396f93c3c6b6a68847811f9bd98ecdd142b175e41f970e1df1e04fd0b2956450ae79d50e517
7
- data.tar.gz: 274afb75e3ba0dd6fdbe4c7a35029f285e5c8fccca6509e0e5cce3fdedf06cfd91c68980037ac4ae811b51fbc901451dbfd75120abaaef92d688eaa2003acb5f
6
+ metadata.gz: d4685933d5e8e5d59f6f4301ad36a1fba2002c7f02f851aea36e9f61f8ab435c7f52b26ee475488adfedb5c8ab872d923619de2c7c0a8f907df50be411a5cc97
7
+ data.tar.gz: 44071e34f1caf2078f909c64c87250ff723cff53a31b2f049475bbbac79cbf6b8cf1881d1d9bad456da9287824aceb3c74777841f0a0f28cca5f40cae2a5b60f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.8.1] - 2023-05-13
2
+
3
+ - Gem path and CI fixes
4
+
1
5
  ## [0.8.0] - 2023-05-13
2
6
 
3
7
  - Ruby 3.1.3 and prettier/ruby https://github.com/shayonj/pg-osc/pull/83
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_online_schema_change (0.8.1)
4
+ pg_online_schema_change (0.9.0)
5
5
  ougai (~> 2.0.0)
6
6
  pg (~> 1.3.2)
7
7
  pg_query (~> 2.1.3)
@@ -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.0"
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.8.1
4
+ version: 0.9.0
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-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ougai