rubocop-migration 0.1.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +58 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +11 -1
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -21
- data/Rakefile +9 -3
- data/config/default.yml +151 -0
- data/data/reserved_words_mysql.txt +750 -0
- data/lib/rubocop/cop/migration/add_check_constraint.rb +111 -0
- data/lib/rubocop/cop/migration/add_column_with_default_value.rb +229 -0
- data/lib/rubocop/cop/migration/add_foreign_key.rb +166 -0
- data/lib/rubocop/cop/migration/add_index_columns_count.rb +114 -0
- data/lib/rubocop/cop/migration/add_index_concurrently.rb +164 -0
- data/lib/rubocop/cop/migration/add_index_duplicate.rb +183 -0
- data/lib/rubocop/cop/migration/batch_in_batches.rb +95 -0
- data/lib/rubocop/cop/migration/batch_in_transaction.rb +83 -0
- data/lib/rubocop/cop/migration/batch_with_throttling.rb +108 -0
- data/lib/rubocop/cop/migration/change_column.rb +113 -0
- data/lib/rubocop/cop/migration/change_column_null.rb +128 -0
- data/lib/rubocop/cop/migration/create_table_force.rb +89 -0
- data/lib/rubocop/cop/migration/jsonb.rb +131 -0
- data/lib/rubocop/cop/migration/remove_column.rb +246 -0
- data/lib/rubocop/cop/migration/rename_column.rb +81 -0
- data/lib/rubocop/cop/migration/rename_table.rb +79 -0
- data/lib/rubocop/cop/migration/reserved_word_mysql.rb +232 -0
- data/lib/rubocop/migration/config_loader.rb +51 -0
- data/lib/rubocop/migration/cop_concerns/batch_processing.rb +34 -0
- data/lib/rubocop/migration/cop_concerns/column_type_method.rb +28 -0
- data/lib/rubocop/migration/cop_concerns/disable_ddl_transaction.rb +51 -0
- data/lib/rubocop/migration/cop_concerns.rb +11 -0
- data/lib/rubocop/migration/rubocop_extension.rb +15 -0
- data/lib/rubocop/migration/version.rb +4 -2
- data/lib/rubocop/migration.rb +23 -0
- data/rubocop-migration.gemspec +25 -29
- metadata +50 -108
- data/.gitignore +0 -15
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/circle.yml +0 -6
- data/lib/rubocop/cop/migration/add_index_non_concurrently.rb +0 -66
- data/lib/rubocop-migration.rb +0 -11
- data/vendor/.gitkeep +0 -0
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.3.2
|
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: 2022-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,150 +16,93 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.34'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.14'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.14'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '10.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '10.0'
|
40
|
+
version: '1.34'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec-its
|
42
|
+
name: rubocop-rails
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
86
44
|
requirements:
|
87
45
|
- - ">="
|
88
46
|
- !ruby/object:Gem::Version
|
89
47
|
version: '0'
|
90
|
-
type: :
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec-collection_matchers
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec_junit_formatter
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.2'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.2'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: pry
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
48
|
+
type: :runtime
|
133
49
|
prerelease: false
|
134
50
|
version_requirements: !ruby/object:Gem::Requirement
|
135
51
|
requirements:
|
136
52
|
- - ">="
|
137
53
|
- !ruby/object:Gem::Version
|
138
54
|
version: '0'
|
139
|
-
description:
|
55
|
+
description:
|
140
56
|
email:
|
141
|
-
-
|
57
|
+
- r7kamura@gmail.com
|
142
58
|
executables: []
|
143
59
|
extensions: []
|
144
60
|
extra_rdoc_files: []
|
145
61
|
files:
|
146
|
-
- ".gitignore"
|
147
62
|
- ".rspec"
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- CHANGELOG.md
|
65
|
+
- CODE_OF_CONDUCT.md
|
148
66
|
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
149
69
|
- README.md
|
150
70
|
- Rakefile
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
- lib/rubocop
|
155
|
-
- lib/rubocop/cop/migration/
|
71
|
+
- config/default.yml
|
72
|
+
- data/reserved_words_mysql.txt
|
73
|
+
- lib/rubocop/cop/migration/add_check_constraint.rb
|
74
|
+
- lib/rubocop/cop/migration/add_column_with_default_value.rb
|
75
|
+
- lib/rubocop/cop/migration/add_foreign_key.rb
|
76
|
+
- lib/rubocop/cop/migration/add_index_columns_count.rb
|
77
|
+
- lib/rubocop/cop/migration/add_index_concurrently.rb
|
78
|
+
- lib/rubocop/cop/migration/add_index_duplicate.rb
|
79
|
+
- lib/rubocop/cop/migration/batch_in_batches.rb
|
80
|
+
- lib/rubocop/cop/migration/batch_in_transaction.rb
|
81
|
+
- lib/rubocop/cop/migration/batch_with_throttling.rb
|
82
|
+
- lib/rubocop/cop/migration/change_column.rb
|
83
|
+
- lib/rubocop/cop/migration/change_column_null.rb
|
84
|
+
- lib/rubocop/cop/migration/create_table_force.rb
|
85
|
+
- lib/rubocop/cop/migration/jsonb.rb
|
86
|
+
- lib/rubocop/cop/migration/remove_column.rb
|
87
|
+
- lib/rubocop/cop/migration/rename_column.rb
|
88
|
+
- lib/rubocop/cop/migration/rename_table.rb
|
89
|
+
- lib/rubocop/cop/migration/reserved_word_mysql.rb
|
90
|
+
- lib/rubocop/migration.rb
|
91
|
+
- lib/rubocop/migration/config_loader.rb
|
92
|
+
- lib/rubocop/migration/cop_concerns.rb
|
93
|
+
- lib/rubocop/migration/cop_concerns/batch_processing.rb
|
94
|
+
- lib/rubocop/migration/cop_concerns/column_type_method.rb
|
95
|
+
- lib/rubocop/migration/cop_concerns/disable_ddl_transaction.rb
|
96
|
+
- lib/rubocop/migration/rubocop_extension.rb
|
156
97
|
- lib/rubocop/migration/version.rb
|
157
98
|
- rubocop-migration.gemspec
|
158
|
-
-
|
159
|
-
homepage: https://github.com/wealthsimple/rubocop-migration
|
99
|
+
homepage: https://github.com/r7kamura/rubocop-migration
|
160
100
|
licenses:
|
161
101
|
- MIT
|
162
|
-
metadata:
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/r7kamura/rubocop-migration
|
104
|
+
source_code_uri: https://github.com/r7kamura/rubocop-migration
|
105
|
+
changelog_uri: https://github.com/r7kamura/rubocop-migration/releases
|
163
106
|
post_install_message:
|
164
107
|
rdoc_options: []
|
165
108
|
require_paths:
|
@@ -168,16 +111,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
168
111
|
requirements:
|
169
112
|
- - ">="
|
170
113
|
- !ruby/object:Gem::Version
|
171
|
-
version: 2.
|
114
|
+
version: '2.7'
|
172
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
116
|
requirements:
|
174
117
|
- - ">="
|
175
118
|
- !ruby/object:Gem::Version
|
176
119
|
version: '0'
|
177
120
|
requirements: []
|
178
|
-
|
179
|
-
rubygems_version: 2.5.1
|
121
|
+
rubygems_version: 3.3.7
|
180
122
|
signing_key:
|
181
123
|
specification_version: 4
|
182
|
-
summary: RuboCop extension
|
124
|
+
summary: RuboCop extension focused on ActiveRecord migration.
|
183
125
|
test_files: []
|
data/.gitignore
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "rubocop-migration"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/circle.yml
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module RuboCop
|
2
|
-
module Cop
|
3
|
-
module Migration
|
4
|
-
class AddIndexNonConcurrently < Cop
|
5
|
-
MSG = 'Use `algorithm: :concurrently` to avoid locking table.'.freeze
|
6
|
-
|
7
|
-
def_node_matcher :add_index_match, <<-PATTERN
|
8
|
-
(send nil :add_index _ _ (hash $...))
|
9
|
-
PATTERN
|
10
|
-
|
11
|
-
def_node_matcher :add_reference_match, <<-PATTERN
|
12
|
-
(send nil {:add_reference :add_belongs_to} _ _ (hash $...))
|
13
|
-
PATTERN
|
14
|
-
|
15
|
-
def_node_matcher :add_reference_index_options?, <<-PATTERN
|
16
|
-
(pair (sym :index) !({:nil false}))
|
17
|
-
PATTERN
|
18
|
-
|
19
|
-
def on_send(node)
|
20
|
-
if node.method_name == :add_index
|
21
|
-
check_add_index(node)
|
22
|
-
elsif [:add_reference, :add_belongs_to].include?(node.method_name)
|
23
|
-
check_add_reference(node)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def check_add_index(node)
|
30
|
-
pairs = add_index_match(node)
|
31
|
-
if !pairs_contains_algorithm_concurrently?(pairs)
|
32
|
-
add_offense(node, :expression, MSG)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def check_add_reference(node)
|
37
|
-
pairs = add_reference_match(node)
|
38
|
-
index_options = pairs&.find { |pair| add_reference_index_options?(pair) }&.value
|
39
|
-
return unless index_options
|
40
|
-
|
41
|
-
valid = true
|
42
|
-
if index_options.true_type?
|
43
|
-
# `index: true` is always invalid
|
44
|
-
valid = false
|
45
|
-
elsif index_options.hash_type?
|
46
|
-
# check for `algorithm: :concurrently`
|
47
|
-
valid = pairs_contains_algorithm_concurrently?(index_options.pairs)
|
48
|
-
end
|
49
|
-
add_offense(node, :expression, MSG) if !valid
|
50
|
-
end
|
51
|
-
|
52
|
-
def pairs_contains_algorithm_concurrently?(pairs)
|
53
|
-
return false unless pairs.is_a?(Array)
|
54
|
-
pairs.each do |pair|
|
55
|
-
next unless pair.pair_type?
|
56
|
-
key = pair.key
|
57
|
-
value = pair.value
|
58
|
-
next unless (key.sym_type? || key.str_type?) && key.children.first.to_s == "algorithm"
|
59
|
-
return true if value.children.first.to_s == "concurrently"
|
60
|
-
end
|
61
|
-
false
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/lib/rubocop-migration.rb
DELETED
data/vendor/.gitkeep
DELETED
File without changes
|