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.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +58 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/Gemfile +11 -1
  6. data/Gemfile.lock +89 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +41 -21
  9. data/Rakefile +9 -3
  10. data/config/default.yml +151 -0
  11. data/data/reserved_words_mysql.txt +750 -0
  12. data/lib/rubocop/cop/migration/add_check_constraint.rb +111 -0
  13. data/lib/rubocop/cop/migration/add_column_with_default_value.rb +229 -0
  14. data/lib/rubocop/cop/migration/add_foreign_key.rb +166 -0
  15. data/lib/rubocop/cop/migration/add_index_columns_count.rb +114 -0
  16. data/lib/rubocop/cop/migration/add_index_concurrently.rb +164 -0
  17. data/lib/rubocop/cop/migration/add_index_duplicate.rb +183 -0
  18. data/lib/rubocop/cop/migration/batch_in_batches.rb +95 -0
  19. data/lib/rubocop/cop/migration/batch_in_transaction.rb +83 -0
  20. data/lib/rubocop/cop/migration/batch_with_throttling.rb +108 -0
  21. data/lib/rubocop/cop/migration/change_column.rb +113 -0
  22. data/lib/rubocop/cop/migration/change_column_null.rb +128 -0
  23. data/lib/rubocop/cop/migration/create_table_force.rb +89 -0
  24. data/lib/rubocop/cop/migration/jsonb.rb +131 -0
  25. data/lib/rubocop/cop/migration/remove_column.rb +246 -0
  26. data/lib/rubocop/cop/migration/rename_column.rb +81 -0
  27. data/lib/rubocop/cop/migration/rename_table.rb +79 -0
  28. data/lib/rubocop/cop/migration/reserved_word_mysql.rb +232 -0
  29. data/lib/rubocop/migration/config_loader.rb +51 -0
  30. data/lib/rubocop/migration/cop_concerns/batch_processing.rb +34 -0
  31. data/lib/rubocop/migration/cop_concerns/column_type_method.rb +28 -0
  32. data/lib/rubocop/migration/cop_concerns/disable_ddl_transaction.rb +51 -0
  33. data/lib/rubocop/migration/cop_concerns.rb +11 -0
  34. data/lib/rubocop/migration/rubocop_extension.rb +15 -0
  35. data/lib/rubocop/migration/version.rb +4 -2
  36. data/lib/rubocop/migration.rb +23 -0
  37. data/rubocop-migration.gemspec +25 -29
  38. metadata +50 -108
  39. data/.gitignore +0 -15
  40. data/bin/console +0 -14
  41. data/bin/setup +0 -8
  42. data/circle.yml +0 -6
  43. data/lib/rubocop/cop/migration/add_index_non_concurrently.rb +0 -66
  44. data/lib/rubocop-migration.rb +0 -11
  45. 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.1.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
- - Peter Graham
7
+ - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-07 00:00:00.000000000 Z
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: '4'
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: '4'
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: 0.48.0
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: 0.48.0
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: rspec
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: :development
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: RuboCop extension to catch common pitfalls in ActiveRecord migrations.
55
+ description:
140
56
  email:
141
- - peter@wealthsimple.com
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
- - bin/console
152
- - bin/setup
153
- - circle.yml
154
- - lib/rubocop-migration.rb
155
- - lib/rubocop/cop/migration/add_index_non_concurrently.rb
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
- - vendor/.gitkeep
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.3.0
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
- rubyforge_project:
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 for ActiveRecord migrations.
124
+ summary: RuboCop extension focused on ActiveRecord migration.
183
125
  test_files: []
data/.gitignore DELETED
@@ -1,15 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
13
-
14
- /vendor/rubocop
15
- *.gem
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
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/circle.yml DELETED
@@ -1,6 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.3.0
4
- dependencies:
5
- pre:
6
- - git clone --depth 1 git://github.com/bbatsov/rubocop.git vendor/rubocop
@@ -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
@@ -1,11 +0,0 @@
1
- require "active_support"
2
- require "active_support/core_ext"
3
- require "rubocop"
4
-
5
- require "rubocop/migration/version"
6
- require "rubocop/cop/migration/add_index_non_concurrently"
7
-
8
- module RuboCop
9
- module Migration
10
- end
11
- end
data/vendor/.gitkeep DELETED
File without changes