safe-pg-migrations 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/safe-pg-migrations/base.rb +4 -2
- data/lib/safe-pg-migrations/plugins/blocking_activity_logger.rb +1 -0
- data/lib/safe-pg-migrations/plugins/idem_potent_statements.rb +14 -10
- data/lib/safe-pg-migrations/plugins/statement_insurer.rb +20 -14
- data/lib/safe-pg-migrations/plugins/statement_retrier.rb +1 -0
- data/lib/safe-pg-migrations/plugins/useless_statements_logger.rb +12 -7
- data/lib/safe-pg-migrations/version.rb +1 -1
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdee6e752da3fbdec93e5fd5c72fb370497ddd66f1cc27f33609c2a31e364c53
|
4
|
+
data.tar.gz: 143a5dcbf614abed765fac78b16969d900ded5ec574f11d939d802b94d7e2586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c264aa05c7b8ad5fe90f7ecdc88fa700504562e69695d5fd9f4dc9ac63315fb666818554e1387251b367aed241fccff31154589f70309905e1ed1cfae90c68
|
7
|
+
data.tar.gz: 9386e6a8b0366387543998ec5cec42e719d2a4138d5eb52f13f6580d2a3d31e48bd438760b358beb1ab5eb32bd8598927d69bafd03756108a514e88eeb431022
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'ruby2_keywords'
|
3
4
|
require 'safe-pg-migrations/configuration'
|
4
5
|
require 'safe-pg-migrations/plugins/verbose_sql_logger'
|
5
6
|
require 'safe-pg-migrations/plugins/blocking_activity_logger'
|
@@ -50,13 +51,13 @@ module SafePgMigrations
|
|
50
51
|
@alternate_connection = nil
|
51
52
|
end
|
52
53
|
|
53
|
-
def say(*args)
|
54
|
+
ruby2_keywords def say(*args)
|
54
55
|
return unless current_migration
|
55
56
|
|
56
57
|
current_migration.say(*args)
|
57
58
|
end
|
58
59
|
|
59
|
-
def say_method_call(method, *args)
|
60
|
+
ruby2_keywords def say_method_call(method, *args)
|
60
61
|
say "#{method}(#{args.map(&:inspect) * ', '})", true
|
61
62
|
end
|
62
63
|
|
@@ -91,6 +92,7 @@ module SafePgMigrations
|
|
91
92
|
|
92
93
|
safety_assured { super(*args) }
|
93
94
|
end
|
95
|
+
ruby2_keywords method
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
module SafePgMigrations
|
4
4
|
module IdemPotentStatements
|
5
|
-
def add_index(table_name, column_name,
|
5
|
+
ruby2_keywords def add_index(table_name, column_name, *args)
|
6
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
6
7
|
index_name = options.key?(:name) ? options[:name].to_s : index_name(table_name, index_column_names(column_name))
|
7
8
|
return super unless index_name_exists?(table_name, index_name)
|
8
9
|
|
@@ -12,19 +13,20 @@ module SafePgMigrations
|
|
12
13
|
super
|
13
14
|
end
|
14
15
|
|
15
|
-
def add_column(table_name, column_name, type,
|
16
|
+
ruby2_keywords def add_column(table_name, column_name, type, *)
|
16
17
|
return super unless column_exists?(table_name, column_name)
|
17
18
|
|
18
19
|
SafePgMigrations.say("/!\\ Column '#{column_name}' already exists in '#{table_name}'. Skipping statement.", true)
|
19
20
|
end
|
20
21
|
|
21
|
-
def remove_column(table_name, column_name, type = nil,
|
22
|
+
ruby2_keywords def remove_column(table_name, column_name, type = nil, *)
|
22
23
|
return super if column_exists?(table_name, column_name)
|
23
24
|
|
24
25
|
SafePgMigrations.say("/!\\ Column '#{column_name}' not found on table '#{table_name}'. Skipping statement.", true)
|
25
26
|
end
|
26
27
|
|
27
|
-
def remove_index(table_name,
|
28
|
+
ruby2_keywords def remove_index(table_name, *args)
|
29
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
28
30
|
index_name = options.key?(:name) ? options[:name].to_s : index_name(table_name, options)
|
29
31
|
|
30
32
|
return super if index_name_exists?(table_name, index_name)
|
@@ -32,9 +34,10 @@ module SafePgMigrations
|
|
32
34
|
SafePgMigrations.say("/!\\ Index '#{index_name}' not found on table '#{table_name}'. Skipping statement.", true)
|
33
35
|
end
|
34
36
|
|
35
|
-
def add_foreign_key(from_table, to_table,
|
36
|
-
|
37
|
-
|
37
|
+
ruby2_keywords def add_foreign_key(from_table, to_table, *args)
|
38
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
39
|
+
suboptions = options.slice(:name, :column)
|
40
|
+
return super unless foreign_key_exists?(from_table, suboptions.present? ? nil : to_table, **suboptions)
|
38
41
|
|
39
42
|
SafePgMigrations.say(
|
40
43
|
"/!\\ Foreign key '#{from_table}' -> '#{to_table}' already exists. Skipping statement.",
|
@@ -42,19 +45,20 @@ module SafePgMigrations
|
|
42
45
|
)
|
43
46
|
end
|
44
47
|
|
45
|
-
def create_table(table_name,
|
48
|
+
ruby2_keywords def create_table(table_name, *args)
|
49
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
46
50
|
return super if options[:force] || !table_exists?(table_name)
|
47
51
|
|
48
52
|
SafePgMigrations.say "/!\\ Table '#{table_name}' already exists.", true
|
49
53
|
|
50
|
-
td = create_table_definition(table_name,
|
54
|
+
td = create_table_definition(table_name, *args)
|
51
55
|
|
52
56
|
yield td if block_given?
|
53
57
|
|
54
58
|
SafePgMigrations.say(td.indexes.empty? ? '-- Skipping statement' : '-- Creating indexes', true)
|
55
59
|
|
56
60
|
td.indexes.each do |column_name, index_options|
|
57
|
-
add_index(table_name, column_name, index_options)
|
61
|
+
add_index(table_name, column_name, **index_options)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SafePgMigrations
|
4
|
-
module StatementInsurer
|
4
|
+
module StatementInsurer # rubocop:disable Metrics/ModuleLength
|
5
5
|
PG_11_VERSION_NUM = 110_000
|
6
6
|
|
7
7
|
%i[change_column_null change_column].each do |method|
|
8
8
|
define_method method do |*args, &block|
|
9
9
|
with_setting(:statement_timeout, SafePgMigrations.config.pg_safe_timeout) { super(*args, &block) }
|
10
10
|
end
|
11
|
+
ruby2_keywords method
|
11
12
|
end
|
12
13
|
|
13
|
-
def add_column(table_name, column_name, type,
|
14
|
+
ruby2_keywords def add_column(table_name, column_name, type, *args) # rubocop:disable Metrics/CyclomaticComplexity
|
15
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
14
16
|
return super if SafePgMigrations.pg_version_num >= PG_11_VERSION_NUM
|
15
17
|
|
16
18
|
default = options.delete(:default)
|
@@ -36,17 +38,21 @@ module SafePgMigrations
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
def add_foreign_key(from_table, to_table,
|
41
|
+
ruby2_keywords def add_foreign_key(from_table, to_table, *args)
|
42
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
40
43
|
validate_present = options.key? :validate
|
41
44
|
options[:validate] = false unless validate_present
|
45
|
+
with_setting(:statement_timeout, SafePgMigrations.config.pg_safe_timeout) do
|
46
|
+
super(from_table, to_table, **options)
|
47
|
+
end
|
42
48
|
|
43
|
-
|
49
|
+
return if validate_present
|
44
50
|
|
45
|
-
|
46
|
-
without_statement_timeout { validate_foreign_key from_table,
|
51
|
+
suboptions = options.slice(:name, :column)
|
52
|
+
without_statement_timeout { validate_foreign_key from_table, suboptions.present? ? nil : to_table, **suboptions }
|
47
53
|
end
|
48
54
|
|
49
|
-
def create_table(*)
|
55
|
+
ruby2_keywords def create_table(*)
|
50
56
|
with_setting(:statement_timeout, SafePgMigrations.config.pg_safe_timeout) do
|
51
57
|
super do |td|
|
52
58
|
yield td if block_given?
|
@@ -65,17 +71,17 @@ module SafePgMigrations
|
|
65
71
|
options[:algorithm] = :concurrently
|
66
72
|
end
|
67
73
|
|
68
|
-
SafePgMigrations.say_method_call(:add_index, table_name, column_name, options)
|
74
|
+
SafePgMigrations.say_method_call(:add_index, table_name, column_name, **options)
|
69
75
|
|
70
|
-
without_timeout { super }
|
76
|
+
without_timeout { super(table_name, column_name, **options) }
|
71
77
|
end
|
72
78
|
|
73
|
-
def remove_index(table_name,
|
74
|
-
options = { column:
|
75
|
-
options[:algorithm] = :concurrently
|
76
|
-
SafePgMigrations.say_method_call(:remove_index, table_name, options)
|
79
|
+
ruby2_keywords def remove_index(table_name, *args)
|
80
|
+
options = args.last.is_a?(Hash) ? args.last : { column: args.last }
|
81
|
+
options[:algorithm] = :concurrently unless options.key?(:algorithm)
|
82
|
+
SafePgMigrations.say_method_call(:remove_index, table_name, **options)
|
77
83
|
|
78
|
-
without_timeout { super }
|
84
|
+
without_timeout { super(table_name, **options) }
|
79
85
|
end
|
80
86
|
|
81
87
|
def backfill_column_default(table_name, column_name)
|
@@ -2,22 +2,27 @@
|
|
2
2
|
|
3
3
|
module SafePgMigrations
|
4
4
|
module UselessStatementsLogger
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class << self
|
6
|
+
ruby2_keywords def warn_useless(action, link = nil, *args)
|
7
|
+
SafePgMigrations.say "/!\\ No need to explicitly use #{action}, safe-pg-migrations does it for you", *args
|
8
|
+
SafePgMigrations.say "\t see #{link} for more details", *args if link
|
9
|
+
end
|
8
10
|
end
|
9
11
|
|
10
|
-
def add_index(
|
12
|
+
ruby2_keywords def add_index(*args)
|
13
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
11
14
|
warn_for_index(**options)
|
12
15
|
super
|
13
16
|
end
|
14
17
|
|
15
|
-
def remove_index(table_name,
|
16
|
-
|
18
|
+
ruby2_keywords def remove_index(table_name, *args)
|
19
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
20
|
+
warn_for_index(**options) unless options.empty?
|
17
21
|
super
|
18
22
|
end
|
19
23
|
|
20
|
-
def add_foreign_key(
|
24
|
+
ruby2_keywords def add_foreign_key(*args)
|
25
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
21
26
|
if options[:validate] == false
|
22
27
|
UselessStatementsLogger.warn_useless '`validate: :false`', 'https://github.com/doctolib/safe-pg-migrations#safe_add_foreign_key'
|
23
28
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe-pg-migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Prat
|
8
8
|
- Romain Choquet
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '5.2'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: ruby2_keywords
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.0.4
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.0.4
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: bundler
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +188,7 @@ homepage: https://github.com/doctolib/safe-pg-migrations
|
|
174
188
|
licenses:
|
175
189
|
- MIT
|
176
190
|
metadata: {}
|
177
|
-
post_install_message:
|
191
|
+
post_install_message:
|
178
192
|
rdoc_options: []
|
179
193
|
require_paths:
|
180
194
|
- lib
|
@@ -183,15 +197,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
197
|
- - ">="
|
184
198
|
- !ruby/object:Gem::Version
|
185
199
|
version: '2.5'
|
200
|
+
- - "<"
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '4'
|
186
203
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
204
|
requirements:
|
188
205
|
- - ">="
|
189
206
|
- !ruby/object:Gem::Version
|
190
207
|
version: '0'
|
191
208
|
requirements: []
|
192
|
-
rubyforge_project:
|
209
|
+
rubyforge_project:
|
193
210
|
rubygems_version: 2.7.3
|
194
|
-
signing_key:
|
211
|
+
signing_key:
|
195
212
|
specification_version: 4
|
196
213
|
summary: Make your PG migrations safe.
|
197
214
|
test_files: []
|