rubocop-migration 0.2.0 → 0.3.2
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 +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 +43 -18
- 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 -31
- metadata +50 -137
- data/.gitignore +0 -15
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/circle.yml +0 -6
- data/lib/rubocop/cop/migration/unsafe_migration.rb +0 -69
- data/lib/rubocop/migration/strong_migrations_checker.rb +0 -47
- data/lib/rubocop-migration.rb +0 -16
- data/vendor/.gitkeep +0 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Migration
|
6
|
+
# Avoid renaming columns that are in use.
|
7
|
+
#
|
8
|
+
# It will cause errors in your application.
|
9
|
+
# A safer approach is to:
|
10
|
+
#
|
11
|
+
# 1. Create a new column
|
12
|
+
# 2. Write to both columns
|
13
|
+
# 3. Backfill data from the old column to the new column
|
14
|
+
# 4. Move reads from the old column to the new column
|
15
|
+
# 5. Stop writing to the old column
|
16
|
+
# 6. Drop the old column
|
17
|
+
#
|
18
|
+
# @safety
|
19
|
+
# Only meaningful if the column is in use.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# # bad
|
23
|
+
# class RenameUsersSettingsToProperties < ActiveRecord::Migration[7.0]
|
24
|
+
# def change
|
25
|
+
# rename_column :users, :settings, :properties
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# class AddUsersProperties < ActiveRecord::Migration[7.0]
|
31
|
+
# def change
|
32
|
+
# add_column :users, :properties, :jsonb
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# class User < ApplicationRecord
|
37
|
+
# self.ignored_columns += %w[settings]
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# class RemoveUsersSettings < ActiveRecord::Migration[7.0]
|
41
|
+
# def change
|
42
|
+
# remove_column :users, :settings
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
class RenameColumn < RuboCop::Cop::Base
|
46
|
+
MSG = 'Avoid renaming columns that are in use.'
|
47
|
+
|
48
|
+
RESTRICT_ON_SEND = %i[
|
49
|
+
rename_column
|
50
|
+
].freeze
|
51
|
+
|
52
|
+
# @param node [RuboCop::AST::SendNode]
|
53
|
+
# @return [void]
|
54
|
+
def on_send(node)
|
55
|
+
return unless bad?(node)
|
56
|
+
|
57
|
+
add_offense(node)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# @!method rename_column?(node)
|
63
|
+
# @param node [RuboCop::AST::SendNode]
|
64
|
+
# @return [Boolean]
|
65
|
+
def_node_matcher :rename_column?, <<~PATTERN
|
66
|
+
(send
|
67
|
+
nil?
|
68
|
+
:rename_column
|
69
|
+
...
|
70
|
+
)
|
71
|
+
PATTERN
|
72
|
+
|
73
|
+
# @param node [RuboCop::AST::SendNode]
|
74
|
+
# @return [Boolean]
|
75
|
+
def bad?(node)
|
76
|
+
rename_column?(node)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Migration
|
6
|
+
# Avoid renaming tables that are in use.
|
7
|
+
#
|
8
|
+
# It will cause errors in your application.
|
9
|
+
# A safer approach is to:
|
10
|
+
#
|
11
|
+
# 1. Create a new table
|
12
|
+
# 2. Write to both tables
|
13
|
+
# 3. Backfill data from the old table to new table
|
14
|
+
# 4. Move reads from the old table to the new table
|
15
|
+
# 5. Stop writing to the old table
|
16
|
+
# 6. Drop the old table
|
17
|
+
#
|
18
|
+
# @safety
|
19
|
+
# Only meaningful if the table is in use.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# # bad
|
23
|
+
# class RenameUsersToAccouts < ActiveRecord::Migration[7.0]
|
24
|
+
# def change
|
25
|
+
# rename_table :users, :accounts
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# class AddAccounts < ActiveRecord::Migration[7.0]
|
31
|
+
# def change
|
32
|
+
# create_table :accounts do |t|
|
33
|
+
# t.string :name, null: false
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# class RemoveUsers < ActiveRecord::Migration[7.0]
|
39
|
+
# def change
|
40
|
+
# remove_table :users
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
class RenameTable < RuboCop::Cop::Base
|
44
|
+
MSG = 'Avoid renaming tables that are in use.'
|
45
|
+
|
46
|
+
RESTRICT_ON_SEND = %i[
|
47
|
+
rename_table
|
48
|
+
].freeze
|
49
|
+
|
50
|
+
# @param node [RuboCop::AST::SendNode]
|
51
|
+
# @return [void]
|
52
|
+
def on_send(node)
|
53
|
+
return unless bad?(node)
|
54
|
+
|
55
|
+
add_offense(node)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# @!method rename_table?(node)
|
61
|
+
# @param node [RuboCop::AST::SendNode]
|
62
|
+
# @return [Boolean]
|
63
|
+
def_node_matcher :rename_table?, <<~PATTERN
|
64
|
+
(send
|
65
|
+
nil?
|
66
|
+
:rename_table
|
67
|
+
...
|
68
|
+
)
|
69
|
+
PATTERN
|
70
|
+
|
71
|
+
# @param node [RuboCop::AST::SendNode]
|
72
|
+
# @return [Boolean]
|
73
|
+
def bad?(node)
|
74
|
+
rename_table?(node)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Migration
|
8
|
+
# Avoid using MySQL reserved words as identifiers.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# # NOTE: `role` is a reserved word in MySQL.
|
13
|
+
# add_column :users, :role, :string
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# add_column :users, :some_other_good_name, :string
|
17
|
+
class ReservedWordMysql < RuboCop::Cop::Base
|
18
|
+
include ::RuboCop::Migration::CopConcerns::ColumnTypeMethod
|
19
|
+
|
20
|
+
MSG = 'Avoid using MySQL reserved words as identifiers.'
|
21
|
+
|
22
|
+
# Obtained from https://dev.mysql.com/doc/refman/8.0/en/keywords.html.
|
23
|
+
PATH_TO_RESERVED_WORDS_FILE = File.expand_path(
|
24
|
+
'../../../../data/reserved_words_mysql.txt',
|
25
|
+
__dir__
|
26
|
+
).freeze
|
27
|
+
|
28
|
+
RESTRICT_ON_SEND = [
|
29
|
+
:add_column,
|
30
|
+
:add_index,
|
31
|
+
:add_reference,
|
32
|
+
:create_join_table,
|
33
|
+
:create_table,
|
34
|
+
:rename,
|
35
|
+
:rename_column,
|
36
|
+
:rename_index,
|
37
|
+
:rename_table,
|
38
|
+
*COLUMN_TYPE_METHOD_NAMES
|
39
|
+
].freeze
|
40
|
+
|
41
|
+
class << self
|
42
|
+
# @return [Array<String>]
|
43
|
+
def reserved_words
|
44
|
+
@reserved_words ||= ::Set.new(
|
45
|
+
::File.read(PATH_TO_RESERVED_WORDS_FILE).split("\n")
|
46
|
+
).freeze
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param node [RuboCop::AST::DefNode]
|
51
|
+
# @return [void]
|
52
|
+
def on_send(node)
|
53
|
+
offended_identifier_nodes_from(node).each do |identifier_node|
|
54
|
+
add_offense(identifier_node)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# @!method index_name_option_from_add_index(node)
|
61
|
+
# @param node [RuboCop::AST::SendNode]
|
62
|
+
# @return [RuboCop::AST::Node, nil]
|
63
|
+
def_node_matcher :index_name_option_from_add_index, <<~PATTERN
|
64
|
+
(send
|
65
|
+
nil?
|
66
|
+
:add_index
|
67
|
+
_
|
68
|
+
_
|
69
|
+
(hash
|
70
|
+
<
|
71
|
+
(pair
|
72
|
+
(sym :name)
|
73
|
+
$_
|
74
|
+
)
|
75
|
+
>
|
76
|
+
...
|
77
|
+
)
|
78
|
+
)
|
79
|
+
PATTERN
|
80
|
+
|
81
|
+
# @!method index_name_option_from_add_reference(node)
|
82
|
+
# @param node [RuboCop::AST::SendNode]
|
83
|
+
# @return [RuboCop::AST::Node, nil]
|
84
|
+
def_node_matcher :index_name_option_from_add_reference, <<~PATTERN
|
85
|
+
(send
|
86
|
+
nil?
|
87
|
+
:add_reference
|
88
|
+
_
|
89
|
+
_
|
90
|
+
(hash
|
91
|
+
<
|
92
|
+
(pair
|
93
|
+
(sym :index)
|
94
|
+
(hash
|
95
|
+
<
|
96
|
+
(pair
|
97
|
+
(sym :name)
|
98
|
+
$_
|
99
|
+
)
|
100
|
+
>
|
101
|
+
...
|
102
|
+
)
|
103
|
+
)
|
104
|
+
>
|
105
|
+
...
|
106
|
+
)
|
107
|
+
)
|
108
|
+
PATTERN
|
109
|
+
|
110
|
+
# @!method index_name_option_from_column_type(node)
|
111
|
+
# @param node [RuboCop::AST::SendNode]
|
112
|
+
# @return [RuboCop::AST::Node, nil]
|
113
|
+
def_node_matcher :index_name_option_from_column_type, <<~PATTERN
|
114
|
+
(send
|
115
|
+
lvar
|
116
|
+
COLUMN_TYPE_METHOD_NAMES
|
117
|
+
_
|
118
|
+
(hash
|
119
|
+
<
|
120
|
+
(pair
|
121
|
+
(sym :index)
|
122
|
+
(hash
|
123
|
+
<
|
124
|
+
(pair
|
125
|
+
(sym :name)
|
126
|
+
$_
|
127
|
+
)
|
128
|
+
...
|
129
|
+
>
|
130
|
+
)
|
131
|
+
)
|
132
|
+
...
|
133
|
+
>
|
134
|
+
)
|
135
|
+
)
|
136
|
+
PATTERN
|
137
|
+
|
138
|
+
# @!method table_name_option_from(node)
|
139
|
+
# @param node [RuboCop::AST::SendNode]
|
140
|
+
# @return [RuboCop::AST::Node, nil]
|
141
|
+
def_node_matcher :table_name_option_from, <<~PATTERN
|
142
|
+
(send
|
143
|
+
nil?
|
144
|
+
:create_join_table
|
145
|
+
_
|
146
|
+
_
|
147
|
+
(hash
|
148
|
+
<
|
149
|
+
(pair
|
150
|
+
(sym :table_name)
|
151
|
+
$_
|
152
|
+
)
|
153
|
+
...
|
154
|
+
>
|
155
|
+
)
|
156
|
+
)
|
157
|
+
PATTERN
|
158
|
+
|
159
|
+
# @param node [RuboCop::AST::SendNode]
|
160
|
+
# @return [Array<RuboCop::AST::Node>]
|
161
|
+
def identifier_column_name_nodes_from(node)
|
162
|
+
case node.method_name
|
163
|
+
when :add_column, :rename
|
164
|
+
[node.arguments[1]]
|
165
|
+
when :rename_column
|
166
|
+
[node.arguments[2]]
|
167
|
+
when *COLUMN_TYPE_METHOD_NAMES
|
168
|
+
[node.arguments[0]]
|
169
|
+
else
|
170
|
+
[]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# @param node [RuboCop::AST::SendNode]
|
175
|
+
# @return [Array<RuboCop::AST::Node>]
|
176
|
+
def identifier_index_name_nodes_from(node)
|
177
|
+
case node.method_name
|
178
|
+
when :add_index
|
179
|
+
[index_name_option_from_add_index(node)].compact
|
180
|
+
when :add_reference
|
181
|
+
[index_name_option_from_add_reference(node)].compact
|
182
|
+
when :rename_index
|
183
|
+
[node.arguments[2]]
|
184
|
+
when *COLUMN_TYPE_METHOD_NAMES
|
185
|
+
[index_name_option_from_column_type(node)].compact
|
186
|
+
else
|
187
|
+
[]
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# @param node [RuboCop::AST::SendNode]
|
192
|
+
# @return [Array<RuboCop::AST::Node>]
|
193
|
+
def identifier_nodes_from(node)
|
194
|
+
identifier_table_name_nodes_from(node) +
|
195
|
+
identifier_column_name_nodes_from(node) +
|
196
|
+
identifier_index_name_nodes_from(node)
|
197
|
+
end
|
198
|
+
|
199
|
+
# @param node [RuboCop::AST::SendNode]
|
200
|
+
# @return [Array<RuboCop::AST::Node>]
|
201
|
+
def identifier_table_name_nodes_from(node)
|
202
|
+
case node.method_name
|
203
|
+
when :create_join_table
|
204
|
+
[table_name_option_from(node)].compact
|
205
|
+
when :create_table
|
206
|
+
[node.arguments[0]]
|
207
|
+
when :rename_table
|
208
|
+
[node.arguments[1]]
|
209
|
+
else
|
210
|
+
[]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# @param node [RuboCop::AST::Node]
|
215
|
+
# @return [Array<RuboCop::AST::Node>]
|
216
|
+
def offended_identifier_nodes_from(node)
|
217
|
+
identifier_nodes_from(node).select do |identifier_node|
|
218
|
+
reserved_word_identifier_node?(identifier_node)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# @param node [RuboCop::AST::Node]
|
223
|
+
# @return [Boolean]
|
224
|
+
def reserved_word_identifier_node?(node)
|
225
|
+
return false unless node.respond_to?(:value)
|
226
|
+
|
227
|
+
self.class.reserved_words.include?(node.value.to_s)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Migration
|
7
|
+
# Merge default RuboCop config with plugin config.
|
8
|
+
class ConfigLoader
|
9
|
+
class << self
|
10
|
+
# @param path [String]
|
11
|
+
# @return [RuboCop::Config]
|
12
|
+
def call(path:)
|
13
|
+
new(path: path).call
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param path [String]
|
18
|
+
def initialize(path:)
|
19
|
+
@path = path
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [RuboCop::Config]
|
23
|
+
def call
|
24
|
+
::RuboCop::ConfigLoader.merge_with_default(
|
25
|
+
plugin_config,
|
26
|
+
@path
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# @return [RuboCop::Config]
|
33
|
+
def plugin_config
|
34
|
+
config = ::RuboCop::Config.new(
|
35
|
+
plugin_config_hash,
|
36
|
+
@path
|
37
|
+
)
|
38
|
+
config.make_excludes_absolute
|
39
|
+
config
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Hash]
|
43
|
+
def plugin_config_hash
|
44
|
+
::RuboCop::ConfigLoader.send(
|
45
|
+
:load_yaml_configuration,
|
46
|
+
@path
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Migration
|
5
|
+
module CopConcerns
|
6
|
+
module BatchProcessing
|
7
|
+
BATCH_PROCESSING_METHOD_NAMES = ::Set.new(
|
8
|
+
%i[
|
9
|
+
delete_all
|
10
|
+
update_all
|
11
|
+
]
|
12
|
+
).freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def included(klass)
|
16
|
+
super
|
17
|
+
klass.class_eval do
|
18
|
+
# @!method batch_processing?(node)
|
19
|
+
# @param node [RuboCop::AST::SendNode]
|
20
|
+
# @return [Boolean]
|
21
|
+
def_node_matcher :batch_processing?, <<~PATTERN
|
22
|
+
(send
|
23
|
+
!nil?
|
24
|
+
BATCH_PROCESSING_METHOD_NAMES
|
25
|
+
...
|
26
|
+
)
|
27
|
+
PATTERN
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Migration
|
5
|
+
module CopConcerns
|
6
|
+
module ColumnTypeMethod
|
7
|
+
COLUMN_TYPE_METHOD_NAMES = ::Set.new(
|
8
|
+
%i[
|
9
|
+
bigint
|
10
|
+
binary
|
11
|
+
blob
|
12
|
+
boolean
|
13
|
+
date
|
14
|
+
datetime
|
15
|
+
decimal
|
16
|
+
float
|
17
|
+
integer
|
18
|
+
numeric
|
19
|
+
primary_key
|
20
|
+
string
|
21
|
+
text
|
22
|
+
time
|
23
|
+
]
|
24
|
+
).freeze
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Migration
|
5
|
+
module CopConcerns
|
6
|
+
module DisableDdlTransaction
|
7
|
+
class << self
|
8
|
+
def included(klass)
|
9
|
+
super
|
10
|
+
klass.class_eval do
|
11
|
+
# @!method disable_ddl_transaction?(node)
|
12
|
+
# @param node [RuboCop::AST::SendNode]
|
13
|
+
# @return [Boolean]
|
14
|
+
def_node_matcher :disable_ddl_transaction?, <<~PATTERN
|
15
|
+
(send
|
16
|
+
nil?
|
17
|
+
:disable_ddl_transaction!
|
18
|
+
...
|
19
|
+
)
|
20
|
+
PATTERN
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# @param corrector [RuboCop::Cop::Corrector]
|
28
|
+
# @param node [RuboCop::AST::SendNode]
|
29
|
+
# @return [void]
|
30
|
+
def insert_disable_ddl_transaction(
|
31
|
+
corrector,
|
32
|
+
node
|
33
|
+
)
|
34
|
+
corrector.insert_before(
|
35
|
+
node.each_ancestor(:def).first,
|
36
|
+
"disable_ddl_transaction!\n\n "
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @param node [RuboCop::AST::SendNode]
|
41
|
+
# @return [Boolean]
|
42
|
+
def within_disable_ddl_transaction?(node)
|
43
|
+
node.each_ancestor(:def).first&.left_siblings&.any? do |sibling|
|
44
|
+
sibling.is_a?(::RuboCop::AST::SendNode) &&
|
45
|
+
disable_ddl_transaction?(sibling)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Migration
|
5
|
+
module CopConcerns
|
6
|
+
autoload :BatchProcessing, 'rubocop/migration/cop_concerns/batch_processing'
|
7
|
+
autoload :ColumnTypeMethod, 'rubocop/migration/cop_concerns/column_type_method'
|
8
|
+
autoload :DisableDdlTransaction, 'rubocop/migration/cop_concerns/disable_ddl_transaction'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
require_relative 'config_loader'
|
6
|
+
|
7
|
+
RuboCop::ConfigLoader.instance_variable_set(
|
8
|
+
:@default_configuration,
|
9
|
+
RuboCop::Migration::ConfigLoader.call(
|
10
|
+
path: ::File.expand_path(
|
11
|
+
'../../../config/default.yml',
|
12
|
+
__dir__
|
13
|
+
)
|
14
|
+
)
|
15
|
+
)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'migration/cop_concerns'
|
4
|
+
require_relative 'migration/rubocop_extension'
|
5
|
+
require_relative 'migration/version'
|
6
|
+
|
7
|
+
require_relative 'cop/migration/add_check_constraint'
|
8
|
+
require_relative 'cop/migration/add_column_with_default_value'
|
9
|
+
require_relative 'cop/migration/add_foreign_key'
|
10
|
+
require_relative 'cop/migration/add_index_columns_count'
|
11
|
+
require_relative 'cop/migration/add_index_concurrently'
|
12
|
+
require_relative 'cop/migration/add_index_duplicate'
|
13
|
+
require_relative 'cop/migration/batch_in_batches'
|
14
|
+
require_relative 'cop/migration/batch_in_transaction'
|
15
|
+
require_relative 'cop/migration/batch_with_throttling'
|
16
|
+
require_relative 'cop/migration/change_column'
|
17
|
+
require_relative 'cop/migration/change_column_null'
|
18
|
+
require_relative 'cop/migration/create_table_force'
|
19
|
+
require_relative 'cop/migration/jsonb'
|
20
|
+
require_relative 'cop/migration/remove_column'
|
21
|
+
require_relative 'cop/migration/rename_column'
|
22
|
+
require_relative 'cop/migration/rename_table'
|
23
|
+
require_relative 'cop/migration/reserved_word_mysql'
|
data/rubocop-migration.gemspec
CHANGED
@@ -1,38 +1,32 @@
|
|
1
|
-
#
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "rubocop/migration/version"
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
spec.name = "rubocop-migration"
|
8
|
-
spec.version = RuboCop::Migration::VERSION
|
9
|
-
spec.authors = ["Peter Graham"]
|
10
|
-
spec.email = ["peter@wealthsimple.com"]
|
3
|
+
require_relative 'lib/rubocop/migration/version'
|
11
4
|
|
12
|
-
|
13
|
-
spec.
|
14
|
-
spec.
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rubocop-migration'
|
7
|
+
spec.version = Rubocop::Migration::VERSION
|
8
|
+
spec.authors = ['Ryo Nakamura']
|
9
|
+
spec.email = ['r7kamura@gmail.com']
|
15
10
|
|
16
|
-
spec.
|
17
|
-
|
18
|
-
|
19
|
-
spec.
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
spec.license = "MIT"
|
11
|
+
spec.summary = 'RuboCop extension focused on ActiveRecord migration.'
|
12
|
+
spec.homepage = 'https://github.com/r7kamura/rubocop-migration'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = '>= 2.7'
|
23
15
|
|
24
|
-
spec.
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/releases"
|
25
19
|
|
26
|
-
spec.
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
spec.files = Dir.chdir(__dir__) do
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
30
28
|
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
spec.add_development_dependency "rspec-its"
|
35
|
-
spec.add_development_dependency "rspec-collection_matchers"
|
36
|
-
spec.add_development_dependency "rspec_junit_formatter", "~> 0.2"
|
37
|
-
spec.add_development_dependency "pry"
|
29
|
+
spec.add_dependency 'activesupport'
|
30
|
+
spec.add_dependency 'rubocop', '>= 1.34'
|
31
|
+
spec.add_dependency 'rubocop-rails'
|
38
32
|
end
|