pg_online_schema_change 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -1
- data/.rubocop_todo.yml +5 -5
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -2
- data/README.md +3 -1
- data/lib/pg_online_schema_change/cli.rb +1 -1
- data/lib/pg_online_schema_change/functions.rb +0 -12
- data/lib/pg_online_schema_change/orchestrate.rb +4 -2
- data/lib/pg_online_schema_change/query.rb +23 -3
- 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: 273557a58c9492e628277e6eed7b655233c47bb51b12a61ca3eaf3377557205a
|
4
|
+
data.tar.gz: 6ec45511249401c420cc3c61652a4ad18225917b644574fb58329819fb422ab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f07b0af4c6a78de6945b6f43e271518f9c5953388e99dcc7582c4db865881ac5e5b8d0f1dff9a1215216ea534ad1e393fb268816e3799832911688b7abc14e
|
7
|
+
data.tar.gz: 0362f9c666c58acdb2fb63f1cd0208c719eb788555b218a57e2aee7bb9d98bbd9a7ff4d1e0ee0a56deec8e9679def1ae116fef919366e86ae30b2444d3379e6a
|
data/.rspec
CHANGED
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-
|
3
|
+
# on 2022-03-13 19:35:49 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:
|
12
|
+
Max: 250
|
13
13
|
|
14
14
|
# Offense count: 2
|
15
15
|
# Configuration parameters: IgnoredMethods.
|
@@ -26,14 +26,14 @@ Packaging/GemspecGit:
|
|
26
26
|
Exclude:
|
27
27
|
- 'pg_online_schema_change.gemspec'
|
28
28
|
|
29
|
-
# Offense count:
|
29
|
+
# Offense count: 67
|
30
30
|
# Configuration parameters: CountAsOne.
|
31
31
|
RSpec/ExampleLength:
|
32
32
|
Max: 55
|
33
33
|
|
34
|
-
# Offense count:
|
34
|
+
# Offense count: 24
|
35
35
|
RSpec/MultipleExpectations:
|
36
|
-
Max:
|
36
|
+
Max: 13
|
37
37
|
|
38
38
|
# Offense count: 6
|
39
39
|
# Configuration parameters: AllowedMethods.
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## [0.6.0] - 2022-02-26
|
2
|
+
* Delete items by audit table PK when replaying by @shayonj @jfrost in https://github.com/shayonj/pg-osc/pull/60
|
3
|
+
- Fixes a race condition issue: https://github.com/shayonj/pg-osc/issues/58
|
4
|
+
|
1
5
|
## [0.5.0] - 2022-02-26
|
2
6
|
* Share some preliminary load test figures in https://github.com/shayonj/pg-osc/pull/54
|
3
7
|
* Reuse existing transaction open for reading table columns in https://github.com/shayonj/pg-osc/pull/53
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pg_online_schema_change (0.
|
4
|
+
pg_online_schema_change (0.6.0)
|
5
5
|
ougai (~> 2.0.0)
|
6
6
|
pg (~> 1.3.2)
|
7
7
|
pg_query (~> 2.1.3)
|
@@ -14,6 +14,7 @@ GEM
|
|
14
14
|
coderay (1.1.3)
|
15
15
|
diff-lcs (1.5.0)
|
16
16
|
google-protobuf (3.19.4)
|
17
|
+
google-protobuf (3.19.4-x86_64-linux)
|
17
18
|
method_source (1.0.0)
|
18
19
|
oj (3.13.11)
|
19
20
|
ougai (2.0.0)
|
@@ -21,7 +22,7 @@ GEM
|
|
21
22
|
parallel (1.21.0)
|
22
23
|
parser (3.0.3.2)
|
23
24
|
ast (~> 2.4.1)
|
24
|
-
pg (1.3.
|
25
|
+
pg (1.3.3)
|
25
26
|
pg_query (2.1.3)
|
26
27
|
google-protobuf (>= 3.19.2)
|
27
28
|
pry (0.14.1)
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# pg-osc
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CI](https://github.com/shayonj/pg-osc/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/shayonj/pg-osc/actions/workflows/ci.yaml)
|
4
|
+
[![Smoke Test PG 9.6](https://github.com/shayonj/pg-osc/actions/workflows/smoke-tests-9-6.yaml/badge.svg?branch=main)](https://github.com/shayonj/pg-osc/actions/workflows/smoke-tests-9-6.yaml)
|
5
|
+
[![Smoke Test PG 13.6](https://github.com/shayonj/pg-osc/actions/workflows/smoke-tests-13-6.yaml/badge.svg?branch=main)](https://github.com/shayonj/pg-osc/actions/workflows/smoke-tests-13-6.yaml)
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/pg_online_schema_change.svg)](https://badge.fury.io/rb/pg_online_schema_change)
|
5
7
|
|
6
8
|
pg-online-schema-change (`pg-osc`) is a tool for making schema changes (any `ALTER` statements) in Postgres tables with minimal locks, thus helping achieve zero downtime schema changes against production workloads.
|
@@ -15,7 +15,7 @@ module PgOnlineSchemaChange
|
|
15
15
|
method_option :host, aliases: "-h", type: :string, required: true, desc: "Server host where the Database is located"
|
16
16
|
method_option :username, aliases: "-u", type: :string, required: true, desc: "Username for the Database"
|
17
17
|
method_option :port, aliases: "-p", type: :numeric, required: true, default: 5432, desc: "Port for the Database"
|
18
|
-
method_option :password, aliases: "-w", type: :string, required:
|
18
|
+
method_option :password, aliases: "-w", type: :string, required: false, default: "", desc: "DEPRECATED: Password for the Database. Please pass PGPASSWORD environment variable instead."
|
19
19
|
method_option :verbose, aliases: "-v", type: :boolean, default: false, desc: "Emit logs in debug mode"
|
20
20
|
method_option :drop, aliases: "-f", type: :boolean, default: false,
|
21
21
|
desc: "Drop the original table in the end after the swap"
|
@@ -47,18 +47,6 @@ FUNC_CREATE_TABLE_ALL = <<~SQL
|
|
47
47
|
EXECUTE format(
|
48
48
|
'CREATE TABLE %s (LIKE %s including all)',
|
49
49
|
newsource_table, source_table);
|
50
|
-
for rec in
|
51
|
-
SELECT oid, conname
|
52
|
-
FROM pg_constraint
|
53
|
-
WHERE contype = 'f'
|
54
|
-
AND conrelid = source_table::regclass
|
55
|
-
LOOP
|
56
|
-
EXECUTE format(
|
57
|
-
'ALTER TABLE %s add constraint %s %s',
|
58
|
-
newsource_table,
|
59
|
-
rec.conname,
|
60
|
-
pg_get_constraintdef(rec.oid));
|
61
|
-
END LOOP;
|
62
50
|
END
|
63
51
|
$$;
|
64
52
|
SQL
|
@@ -38,7 +38,8 @@ module PgOnlineSchemaChange
|
|
38
38
|
Store.set(:audit_table_pk_sequence, "#{audit_table}_#{audit_table_pk}_seq")
|
39
39
|
Store.set(:shadow_table, "pgosc_st_#{client.table}_#{pgosc_identifier}")
|
40
40
|
|
41
|
-
Store.set(:
|
41
|
+
Store.set(:referential_foreign_key_statements, Query.referential_foreign_keys_to_refresh(client, client.table))
|
42
|
+
Store.set(:self_foreign_key_statements, Query.self_foreign_keys_to_refresh(client, client.table))
|
42
43
|
end
|
43
44
|
|
44
45
|
def run!(options)
|
@@ -240,7 +241,8 @@ module PgOnlineSchemaChange
|
|
240
241
|
sql = <<~SQL
|
241
242
|
ALTER TABLE #{client.table} RENAME to #{old_primary_table};
|
242
243
|
ALTER TABLE #{shadow_table} RENAME to #{client.table};
|
243
|
-
#{
|
244
|
+
#{referential_foreign_key_statements}
|
245
|
+
#{self_foreign_key_statements}
|
244
246
|
#{storage_params_reset}
|
245
247
|
DROP TRIGGER IF EXISTS primary_to_audit_table_trigger ON #{client.table};
|
246
248
|
SQL
|
@@ -140,7 +140,7 @@ module PgOnlineSchemaChange
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
def
|
143
|
+
def referential_foreign_keys_to_refresh(client, table)
|
144
144
|
references = get_all_constraints_for(client).select do |row|
|
145
145
|
row["table_from"] == table && row["constraint_type"] == "f"
|
146
146
|
end
|
@@ -158,12 +158,32 @@ module PgOnlineSchemaChange
|
|
158
158
|
end.join
|
159
159
|
end
|
160
160
|
|
161
|
-
def
|
161
|
+
def self_foreign_keys_to_refresh(client, table)
|
162
162
|
references = get_all_constraints_for(client).select do |row|
|
163
|
-
row["
|
163
|
+
row["table_on"] == table && row["constraint_type"] == "f"
|
164
164
|
end
|
165
165
|
|
166
166
|
references.map do |row|
|
167
|
+
add_statement = if row["definition"].end_with?("NOT VALID")
|
168
|
+
"ALTER TABLE #{row["table_on"]} ADD CONSTRAINT #{row["constraint_name"]} #{row["definition"]};"
|
169
|
+
else
|
170
|
+
"ALTER TABLE #{row["table_on"]} ADD CONSTRAINT #{row["constraint_name"]} #{row["definition"]} NOT VALID;"
|
171
|
+
end
|
172
|
+
add_statement
|
173
|
+
end.join
|
174
|
+
end
|
175
|
+
|
176
|
+
def get_foreign_keys_to_validate(client, table)
|
177
|
+
constraints = get_all_constraints_for(client)
|
178
|
+
referential_foreign_keys = constraints.select do |row|
|
179
|
+
row["table_from"] == table && row["constraint_type"] == "f"
|
180
|
+
end
|
181
|
+
|
182
|
+
self_foreign_keys = constraints.select do |row|
|
183
|
+
row["table_on"] == table && row["constraint_type"] == "f"
|
184
|
+
end
|
185
|
+
|
186
|
+
[referential_foreign_keys, self_foreign_keys].flatten.map do |row|
|
167
187
|
"ALTER TABLE #{row["table_on"]} VALIDATE CONSTRAINT #{row["constraint_name"]};"
|
168
188
|
end.join
|
169
189
|
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.
|
4
|
+
version: 0.7.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: 2022-
|
11
|
+
date: 2022-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ougai
|