gitlab-styles 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d23f16df66558ac47e1084f4558dbf68589e7c81a3e99056e193500962c6608
4
- data.tar.gz: 0aedb037f3ef8a90a2c3c0c80945949832eaa52da9ec5c3f872d8fc24157f300
3
+ metadata.gz: 2ffa11a484785184125888f8cc6716080d991e43672b0fb173aa7752ca67caba
4
+ data.tar.gz: 4e4a4d2349213d8696f838893865d6ebe4f7a865bc61355977c37f32ac4748dd
5
5
  SHA512:
6
- metadata.gz: 478c9a5284aeb471ca82131d10496ce730126c1a66fb87f6a369153bb4ef65850fef4a92834cc5ac23ea66ef000afdbc2803a05fded8332a14eee08673aa4c36
7
- data.tar.gz: 1675434965d80d42e2ffd7fff89eb84460d6bc70c4971e3fcf826273a118a55967a96446addf8454d851ebbbf097adf33a5f0498de1fb8c4b2e63b47a8ca103a
6
+ metadata.gz: 3568f7eb05f54bcf76640c2a6a53149e4ffc73f0affb6840f2dfc43c59152db7ca7c60b3d06441cfc0399ba1cce8bd23c3667549174ba5c3f282b6be721bf091
7
+ data.tar.gz: ae89b5dd974632887e8142fcf9a89bb511ddbab969380ba6abd4daa990d3ad67916e95cb39c7394f659a8b9e787257270c557a6fa9579def27f3fcd2e578d364
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ group :test do
9
9
  # Pin these dependencies, otherwise a new rule could break the CI pipelines
10
10
  gem 'rubocop', '0.82.0'
11
11
  gem 'rubocop-rspec', '1.36.0'
12
+ gem 'rspec-parameterized', '0.4.2', require: false
12
13
  end
data/README.md CHANGED
@@ -42,6 +42,7 @@ rules:
42
42
  - `rubocop-gemspec.yml`
43
43
  - `rubocop-layout.yml`
44
44
  - `rubocop-lint.yml`
45
+ - `rubocop-migrations.yml`
45
46
  - `rubocop-metrics.yml`
46
47
  - `rubocop-naming.yml`
47
48
  - `rubocop-performance.yml`
@@ -8,6 +8,7 @@ require 'gitlab/styles/rubocop/cop/polymorphic_associations'
8
8
  require 'gitlab/styles/rubocop/cop/active_record_dependent'
9
9
  require 'gitlab/styles/rubocop/cop/in_batches'
10
10
  require 'gitlab/styles/rubocop/cop/line_break_after_guard_clauses'
11
+ require 'gitlab/styles/rubocop/cop/migration/update_large_table'
11
12
  require 'gitlab/styles/rubocop/cop/without_reactive_cache'
12
13
  require 'gitlab/styles/rubocop/cop/rspec/single_line_hook'
13
14
  require 'gitlab/styles/rubocop/cop/rspec/have_link_parameters'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../../migration_helpers'
3
+
4
+ module Gitlab
5
+ module Styles
6
+ module Rubocop
7
+ module Cop
8
+ module Migration
9
+ # This cop checks for methods that may lead to batch type issues on a table that's been
10
+ # explicitly denied because of its size.
11
+ #
12
+ # Even though though these methods perform functions to avoid
13
+ # downtime, using it with tables with millions of rows still causes a
14
+ # significant delay in the deploy process and is best avoided.
15
+ #
16
+ # See https://gitlab.com/gitlab-com/infrastructure/issues/1602 for more
17
+ # information.
18
+ class UpdateLargeTable < RuboCop::Cop::Cop
19
+ include MigrationHelpers
20
+
21
+ MSG = 'Using `%s` on the `%s` table will take a long time to ' \
22
+ 'complete, and should be avoided unless absolutely ' \
23
+ 'necessary'
24
+
25
+ def_node_matcher :batch_update?, <<~PATTERN
26
+ (send nil? ${#denied_method?}
27
+ (sym $...)
28
+ ...)
29
+ PATTERN
30
+
31
+ def on_send(node)
32
+ return if denied_tables.empty? || denied_methods.empty?
33
+ return unless in_migration?(node)
34
+
35
+ matches = batch_update?(node)
36
+ return unless matches
37
+
38
+ update_method = matches.first
39
+ table = matches.last.to_a.first
40
+
41
+ return unless denied_tables.include?(table)
42
+
43
+ add_offense(node, location: :expression, message: format(MSG, update_method, table))
44
+ end
45
+
46
+ private
47
+
48
+ def denied_tables
49
+ cop_config['DeniedTables'] || []
50
+ end
51
+
52
+ def denied_method?(method_name)
53
+ denied_methods.include?(method_name)
54
+ end
55
+
56
+ def denied_methods
57
+ cop_config['DeniedMethods'] || []
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module Styles
5
- VERSION = '4.0.0'
5
+ VERSION = '4.1.0'
6
6
  end
7
7
  end
@@ -12,6 +12,7 @@ inherit_from:
12
12
  - rubocop-layout.yml
13
13
  - rubocop-lint.yml
14
14
  - rubocop-metrics.yml
15
+ - rubocop-migrations.yml
15
16
  - rubocop-naming.yml
16
17
  - rubocop-performance.yml
17
18
  - rubocop-rails.yml
@@ -0,0 +1,21 @@
1
+ # Checks for methods that may lead to batch type issues on a table that's been
2
+ # explicitly denied because of its size.
3
+ #
4
+ # Even though these methods perform functions to avoid
5
+ # downtime, using it with tables with millions of rows still causes a
6
+ # significant delay in the deploy process and is best avoided.
7
+ #
8
+ # See https://gitlab.com/gitlab-com/infrastructure/issues/1602 for more
9
+ # information.
10
+ # The default can be changed as follows:
11
+ # Migration/UpdateLargeTable:
12
+ # DeniedTables:
13
+ # - :usage_data
14
+ # - :version_checks
15
+ # DeniedMethods:
16
+ # - :add_column_with_default
17
+ # - :change_column_type_concurrently
18
+ # - :rename_column_concurrently
19
+ # - :update_column_in_batches
20
+ Migration/UpdateLargeTable:
21
+ Enabled: false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-styles
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2020-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -152,6 +152,7 @@ files:
152
152
  - lib/gitlab/styles/rubocop/cop/gem_fetcher.rb
153
153
  - lib/gitlab/styles/rubocop/cop/in_batches.rb
154
154
  - lib/gitlab/styles/rubocop/cop/line_break_after_guard_clauses.rb
155
+ - lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb
155
156
  - lib/gitlab/styles/rubocop/cop/polymorphic_associations.rb
156
157
  - lib/gitlab/styles/rubocop/cop/redirect_with_status.rb
157
158
  - lib/gitlab/styles/rubocop/cop/rspec/have_link_parameters.rb
@@ -168,6 +169,7 @@ files:
168
169
  - rubocop-layout.yml
169
170
  - rubocop-lint.yml
170
171
  - rubocop-metrics.yml
172
+ - rubocop-migrations.yml
171
173
  - rubocop-naming.yml
172
174
  - rubocop-performance.yml
173
175
  - rubocop-rails.yml