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
242cb46a
Commit
242cb46a
authored
Dec 04, 2019
by
Andreas Brandl
Committed by
Tiger
Dec 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow add_column_with_default with NOT NULL
See
https://gitlab.com/gitlab-org/gitlab/issues/38060
parent
610aa44c
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
150 additions
and
15 deletions
+150
-15
db/migrate/20180305144721_add_privileged_to_runner.rb
db/migrate/20180305144721_add_privileged_to_runner.rb
+1
-1
db/migrate/20180423204600_add_pages_access_level_to_project_feature.rb
...180423204600_add_pages_access_level_to_project_feature.rb
+1
-1
db/migrate/20180515005612_add_squash_to_merge_requests.rb
db/migrate/20180515005612_add_squash_to_merge_requests.rb
+1
-1
db/migrate/20180529093006_ensure_remote_mirror_columns.rb
db/migrate/20180529093006_ensure_remote_mirror_columns.rb
+1
-1
db/migrate/20180601213245_add_deploy_strategy_to_project_auto_devops.rb
...80601213245_add_deploy_strategy_to_project_auto_devops.rb
+1
-1
db/migrate/20181016141739_add_status_to_deployments.rb
db/migrate/20181016141739_add_status_to_deployments.rb
+1
-1
db/migrate/20190218134158_add_masked_to_ci_variables.rb
db/migrate/20190218134158_add_masked_to_ci_variables.rb
+1
-1
db/migrate/20190218134209_add_masked_to_ci_group_variables.rb
...igrate/20190218134209_add_masked_to_ci_group_variables.rb
+1
-1
db/migrate/20190228192410_add_multi_line_attributes_to_suggestion.rb
...20190228192410_add_multi_line_attributes_to_suggestion.rb
+2
-0
db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb
...190416185130_add_merge_train_enabled_to_ci_cd_settings.rb
+1
-1
db/migrate/20190426180107_add_deployment_events_to_services.rb
...grate/20190426180107_add_deployment_events_to_services.rb
+1
-1
db/migrate/20190709204413_add_rule_type_to_approval_project_rules.rb
...20190709204413_add_rule_type_to_approval_project_rules.rb
+1
-1
db/migrate/20190907184714_add_show_whitespace_in_diffs_to_user_preferences.rb
...84714_add_show_whitespace_in_diffs_to_user_preferences.rb
+1
-1
db/migrate/20190918104731_add_cleanup_status_to_cluster.rb
db/migrate/20190918104731_add_cleanup_status_to_cluster.rb
+1
-1
db/migrate/20191029191901_add_enabled_to_grafana_integrations.rb
...ate/20191029191901_add_enabled_to_grafana_integrations.rb
+1
-1
db/migrate/20191112090226_add_artifacts_to_ci_build_need.rb
db/migrate/20191112090226_add_artifacts_to_ci_build_need.rb
+1
-1
doc/development/what_requires_downtime.md
doc/development/what_requires_downtime.md
+3
-0
rubocop/cop/migration/add_column_with_default.rb
rubocop/cop/migration/add_column_with_default.rb
+64
-0
rubocop/rubocop.rb
rubocop/rubocop.rb
+1
-0
spec/rubocop/cop/migration/add_column_with_default_spec.rb
spec/rubocop/cop/migration/add_column_with_default_spec.rb
+65
-0
No files found.
db/migrate/20180305144721_add_privileged_to_runner.rb
View file @
242cb46a
...
@@ -9,7 +9,7 @@ class AddPrivilegedToRunner < ActiveRecord::Migration[4.2]
...
@@ -9,7 +9,7 @@ class AddPrivilegedToRunner < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:clusters_applications_runners
,
:privileged
,
:boolean
,
default:
true
,
allow_null:
false
add_column_with_default
:clusters_applications_runners
,
:privileged
,
:boolean
,
default:
true
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20180423204600_add_pages_access_level_to_project_feature.rb
View file @
242cb46a
...
@@ -5,7 +5,7 @@ class AddPagesAccessLevelToProjectFeature < ActiveRecord::Migration[4.2]
...
@@ -5,7 +5,7 @@ class AddPagesAccessLevelToProjectFeature < ActiveRecord::Migration[4.2]
DOWNTIME
=
false
DOWNTIME
=
false
def
up
def
up
add_column_with_default
(
:project_features
,
:pages_access_level
,
:integer
,
default:
ProjectFeature
::
PUBLIC
,
allow_null:
false
)
add_column_with_default
(
:project_features
,
:pages_access_level
,
:integer
,
default:
ProjectFeature
::
PUBLIC
,
allow_null:
false
)
# rubocop:disable Migration/AddColumnWithDefault
change_column_default
(
:project_features
,
:pages_access_level
,
ProjectFeature
::
ENABLED
)
change_column_default
(
:project_features
,
:pages_access_level
,
ProjectFeature
::
ENABLED
)
end
end
...
...
db/migrate/20180515005612_add_squash_to_merge_requests.rb
View file @
242cb46a
...
@@ -10,7 +10,7 @@ class AddSquashToMergeRequests < ActiveRecord::Migration[4.2]
...
@@ -10,7 +10,7 @@ class AddSquashToMergeRequests < ActiveRecord::Migration[4.2]
def
up
def
up
unless
column_exists?
(
:merge_requests
,
:squash
)
unless
column_exists?
(
:merge_requests
,
:squash
)
# rubocop:disable Migration/UpdateLargeTable
# rubocop:disable Migration/UpdateLargeTable
add_column_with_default
:merge_requests
,
:squash
,
:boolean
,
default:
false
,
allow_null:
false
add_column_with_default
:merge_requests
,
:squash
,
:boolean
,
default:
false
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
end
end
...
...
db/migrate/20180529093006_ensure_remote_mirror_columns.rb
View file @
242cb46a
...
@@ -11,7 +11,7 @@ class EnsureRemoteMirrorColumns < ActiveRecord::Migration[4.2]
...
@@ -11,7 +11,7 @@ class EnsureRemoteMirrorColumns < ActiveRecord::Migration[4.2]
add_column
:remote_mirrors
,
:remote_name
,
:string
unless
column_exists?
(
:remote_mirrors
,
:remote_name
)
# rubocop:disable Migration/AddLimitToStringColumns
add_column
:remote_mirrors
,
:remote_name
,
:string
unless
column_exists?
(
:remote_mirrors
,
:remote_name
)
# rubocop:disable Migration/AddLimitToStringColumns
unless
column_exists?
(
:remote_mirrors
,
:only_protected_branches
)
unless
column_exists?
(
:remote_mirrors
,
:only_protected_branches
)
add_column_with_default
(
:remote_mirrors
,
add_column_with_default
(
:remote_mirrors
,
# rubocop:disable Migration/AddColumnWithDefault
:only_protected_branches
,
:only_protected_branches
,
:boolean
,
:boolean
,
default:
false
,
default:
false
,
...
...
db/migrate/20180601213245_add_deploy_strategy_to_project_auto_devops.rb
View file @
242cb46a
...
@@ -10,7 +10,7 @@ class AddDeployStrategyToProjectAutoDevops < ActiveRecord::Migration[4.2]
...
@@ -10,7 +10,7 @@ class AddDeployStrategyToProjectAutoDevops < ActiveRecord::Migration[4.2]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:project_auto_devops
,
:deploy_strategy
,
:integer
,
default:
0
,
allow_null:
false
add_column_with_default
:project_auto_devops
,
:deploy_strategy
,
:integer
,
default:
0
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20181016141739_add_status_to_deployments.rb
View file @
242cb46a
...
@@ -15,7 +15,7 @@ class AddStatusToDeployments < ActiveRecord::Migration[4.2]
...
@@ -15,7 +15,7 @@ class AddStatusToDeployments < ActiveRecord::Migration[4.2]
# However, we have to use the default value for avoiding `NOT NULL` violation during the transition period.
# However, we have to use the default value for avoiding `NOT NULL` violation during the transition period.
# The default value should be removed in the future release.
# The default value should be removed in the future release.
def
up
def
up
add_column_with_default
(
:deployments
,
add_column_with_default
(
:deployments
,
# rubocop:disable Migration/AddColumnWithDefault
:status
,
:status
,
:integer
,
:integer
,
limit:
2
,
limit:
2
,
...
...
db/migrate/20190218134158_add_masked_to_ci_variables.rb
View file @
242cb46a
...
@@ -12,7 +12,7 @@ class AddMaskedToCiVariables < ActiveRecord::Migration[5.0]
...
@@ -12,7 +12,7 @@ class AddMaskedToCiVariables < ActiveRecord::Migration[5.0]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:ci_variables
,
:masked
,
:boolean
,
default:
false
,
allow_null:
false
add_column_with_default
:ci_variables
,
:masked
,
:boolean
,
default:
false
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190218134209_add_masked_to_ci_group_variables.rb
View file @
242cb46a
...
@@ -12,7 +12,7 @@ class AddMaskedToCiGroupVariables < ActiveRecord::Migration[5.0]
...
@@ -12,7 +12,7 @@ class AddMaskedToCiGroupVariables < ActiveRecord::Migration[5.0]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:ci_group_variables
,
:masked
,
:boolean
,
default:
false
,
allow_null:
false
add_column_with_default
:ci_group_variables
,
:masked
,
:boolean
,
default:
false
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190228192410_add_multi_line_attributes_to_suggestion.rb
View file @
242cb46a
...
@@ -8,9 +8,11 @@ class AddMultiLineAttributesToSuggestion < ActiveRecord::Migration[5.0]
...
@@ -8,9 +8,11 @@ class AddMultiLineAttributesToSuggestion < ActiveRecord::Migration[5.0]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
# rubocop:disable Migration/AddColumnWithDefault
add_column_with_default
:suggestions
,
:lines_above
,
:integer
,
default:
0
,
allow_null:
false
add_column_with_default
:suggestions
,
:lines_above
,
:integer
,
default:
0
,
allow_null:
false
add_column_with_default
:suggestions
,
:lines_below
,
:integer
,
default:
0
,
allow_null:
false
add_column_with_default
:suggestions
,
:lines_below
,
:integer
,
default:
0
,
allow_null:
false
add_column_with_default
:suggestions
,
:outdated
,
:boolean
,
default:
false
,
allow_null:
false
add_column_with_default
:suggestions
,
:outdated
,
:boolean
,
default:
false
,
allow_null:
false
# rubocop:enable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190416185130_add_merge_train_enabled_to_ci_cd_settings.rb
View file @
242cb46a
...
@@ -8,7 +8,7 @@ class AddMergeTrainEnabledToCiCdSettings < ActiveRecord::Migration[5.1]
...
@@ -8,7 +8,7 @@ class AddMergeTrainEnabledToCiCdSettings < ActiveRecord::Migration[5.1]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:project_ci_cd_settings
,
:merge_trains_enabled
,
:boolean
,
default:
false
,
allow_null:
false
add_column_with_default
:project_ci_cd_settings
,
:merge_trains_enabled
,
:boolean
,
default:
false
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190426180107_add_deployment_events_to_services.rb
View file @
242cb46a
...
@@ -8,7 +8,7 @@ class AddDeploymentEventsToServices < ActiveRecord::Migration[5.0]
...
@@ -8,7 +8,7 @@ class AddDeploymentEventsToServices < ActiveRecord::Migration[5.0]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
(
:services
,
:deployment_events
,
:boolean
,
default:
false
,
allow_null:
false
)
add_column_with_default
(
:services
,
:deployment_events
,
:boolean
,
default:
false
,
allow_null:
false
)
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190709204413_add_rule_type_to_approval_project_rules.rb
View file @
242cb46a
...
@@ -8,7 +8,7 @@ class AddRuleTypeToApprovalProjectRules < ActiveRecord::Migration[5.1]
...
@@ -8,7 +8,7 @@ class AddRuleTypeToApprovalProjectRules < ActiveRecord::Migration[5.1]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:approval_project_rules
,
:rule_type
,
:integer
,
limit:
2
,
default:
0
,
allow_null:
false
add_column_with_default
:approval_project_rules
,
:rule_type
,
:integer
,
limit:
2
,
default:
0
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190907184714_add_show_whitespace_in_diffs_to_user_preferences.rb
View file @
242cb46a
...
@@ -11,7 +11,7 @@ class AddShowWhitespaceInDiffsToUserPreferences < ActiveRecord::Migration[5.2]
...
@@ -11,7 +11,7 @@ class AddShowWhitespaceInDiffsToUserPreferences < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
:user_preferences
,
:show_whitespace_in_diffs
,
:boolean
,
default:
true
,
allow_null:
false
add_column_with_default
:user_preferences
,
:show_whitespace_in_diffs
,
:boolean
,
default:
true
,
allow_null:
false
# rubocop:disable Migration/AddColumnWithDefault
end
end
def
down
def
down
...
...
db/migrate/20190918104731_add_cleanup_status_to_cluster.rb
View file @
242cb46a
...
@@ -9,7 +9,7 @@ class AddCleanupStatusToCluster < ActiveRecord::Migration[5.2]
...
@@ -9,7 +9,7 @@ class AddCleanupStatusToCluster < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
(
:clusters
,
:cleanup_status
,
add_column_with_default
(
:clusters
,
:cleanup_status
,
# rubocop:disable Migration/AddColumnWithDefault
:smallint
,
:smallint
,
default:
1
,
default:
1
,
allow_null:
false
)
allow_null:
false
)
...
...
db/migrate/20191029191901_add_enabled_to_grafana_integrations.rb
View file @
242cb46a
...
@@ -8,7 +8,7 @@ class AddEnabledToGrafanaIntegrations < ActiveRecord::Migration[5.2]
...
@@ -8,7 +8,7 @@ class AddEnabledToGrafanaIntegrations < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
(
add_column_with_default
(
# rubocop:disable Migration/AddColumnWithDefault
:grafana_integrations
,
:grafana_integrations
,
:enabled
,
:enabled
,
:boolean
,
:boolean
,
...
...
db/migrate/20191112090226_add_artifacts_to_ci_build_need.rb
View file @
242cb46a
...
@@ -8,7 +8,7 @@ class AddArtifactsToCiBuildNeed < ActiveRecord::Migration[5.2]
...
@@ -8,7 +8,7 @@ class AddArtifactsToCiBuildNeed < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
add_column_with_default
(
:ci_build_needs
,
:artifacts
,
add_column_with_default
(
:ci_build_needs
,
:artifacts
,
# rubocop:disable Migration/AddColumnWithDefault
:boolean
,
:boolean
,
default:
true
,
default:
true
,
allow_null:
false
)
allow_null:
false
)
...
...
doc/development/what_requires_downtime.md
View file @
242cb46a
...
@@ -34,6 +34,9 @@ blocking access to the table being modified. See ["Adding Columns With Default
...
@@ -34,6 +34,9 @@ blocking access to the table being modified. See ["Adding Columns With Default
Values"
](
migration_style_guide.md#adding-columns-with-default-values
)
for more
Values"
](
migration_style_guide.md#adding-columns-with-default-values
)
for more
information on how to use this method.
information on how to use this method.
Note that usage of
`add_column_with_default`
with
`allow_null: false`
to also add
a
`NOT NULL`
constraint is
[
discouraged
](
https://gitlab.com/gitlab-org/gitlab/issues/38060
)
.
## Dropping Columns
## Dropping Columns
Removing columns is tricky because running GitLab processes may still be using
Removing columns is tricky because running GitLab processes may still be using
...
...
rubocop/cop/migration/add_column_with_default.rb
0 → 100644
View file @
242cb46a
# frozen_string_literal: true
require_relative
'../../migration_helpers'
module
RuboCop
module
Cop
module
Migration
# Cop that checks if columns are added in a way that doesn't require
# downtime.
class
AddColumnWithDefault
<
RuboCop
::
Cop
::
Cop
include
MigrationHelpers
WHITELISTED_TABLES
=
[
:application_settings
].
freeze
MSG
=
'`add_column_with_default` with `allow_null: false` may cause prolonged lock situations and downtime, '
\
'see https://gitlab.com/gitlab-org/gitlab/issues/38060'
.
freeze
def
on_send
(
node
)
return
unless
in_migration?
(
node
)
name
=
node
.
children
[
1
]
return
unless
name
==
:add_column_with_default
# Ignore whitelisted tables.
return
if
table_whitelisted?
(
node
.
children
[
2
])
opts
=
node
.
children
.
last
return
unless
opts
&&
opts
.
type
==
:hash
opts
.
each_node
(
:pair
)
do
|
pair
|
if
disallows_null_values?
(
pair
)
add_offense
(
node
,
location: :selector
)
end
end
end
def
table_whitelisted?
(
symbol
)
symbol
&&
symbol
.
type
==
:sym
&&
WHITELISTED_TABLES
.
include?
(
symbol
.
children
[
0
])
end
def
disallows_null_values?
(
pair
)
options
=
[
hash_key_type
(
pair
),
hash_key_name
(
pair
),
hash_value
(
pair
)]
options
==
[
:sym
,
:allow_null
,
:false
]
# rubocop:disable Lint/BooleanSymbol
end
def
hash_key_type
(
pair
)
pair
.
children
[
0
].
type
end
def
hash_key_name
(
pair
)
pair
.
children
[
0
].
children
[
0
]
end
def
hash_value
(
pair
)
pair
.
children
[
1
].
type
end
end
end
end
end
rubocop/rubocop.rb
View file @
242cb46a
...
@@ -17,6 +17,7 @@ require_relative 'cop/prefer_class_methods_over_module'
...
@@ -17,6 +17,7 @@ require_relative 'cop/prefer_class_methods_over_module'
require_relative
'cop/put_project_routes_under_scope'
require_relative
'cop/put_project_routes_under_scope'
require_relative
'cop/put_group_routes_under_scope'
require_relative
'cop/put_group_routes_under_scope'
require_relative
'cop/migration/add_column'
require_relative
'cop/migration/add_column'
require_relative
'cop/migration/add_column_with_default'
require_relative
'cop/migration/add_concurrent_foreign_key'
require_relative
'cop/migration/add_concurrent_foreign_key'
require_relative
'cop/migration/add_concurrent_index'
require_relative
'cop/migration/add_concurrent_index'
require_relative
'cop/migration/add_index'
require_relative
'cop/migration/add_index'
...
...
spec/rubocop/cop/migration/add_column_with_default_spec.rb
0 → 100644
View file @
242cb46a
# frozen_string_literal: true
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../../rubocop/cop/migration/add_column_with_default'
describe
RuboCop
::
Cop
::
Migration
::
AddColumnWithDefault
do
include
CopHelper
let
(
:cop
)
{
described_class
.
new
}
context
'outside of a migration'
do
it
'does not register any offenses'
do
expect_no_offenses
(
<<~
RUBY
)
def up
add_reference(:projects, :users)
end
RUBY
end
end
context
'in a migration'
do
before
do
allow
(
cop
).
to
receive
(
:in_migration?
).
and_return
(
true
)
end
let
(
:offense
)
{
'`add_column_with_default` with `allow_null: false` may cause prolonged lock situations and downtime, see https://gitlab.com/gitlab-org/gitlab/issues/38060'
}
it
'registers an offense when specifying allow_null: false'
do
expect_offense
(
<<~
RUBY
)
def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: false)
^^^^^^^^^^^^^^^^^^^^^^^
#{
offense
}
end
RUBY
end
it
'registers no offense when specifying allow_null: true'
do
expect_no_offenses
(
<<~
RUBY
)
def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: true)
end
RUBY
end
it
'registers no offense when allow_null is not specified'
do
expect_no_offenses
(
<<~
RUBY
)
def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true)
end
RUBY
end
it
'registers no offense for application_settings (whitelisted table)'
do
expect_no_offenses
(
<<~
RUBY
)
def up
add_column_with_default(:application_settings, :another_column, :boolean, default: true, allow_null: false)
end
RUBY
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