rubocop-migration 0.4.2 → 0.5.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/.rubocop.yml +3 -3
- data/Gemfile.lock +60 -36
- data/lib/rubocop/cop/migration/add_column_with_default_value.rb +1 -1
- data/lib/rubocop/cop/migration/add_foreign_key.rb +1 -1
- data/lib/rubocop/cop/migration/add_index_duplicate.rb +2 -2
- data/lib/rubocop/cop/migration/batch_in_batches.rb +27 -16
- data/lib/rubocop/cop/migration/change_column_null.rb +4 -4
- data/lib/rubocop/cop/migration/create_table_force.rb +1 -1
- data/lib/rubocop/cop/migration/jsonb.rb +2 -2
- data/lib/rubocop/cop/migration/remove_column.rb +1 -1
- data/lib/rubocop/cop/migration/reserved_word_mysql.rb +2 -2
- data/lib/rubocop/migration/rubocop_extension.rb +1 -1
- data/lib/rubocop/migration/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: 74f6229f8d3cbb9c31aee226d95ed698edec1fb5cde69090bb8efd57179d8cfe
|
|
4
|
+
data.tar.gz: 85ea516f3e408ae2bfabd0d7bcd7162bbad88281b5e6513d6da71b0c14c3b2a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7af4ce63e220e72a147c272df33ec7d5096868742edb42377871d73eaecd7c0f0ec50505274310b27b5385f1e6bef57e85ec7528df76b88351b3bdde8997a544
|
|
7
|
+
data.tar.gz: 28cdf473b50695099a1d847a482fd5de54cdbeacd8778dbf54389027095478d460b3c70532115b4c2e2dbeba1137f5191946f66a6c2b20eb302310734906f64c
|
data/.rubocop.yml
CHANGED
|
@@ -48,11 +48,11 @@ Sevencop/MethodDefinitionKeywordArgumentOrdered:
|
|
|
48
48
|
Sevencop/MethodDefinitionOrdered:
|
|
49
49
|
Enabled: true
|
|
50
50
|
|
|
51
|
-
Sevencop/RequireOrdered:
|
|
52
|
-
Enabled: true
|
|
53
|
-
|
|
54
51
|
Style/Documentation:
|
|
55
52
|
Enabled: false
|
|
56
53
|
|
|
57
54
|
Style/MultilineBlockChain:
|
|
58
55
|
Enabled: false
|
|
56
|
+
|
|
57
|
+
Style/RequireOrder:
|
|
58
|
+
Enabled: true
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rubocop-migration (0.
|
|
4
|
+
rubocop-migration (0.5.0)
|
|
5
5
|
activesupport
|
|
6
6
|
rubocop (>= 1.34)
|
|
7
7
|
rubocop-rails
|
|
@@ -9,68 +9,92 @@ PATH
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
activesupport (7.
|
|
12
|
+
activesupport (7.1.3)
|
|
13
|
+
base64
|
|
14
|
+
bigdecimal
|
|
13
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
16
|
+
connection_pool (>= 2.2.5)
|
|
17
|
+
drb
|
|
14
18
|
i18n (>= 1.6, < 2)
|
|
15
19
|
minitest (>= 5.1)
|
|
20
|
+
mutex_m
|
|
16
21
|
tzinfo (~> 2.0)
|
|
17
22
|
ast (2.4.2)
|
|
18
|
-
|
|
23
|
+
base64 (0.2.0)
|
|
24
|
+
bigdecimal (3.1.6)
|
|
25
|
+
concurrent-ruby (1.2.3)
|
|
26
|
+
connection_pool (2.4.1)
|
|
19
27
|
diff-lcs (1.5.0)
|
|
28
|
+
drb (2.2.0)
|
|
29
|
+
ruby2_keywords
|
|
20
30
|
i18n (1.14.1)
|
|
21
31
|
concurrent-ruby (~> 1.0)
|
|
22
|
-
json (2.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
json (2.7.1)
|
|
33
|
+
language_server-protocol (3.17.0.3)
|
|
34
|
+
minitest (5.21.2)
|
|
35
|
+
mutex_m (0.2.0)
|
|
36
|
+
parallel (1.24.0)
|
|
37
|
+
parser (3.3.0.5)
|
|
26
38
|
ast (~> 2.4.1)
|
|
39
|
+
racc
|
|
40
|
+
racc (1.7.3)
|
|
27
41
|
rack (3.0.8)
|
|
28
42
|
rainbow (3.1.1)
|
|
29
|
-
rake (13.0
|
|
30
|
-
regexp_parser (2.
|
|
31
|
-
rexml (3.2.
|
|
32
|
-
rspec (3.
|
|
33
|
-
rspec-core (~> 3.
|
|
34
|
-
rspec-expectations (~> 3.
|
|
35
|
-
rspec-mocks (~> 3.
|
|
36
|
-
rspec-core (3.
|
|
37
|
-
rspec-support (~> 3.
|
|
38
|
-
rspec-expectations (3.
|
|
43
|
+
rake (13.1.0)
|
|
44
|
+
regexp_parser (2.9.0)
|
|
45
|
+
rexml (3.2.6)
|
|
46
|
+
rspec (3.12.0)
|
|
47
|
+
rspec-core (~> 3.12.0)
|
|
48
|
+
rspec-expectations (~> 3.12.0)
|
|
49
|
+
rspec-mocks (~> 3.12.0)
|
|
50
|
+
rspec-core (3.12.2)
|
|
51
|
+
rspec-support (~> 3.12.0)
|
|
52
|
+
rspec-expectations (3.12.3)
|
|
39
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
-
rspec-support (~> 3.
|
|
41
|
-
rspec-mocks (3.
|
|
54
|
+
rspec-support (~> 3.12.0)
|
|
55
|
+
rspec-mocks (3.12.6)
|
|
42
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
-
rspec-support (~> 3.
|
|
44
|
-
rspec-support (3.
|
|
45
|
-
rubocop (1.
|
|
57
|
+
rspec-support (~> 3.12.0)
|
|
58
|
+
rspec-support (3.12.1)
|
|
59
|
+
rubocop (1.60.2)
|
|
46
60
|
json (~> 2.3)
|
|
61
|
+
language_server-protocol (>= 3.17.0)
|
|
47
62
|
parallel (~> 1.10)
|
|
48
|
-
parser (>= 3.
|
|
63
|
+
parser (>= 3.3.0.2)
|
|
49
64
|
rainbow (>= 2.2.2, < 4.0)
|
|
50
65
|
regexp_parser (>= 1.8, < 3.0)
|
|
51
66
|
rexml (>= 3.2.5, < 4.0)
|
|
52
|
-
rubocop-ast (>= 1.
|
|
67
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
53
68
|
ruby-progressbar (~> 1.7)
|
|
54
|
-
unicode-display_width (>=
|
|
55
|
-
rubocop-ast (1.
|
|
56
|
-
parser (>= 3.
|
|
57
|
-
rubocop-
|
|
58
|
-
rubocop (
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
70
|
+
rubocop-ast (1.30.0)
|
|
71
|
+
parser (>= 3.2.1.0)
|
|
72
|
+
rubocop-capybara (2.20.0)
|
|
73
|
+
rubocop (~> 1.41)
|
|
74
|
+
rubocop-factory_bot (2.25.1)
|
|
75
|
+
rubocop (~> 1.41)
|
|
76
|
+
rubocop-performance (1.20.2)
|
|
77
|
+
rubocop (>= 1.48.1, < 2.0)
|
|
78
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
79
|
+
rubocop-rails (2.23.1)
|
|
61
80
|
activesupport (>= 4.2.0)
|
|
62
81
|
rack (>= 1.1)
|
|
63
82
|
rubocop (>= 1.33.0, < 2.0)
|
|
83
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
|
64
84
|
rubocop-rake (0.6.0)
|
|
65
85
|
rubocop (~> 1.0)
|
|
66
|
-
rubocop-rspec (2.
|
|
67
|
-
rubocop (~> 1.
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
rubocop-rspec (2.26.1)
|
|
87
|
+
rubocop (~> 1.40)
|
|
88
|
+
rubocop-capybara (~> 2.17)
|
|
89
|
+
rubocop-factory_bot (~> 2.22)
|
|
90
|
+
ruby-progressbar (1.13.0)
|
|
91
|
+
ruby2_keywords (0.0.5)
|
|
92
|
+
sevencop (0.35.1)
|
|
93
|
+
activesupport
|
|
70
94
|
rubocop
|
|
71
95
|
tzinfo (2.0.6)
|
|
72
96
|
concurrent-ruby (~> 1.0)
|
|
73
|
-
unicode-display_width (2.
|
|
97
|
+
unicode-display_width (2.5.0)
|
|
74
98
|
|
|
75
99
|
PLATFORMS
|
|
76
100
|
x86_64-linux
|
|
@@ -144,7 +144,7 @@ module RuboCop
|
|
|
144
144
|
corrector.remove(
|
|
145
145
|
range_with_surrounding_comma(
|
|
146
146
|
range_with_surrounding_space(
|
|
147
|
-
option_foreign_key_true_node_from_add_reference(node).
|
|
147
|
+
option_foreign_key_true_node_from_add_reference(node).source_range,
|
|
148
148
|
side: :left
|
|
149
149
|
),
|
|
150
150
|
:left
|
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
|
108
108
|
indexed_columns_node = indexed_columns_node_from(node)
|
|
109
109
|
case indexed_columns_node&.type
|
|
110
110
|
when :array
|
|
111
|
-
indexed_columns_node.children.map
|
|
111
|
+
indexed_columns_node.children.map { |child| child.value.to_s }
|
|
112
112
|
when :str, :sym
|
|
113
113
|
[indexed_columns_node.value.to_s]
|
|
114
114
|
end
|
|
@@ -121,7 +121,7 @@ module RuboCop
|
|
|
121
121
|
when :add_index
|
|
122
122
|
node.arguments[1]
|
|
123
123
|
when :index
|
|
124
|
-
node.
|
|
124
|
+
node.first_argument
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -26,7 +26,16 @@ module RuboCop
|
|
|
26
26
|
# disable_ddl_transaction!
|
|
27
27
|
#
|
|
28
28
|
# def up
|
|
29
|
-
# User.
|
|
29
|
+
# User.in_batches.update_all(some_column: 'some value')
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# # good
|
|
34
|
+
# class BackfillSomeColumnToUsers < ActiveRecord::Migration[7.0]
|
|
35
|
+
# disable_ddl_transaction!
|
|
36
|
+
#
|
|
37
|
+
# def up
|
|
38
|
+
# User.in_batches do |relation|
|
|
30
39
|
# relation.update_all(some_column: 'some value')
|
|
31
40
|
# end
|
|
32
41
|
# end
|
|
@@ -62,32 +71,34 @@ module RuboCop
|
|
|
62
71
|
corrector,
|
|
63
72
|
node
|
|
64
73
|
)
|
|
65
|
-
|
|
66
|
-
end_pos: node.location.expression.end_pos
|
|
67
|
-
)
|
|
68
|
-
corrector.replace(
|
|
69
|
-
range,
|
|
70
|
-
<<~TEXT.chomp
|
|
71
|
-
in_batches do |relation|
|
|
72
|
-
relation.#{range.source}
|
|
73
|
-
end
|
|
74
|
-
TEXT
|
|
75
|
-
)
|
|
74
|
+
corrector.insert_before(node.location.selector, 'in_batches.')
|
|
76
75
|
end
|
|
77
76
|
|
|
78
|
-
# @param node [RuboCop::AST::
|
|
77
|
+
# @param node [RuboCop::AST::SendNode]
|
|
79
78
|
# @return [Boolean]
|
|
80
|
-
def
|
|
79
|
+
def in_batches?(node)
|
|
80
|
+
in_block_batches?(node) || in_inline_batches?(node)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @param node [RuboCop::AST::SendNode]
|
|
84
|
+
# @return [Boolean]
|
|
85
|
+
def in_block_batches?(node)
|
|
81
86
|
node.each_ancestor(:block).any? do |ancestor|
|
|
82
87
|
ancestor.method?(:in_batches)
|
|
83
88
|
end
|
|
84
89
|
end
|
|
85
90
|
|
|
91
|
+
# @param node [RuboCop::AST::SendNode]
|
|
92
|
+
# @return [Boolean]
|
|
93
|
+
def in_inline_batches?(node)
|
|
94
|
+
node.receiver.is_a?(::RuboCop::AST::SendNode) &&
|
|
95
|
+
node.receiver.method?(:in_batches)
|
|
96
|
+
end
|
|
97
|
+
|
|
86
98
|
# @param node [RuboCop::AST::SendNode]
|
|
87
99
|
# @return [Boolean]
|
|
88
100
|
def wrong?(node)
|
|
89
|
-
batch_processing?(node) &&
|
|
90
|
-
!within_in_batches?(node)
|
|
101
|
+
batch_processing?(node) && !in_batches?(node)
|
|
91
102
|
end
|
|
92
103
|
end
|
|
93
104
|
end
|
|
@@ -102,7 +102,7 @@ module RuboCop
|
|
|
102
102
|
)
|
|
103
103
|
corrector.replace(
|
|
104
104
|
node.location.selector.with(
|
|
105
|
-
end_pos: node.
|
|
105
|
+
end_pos: node.source_range.end_pos
|
|
106
106
|
),
|
|
107
107
|
format_check_constraint(
|
|
108
108
|
column_name: find_column_name_from_change_null(node),
|
|
@@ -141,19 +141,19 @@ module RuboCop
|
|
|
141
141
|
# @param node [RuboCop::AST::SendNode]
|
|
142
142
|
# @return [String]
|
|
143
143
|
def find_column_name_from_change_null(node)
|
|
144
|
-
node.
|
|
144
|
+
node.first_argument.value.to_s
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
# @parm node [RuboCop::AST::SendNode]
|
|
148
148
|
# @return [String]
|
|
149
149
|
def find_table_name_from_change_column_null(node)
|
|
150
|
-
node.
|
|
150
|
+
node.first_argument.value.to_s
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
# @param node [RuboCop::AST::SendNode]
|
|
154
154
|
# @return [String]
|
|
155
155
|
def find_table_name_from_change_null(node)
|
|
156
|
-
find_ancestor_change_table(node).send_node.
|
|
156
|
+
find_ancestor_change_table(node).send_node.first_argument.value.to_s
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
# @param column_name [String]
|
|
@@ -111,8 +111,8 @@ module RuboCop
|
|
|
111
111
|
when :send
|
|
112
112
|
node.location.selector
|
|
113
113
|
when :sym
|
|
114
|
-
node.
|
|
115
|
-
begin_pos: node.
|
|
114
|
+
node.source_range.with(
|
|
115
|
+
begin_pos: node.source_range.begin_pos + 1
|
|
116
116
|
)
|
|
117
117
|
end
|
|
118
118
|
end
|
|
@@ -135,7 +135,7 @@ module RuboCop
|
|
|
135
135
|
# @param node [RuboCop::AST::SendNode]
|
|
136
136
|
# @return [String, nil]
|
|
137
137
|
def find_table_name_from(node)
|
|
138
|
-
table_name_node = node.
|
|
138
|
+
table_name_node = node.first_argument
|
|
139
139
|
table_name_node.value&.to_s if table_name_node.respond_to?(:value)
|
|
140
140
|
end
|
|
141
141
|
|
|
@@ -165,7 +165,7 @@ module RuboCop
|
|
|
165
165
|
when :rename_column
|
|
166
166
|
[node.arguments[2]]
|
|
167
167
|
when *COLUMN_TYPE_METHOD_NAMES
|
|
168
|
-
[node.
|
|
168
|
+
[node.first_argument]
|
|
169
169
|
else
|
|
170
170
|
[]
|
|
171
171
|
end
|
|
@@ -203,7 +203,7 @@ module RuboCop
|
|
|
203
203
|
when :create_join_table
|
|
204
204
|
[table_name_option_from(node)].compact
|
|
205
205
|
when :create_table
|
|
206
|
-
[node.
|
|
206
|
+
[node.first_argument]
|
|
207
207
|
when :rename_table
|
|
208
208
|
[node.arguments[1]]
|
|
209
209
|
else
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-migration
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryo Nakamura
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|