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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/pg_online_schema_change/orchestrate.rb +16 -0
- data/lib/pg_online_schema_change/query.rb +21 -0
- data/lib/pg_online_schema_change/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b959611ab7bbaabb457ac51ee7b25c7449962d8a3ff39986251bfaf2c890a4f
|
4
|
+
data.tar.gz: a8cff6b404a625b2f1e3099d5ccec6d35ad4e0346e0016bc7837dced67664f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4685933d5e8e5d59f6f4301ad36a1fba2002c7f02f851aea36e9f61f8ab435c7f52b26ee475488adfedb5c8ab872d923619de2c7c0a8f907df50be411a5cc97
|
7
|
+
data.tar.gz: 44071e34f1caf2078f909c64c87250ff723cff53a31b2f049475bbbac79cbf6b8cf1881d1d9bad456da9287824aceb3c74777841f0a0f28cca5f40cae2a5b60f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2023-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ougai
|