Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
17e6c71e
Commit
17e6c71e
authored
Jun 05, 2020
by
Doug Stull
Committed by
Mayra Cabrera
Jun 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use upstream version of update large table cop
- also remove the exception on add_column_concurrently
parent
eb63ad83
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
180 deletions
+44
-180
.rubocop.yml
.rubocop.yml
+4
-1
rubocop/cop/migration/update_large_table.rb
rubocop/cop/migration/update_large_table.rb
+0
-49
rubocop/migration_helpers.rb
rubocop/migration_helpers.rb
+0
-39
rubocop/rubocop-migrations.yml
rubocop/rubocop-migrations.yml
+40
-0
spec/rubocop/cop/migration/update_large_table_spec.rb
spec/rubocop/cop/migration/update_large_table_spec.rb
+0
-91
No files found.
.rubocop.yml
View file @
17e6c71e
...
...
@@ -2,11 +2,14 @@ inherit_gem:
gitlab-styles
:
-
rubocop-default.yml
inherit_from
:
.rubocop_todo.yml
require
:
-
./rubocop/rubocop
-
rubocop-rspec
inherit_from
:
-
.rubocop_todo.yml
-
./rubocop/rubocop-migrations.yml
inherit_mode
:
merge
:
-
Include
...
...
rubocop/cop/migration/update_large_table.rb
deleted
100644 → 0
View file @
eb63ad83
require_relative
'../../migration_helpers'
module
RuboCop
module
Cop
module
Migration
# This cop checks for `add_column_with_default` on a table that's been
# explicitly blacklisted because of its size.
#
# Even though this helper performs the update in batches to avoid
# downtime, using it with tables with millions of rows still causes a
# significant delay in the deploy process and is best avoided.
#
# See https://gitlab.com/gitlab-com/infrastructure/issues/1602 for more
# information.
class
UpdateLargeTable
<
RuboCop
::
Cop
::
Cop
include
MigrationHelpers
MSG
=
'Using `%s` on the `%s` table will take a long time to '
\
'complete, and should be avoided unless absolutely '
\
'necessary'
.
freeze
BATCH_UPDATE_METHODS
=
%w[
:add_column_with_default
:change_column_type_concurrently
:rename_column_concurrently
:update_column_in_batches
]
.
join
(
' '
).
freeze
def_node_matcher
:batch_update?
,
<<~
PATTERN
(send nil? ${
#{
BATCH_UPDATE_METHODS
}
} $(sym ...) ...)
PATTERN
def
on_send
(
node
)
return
unless
in_migration?
(
node
)
matches
=
batch_update?
(
node
)
return
unless
matches
update_method
=
matches
.
first
table
=
matches
.
last
.
to_a
.
first
return
unless
BLACKLISTED_TABLES
.
include?
(
table
)
add_offense
(
node
,
location: :expression
,
message:
format
(
MSG
,
update_method
,
table
))
end
end
end
end
end
rubocop/migration_helpers.rb
View file @
17e6c71e
...
...
@@ -6,45 +6,6 @@ module RuboCop
plan_limits
]
.
freeze
# Blacklisted tables due to:
# - size in GB (>= 10 GB on GitLab.com as of 02/2020)
# - number of records
BLACKLISTED_TABLES
=
%i[
audit_events
ci_build_trace_sections
ci_builds
ci_builds_metadata
ci_job_artifacts
ci_pipeline_variables
ci_pipelines
ci_stages
deployments
events
issues
merge_request_diff_commits
merge_request_diff_files
merge_request_diffs
merge_request_metrics
merge_requests
namespaces
note_diff_files
notes
project_authorizations
projects
project_ci_cd_settings
project_features
push_event_payloads
resource_label_events
routes
sent_notifications
services
system_note_metadata
taggings
todos
users
web_hook_logs
]
.
freeze
# Blacklisted tables due to:
# - number of columns (> 50 on GitLab.com as of 03/2020)
# - number of records
...
...
rubocop/rubocop-migrations.yml
0 → 100644
View file @
17e6c71e
Migration/UpdateLargeTable
:
Enabled
:
true
DeniedTables
:
&denied_tables
# size in GB (>= 10 GB on GitLab.com as of 02/2020) and/or number of records
-
:audit_events
-
:ci_build_trace_sections
-
:ci_builds
-
:ci_builds_metadata
-
:ci_job_artifacts
-
:ci_pipeline_variables
-
:ci_pipelines
-
:ci_stages
-
:deployments
-
:events
-
:issues
-
:merge_request_diff_commits
-
:merge_request_diff_files
-
:merge_request_diffs
-
:merge_request_metrics
-
:merge_requests
-
:namespaces
-
:note_diff_files
-
:notes
-
:project_authorizations
-
:projects
-
:project_ci_cd_settings
-
:project_features
-
:push_event_payloads
-
:resource_label_events
-
:routes
-
:sent_notifications
-
:services
-
:system_note_metadata
-
:taggings
-
:todos
-
:users
-
:web_hook_logs
DeniedMethods
:
-
:change_column_type_concurrently
-
:rename_column_concurrently
-
:update_column_in_batches
spec/rubocop/cop/migration/update_large_table_spec.rb
deleted
100644 → 0
View file @
eb63ad83
# frozen_string_literal: true
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../../rubocop/cop/migration/update_large_table'
describe
RuboCop
::
Cop
::
Migration
::
UpdateLargeTable
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
context
'in migration'
do
before
do
allow
(
cop
).
to
receive
(
:in_migration?
).
and_return
(
true
)
end
shared_examples
'large tables'
do
|
update_method
|
described_class
::
BLACKLISTED_TABLES
.
each
do
|
table
|
it
"registers an offense for the
#{
table
}
table"
do
inspect_source
(
"
#{
update_method
}
:
#{
table
}
, :column, default: true"
)
aggregate_failures
do
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
expect
(
cop
.
offenses
.
map
(
&
:line
)).
to
eq
([
1
])
end
end
end
end
context
'for the add_column_with_default method'
do
include_examples
'large tables'
,
'add_column_with_default'
end
context
'for the change_column_type_concurrently method'
do
include_examples
'large tables'
,
'change_column_type_concurrently'
end
context
'for the rename_column_concurrently method'
do
include_examples
'large tables'
,
'rename_column_concurrently'
end
context
'for the update_column_in_batches method'
do
include_examples
'large tables'
,
'update_column_in_batches'
end
it
'registers no offense for non-blacklisted tables'
do
inspect_source
(
"add_column_with_default :table, :column, default: true"
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
'registers no offense for non-blacklisted methods'
do
table
=
described_class
::
BLACKLISTED_TABLES
.
sample
inspect_source
(
"some_other_method :
#{
table
}
, :column, default: true"
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
context
'outside of migration'
do
let
(
:table
)
{
described_class
::
BLACKLISTED_TABLES
.
sample
}
it
'registers no offense for add_column_with_default'
do
inspect_source
(
"add_column_with_default :
#{
table
}
, :column, default: true"
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
'registers no offense for change_column_type_concurrently'
do
inspect_source
(
"change_column_type_concurrently :
#{
table
}
, :column, default: true"
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
'registers no offense for rename_column_concurrently'
do
inspect_source
(
"rename_column_concurrently :
#{
table
}
, :column, default: true"
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
'registers no offense for update_column_concurrently'
do
inspect_source
(
"update_column_concurrently :
#{
table
}
, :column, default: true"
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment