gitlab-styles 4.0.0 → 4.1.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/Gemfile +1 -0
- data/README.md +1 -0
- data/lib/gitlab/styles/rubocop.rb +1 -0
- data/lib/gitlab/styles/rubocop/cop/migration/update_large_table.rb +64 -0
- data/lib/gitlab/styles/version.rb +1 -1
- data/rubocop-default.yml +1 -0
- data/rubocop-migrations.yml +21 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ffa11a484785184125888f8cc6716080d991e43672b0fb173aa7752ca67caba
|
4
|
+
data.tar.gz: 4e4a4d2349213d8696f838893865d6ebe4f7a865bc61355977c37f32ac4748dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3568f7eb05f54bcf76640c2a6a53149e4ffc73f0affb6840f2dfc43c59152db7ca7c60b3d06441cfc0399ba1cce8bd23c3667549174ba5c3f282b6be721bf091
|
7
|
+
data.tar.gz: ae89b5dd974632887e8142fcf9a89bb511ddbab969380ba6abd4daa990d3ad67916e95cb39c7394f659a8b9e787257270c557a6fa9579def27f3fcd2e578d364
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -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
|
data/rubocop-default.yml
CHANGED
@@ -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.
|
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-
|
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
|