Commit 881c9510 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch 'ab/blacklist-add-column-with-default' into 'master'

Blacklist tables for add_column_with_default

See merge request gitlab-org/gitlab!25882
parents e7801a83 7a8d2500
...@@ -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 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :clusters_applications_runners, :privileged, :boolean, default: true, allow_null: false
end end
def down def down
......
...@@ -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) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:project_features, :pages_access_level, :integer, default: ProjectFeature::PUBLIC, allow_null: false)
change_column_default(:project_features, :pages_access_level, ProjectFeature::ENABLED) change_column_default(:project_features, :pages_access_level, ProjectFeature::ENABLED)
end end
......
...@@ -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, # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:remote_mirrors,
:only_protected_branches, :only_protected_branches,
:boolean, :boolean,
default: false, default: false,
......
...@@ -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 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :project_auto_devops, :deploy_strategy, :integer, default: 0, allow_null: false
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddCommonToPrometheusMetrics < ActiveRecord::Migration[4.2] ...@@ -8,7 +8,7 @@ class AddCommonToPrometheusMetrics < ActiveRecord::Migration[4.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:prometheus_metrics, :common, :boolean, default: false) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:prometheus_metrics, :common, :boolean, default: false)
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddLegacyAbacToClusterProvidersGcp < ActiveRecord::Migration[4.2] ...@@ -8,7 +8,7 @@ class AddLegacyAbacToClusterProvidersGcp < ActiveRecord::Migration[4.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:cluster_providers_gcp, :legacy_abac, :boolean, default: true) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:cluster_providers_gcp, :legacy_abac, :boolean, default: true)
end end
def down def down
......
...@@ -9,7 +9,7 @@ class AddClusterTypeToClusters < ActiveRecord::Migration[4.2] ...@@ -9,7 +9,7 @@ class AddClusterTypeToClusters < ActiveRecord::Migration[4.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:clusters, :cluster_type, :smallint, default: PROJECT_CLUSTER_TYPE) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:clusters, :cluster_type, :smallint, default: PROJECT_CLUSTER_TYPE)
end end
def down def down
......
...@@ -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 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :ci_variables, :masked, :boolean, default: false, allow_null: false
end end
def down def down
......
...@@ -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 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :ci_group_variables, :masked, :boolean, default: false, allow_null: false
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddEmailHeaderAndFooterEnabledFlagToAppearancesTable < ActiveRecord::Migra ...@@ -8,7 +8,7 @@ class AddEmailHeaderAndFooterEnabledFlagToAppearancesTable < ActiveRecord::Migra
DOWNTIME = false DOWNTIME = false
def up def up
add_column_with_default(:appearances, :email_header_and_footer_enabled, :boolean, default: false) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:appearances, :email_header_and_footer_enabled, :boolean, default: false)
end end
def down def down
......
...@@ -8,11 +8,9 @@ class AddMultiLineAttributesToSuggestion < ActiveRecord::Migration[5.0] ...@@ -8,11 +8,9 @@ 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
......
...@@ -8,7 +8,7 @@ class AddAutoSslEnabledToPagesDomain < ActiveRecord::Migration[5.0] ...@@ -8,7 +8,7 @@ class AddAutoSslEnabledToPagesDomain < ActiveRecord::Migration[5.0]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :pages_domains, :auto_ssl_enabled, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :pages_domains, :auto_ssl_enabled, :boolean, default: false
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddManagedToCluster < ActiveRecord::Migration[5.0] ...@@ -8,7 +8,7 @@ class AddManagedToCluster < ActiveRecord::Migration[5.0]
DOWNTIME = false DOWNTIME = false
def up def up
add_column_with_default(:clusters, :managed, :boolean, default: true) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:clusters, :managed, :boolean, default: true)
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddVariableTypeToCiVariables < ActiveRecord::Migration[5.0] ...@@ -8,7 +8,7 @@ class AddVariableTypeToCiVariables < ActiveRecord::Migration[5.0]
ENV_VAR_VARIABLE_TYPE = 1 ENV_VAR_VARIABLE_TYPE = 1
def up def up
add_column_with_default(:ci_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:ci_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE)
end end
def down def down
......
...@@ -8,12 +8,10 @@ class AddMergeTrainEnabledToCiCdSettings < ActiveRecord::Migration[5.1] ...@@ -8,12 +8,10 @@ class AddMergeTrainEnabledToCiCdSettings < ActiveRecord::Migration[5.1]
disable_ddl_transaction! disable_ddl_transaction!
# rubocop:disable Migration/UpdateLargeTable # rubocop:disable Migration/UpdateLargeTable
# rubocop:disable Migration/AddColumnWithDefault
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
end end
# rubocop:enable Migration/UpdateLargeTable # rubocop:enable Migration/UpdateLargeTable
# rubocop:enable Migration/AddColumnWithDefault
def down def down
remove_column :project_ci_cd_settings, :merge_trains_enabled remove_column :project_ci_cd_settings, :merge_trains_enabled
......
...@@ -8,7 +8,7 @@ class AddVariableTypeToCiGroupVariables < ActiveRecord::Migration[5.0] ...@@ -8,7 +8,7 @@ class AddVariableTypeToCiGroupVariables < ActiveRecord::Migration[5.0]
ENV_VAR_VARIABLE_TYPE = 1 ENV_VAR_VARIABLE_TYPE = 1
def up def up
add_column_with_default(:ci_group_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:ci_group_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE)
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddVariableTypeToCiPipelineScheduleVariables < ActiveRecord::Migration[5.0 ...@@ -8,7 +8,7 @@ class AddVariableTypeToCiPipelineScheduleVariables < ActiveRecord::Migration[5.0
ENV_VAR_VARIABLE_TYPE = 1 ENV_VAR_VARIABLE_TYPE = 1
def up def up
add_column_with_default(:ci_pipeline_schedule_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:ci_pipeline_schedule_variables, :variable_type, :smallint, default: ENV_VAR_VARIABLE_TYPE)
end end
def down def down
......
...@@ -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) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:services, :deployment_events, :boolean, default: false, allow_null: false)
end end
def down def down
......
...@@ -12,7 +12,7 @@ class AddRuleTypeToApprovalMergeRequestApprovalRules < ActiveRecord::Migration[5 ...@@ -12,7 +12,7 @@ class AddRuleTypeToApprovalMergeRequestApprovalRules < ActiveRecord::Migration[5
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:approval_merge_request_rules, :rule_type, :integer, limit: 2, default: 1) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:approval_merge_request_rules, :rule_type, :integer, limit: 2, default: 1)
end end
def down def down
......
...@@ -12,7 +12,7 @@ class AddSourceToPagesDomains < ActiveRecord::Migration[5.1] ...@@ -12,7 +12,7 @@ class AddSourceToPagesDomains < ActiveRecord::Migration[5.1]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:pages_domains, :certificate_source, :smallint, default: 0) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:pages_domains, :certificate_source, :smallint, default: 0)
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddStrategiesToOperationsFeatureFlagScopes < ActiveRecord::Migration[5.1] ...@@ -8,7 +8,7 @@ class AddStrategiesToOperationsFeatureFlagScopes < ActiveRecord::Migration[5.1]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :operations_feature_flag_scopes, :strategies, :jsonb, default: [{ name: "default", parameters: {} }] # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :operations_feature_flag_scopes, :strategies, :jsonb, default: [{ name: "default", parameters: {} }]
end end
def down def down
......
...@@ -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 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :approval_project_rules, :rule_type, :integer, limit: 2, default: 0, allow_null: false
end end
def down def down
......
...@@ -11,7 +11,7 @@ class AddNamespacePerEnvironmentFlagToClusters < ActiveRecord::Migration[5.1] ...@@ -11,7 +11,7 @@ class AddNamespacePerEnvironmentFlagToClusters < ActiveRecord::Migration[5.1]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :clusters, :namespace_per_environment, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :clusters, :namespace_per_environment, :boolean, default: false
end end
def down def down
......
...@@ -12,7 +12,7 @@ class AddObjectStorageFlagToGeoNode < ActiveRecord::Migration[5.2] ...@@ -12,7 +12,7 @@ class AddObjectStorageFlagToGeoNode < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :geo_nodes, :sync_object_storage, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :geo_nodes, :sync_object_storage, :boolean, default: false
end end
def down def down
......
...@@ -9,7 +9,7 @@ class AddMergeRequestsRequireCodeOwnerApprovalToProtectedBranches < ActiveRecord ...@@ -9,7 +9,7 @@ class AddMergeRequestsRequireCodeOwnerApprovalToProtectedBranches < ActiveRecord
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:protected_branches, :protected_branches,
:code_owner_approval_required, :code_owner_approval_required,
:boolean, :boolean,
......
...@@ -8,7 +8,7 @@ class AddActiveJobsLimitToPlans < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddActiveJobsLimitToPlans < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :plans, :active_jobs_limit, :integer, default: 0 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :plans, :active_jobs_limit, :integer, default: 0
end end
def down def down
......
...@@ -7,7 +7,7 @@ class AddMaxIssueCountToList < ActiveRecord::Migration[4.2] ...@@ -7,7 +7,7 @@ class AddMaxIssueCountToList < ActiveRecord::Migration[4.2]
DOWNTIME = false DOWNTIME = false
def up def up
add_column_with_default :lists, :max_issue_count, :integer, default: 0 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :lists, :max_issue_count, :integer, default: 0
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddCloudRunToClustersProvidersGcp < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddCloudRunToClustersProvidersGcp < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:cluster_providers_gcp, :cloud_run, :boolean, default: false) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:cluster_providers_gcp, :cloud_run, :boolean, default: false)
end end
def down def down
......
...@@ -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 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :user_preferences, :show_whitespace_in_diffs, :boolean, default: true, allow_null: false
end end
def down def down
......
...@@ -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, # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:clusters, :cleanup_status,
:smallint, :smallint,
default: 1, default: 1,
allow_null: false) allow_null: false)
......
...@@ -8,7 +8,7 @@ class AddExpireNotificationDeliveredToPersonalAccessTokens < ActiveRecord::Migra ...@@ -8,7 +8,7 @@ class AddExpireNotificationDeliveredToPersonalAccessTokens < ActiveRecord::Migra
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :personal_access_tokens, :expire_notification_delivered, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :personal_access_tokens, :expire_notification_delivered, :boolean, default: false
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddCommentActionsToServices < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddCommentActionsToServices < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:services, :comment_on_event_enabled, :boolean, default: true) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:services, :comment_on_event_enabled, :boolean, default: true)
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddMaxIssueWeightToList < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddMaxIssueWeightToList < ActiveRecord::Migration[5.2]
DOWNTIME = false DOWNTIME = false
def up def up
add_column_with_default :lists, :max_issue_weight, :integer, default: 0 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :lists, :max_issue_weight, :integer, default: 0
end end
def down def down
......
...@@ -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( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:grafana_integrations, :grafana_integrations,
:enabled, :enabled,
:boolean, :boolean,
......
...@@ -9,7 +9,7 @@ class AddSecretToSnippet < ActiveRecord::Migration[5.2] ...@@ -9,7 +9,7 @@ class AddSecretToSnippet < ActiveRecord::Migration[5.2]
def up def up
unless column_exists?(:snippets, :secret) unless column_exists?(:snippets, :secret)
add_column_with_default :snippets, :secret, :boolean, default: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :snippets, :secret, :boolean, default: false
end end
add_concurrent_index :snippets, [:visibility_level, :secret] add_concurrent_index :snippets, [:visibility_level, :secret]
......
...@@ -9,7 +9,7 @@ class AddStateToMergeTrains < ActiveRecord::Migration[5.2] ...@@ -9,7 +9,7 @@ class AddStateToMergeTrains < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :merge_trains, :status, :integer, limit: 2, default: MERGE_TRAIN_STATUS_CREATED # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :merge_trains, :status, :integer, limit: 2, default: MERGE_TRAIN_STATUS_CREATED
end end
def down def down
......
...@@ -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, # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:ci_build_needs, :artifacts,
:boolean, :boolean,
default: true, default: true,
allow_null: false) allow_null: false)
......
...@@ -8,7 +8,7 @@ class AddIssueLinksType < ActiveRecord::Migration[5.1] ...@@ -8,7 +8,7 @@ class AddIssueLinksType < ActiveRecord::Migration[5.1]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :issue_links, :link_type, :integer, default: 0, limit: 2 # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :issue_links, :link_type, :integer, default: 0, limit: 2
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddConfidentialToDoorkeeperApplication < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddConfidentialToDoorkeeperApplication < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:oauth_applications, :oauth_applications,
:confidential, :confidential,
:boolean, :boolean,
......
...@@ -9,10 +9,8 @@ class AddWildcardAndDomainTypeToPagesDomains < ActiveRecord::Migration[5.2] ...@@ -9,10 +9,8 @@ class AddWildcardAndDomainTypeToPagesDomains < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
# rubocop:disable Migration/AddColumnWithDefault
add_column_with_default :pages_domains, :wildcard, :boolean, default: false add_column_with_default :pages_domains, :wildcard, :boolean, default: false
add_column_with_default :pages_domains, :domain_type, :integer, limit: 2, default: PROJECT_TYPE add_column_with_default :pages_domains, :domain_type, :integer, limit: 2, default: PROJECT_TYPE
# rubocop:enable Migration/AddColumnWithDefault
end end
def down def down
......
...@@ -10,7 +10,7 @@ class AddBroadcastTypeToBroadcastMessage < ActiveRecord::Migration[5.2] ...@@ -10,7 +10,7 @@ class AddBroadcastTypeToBroadcastMessage < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:broadcast_messages, :broadcast_type, :smallint, default: BROADCAST_MESSAGE_BANNER_TYPE) # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(:broadcast_messages, :broadcast_type, :smallint, default: BROADCAST_MESSAGE_BANNER_TYPE)
end end
def down def down
......
...@@ -8,7 +8,7 @@ class AddRepositoryStorageToSnippets < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddRepositoryStorageToSnippets < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:snippets, :snippets,
:repository_storage, :repository_storage,
:string, :string,
......
...@@ -8,7 +8,7 @@ class AddStorageVersionToSnippets < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddStorageVersionToSnippets < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:snippets, :snippets,
:storage_version, :storage_version,
:integer, :integer,
......
...@@ -8,7 +8,7 @@ class AddDeployTokenTypeToDeployTokens < ActiveRecord::Migration[5.2] ...@@ -8,7 +8,7 @@ class AddDeployTokenTypeToDeployTokens < ActiveRecord::Migration[5.2]
DOWNTIME = false DOWNTIME = false
def up def up
add_column_with_default :deploy_tokens, :deploy_token_type, :integer, default: 2, limit: 2, allow_null: false # rubocop: disable Migration/AddColumnWithDefault add_column_with_default :deploy_tokens, :deploy_token_type, :integer, default: 2, limit: 2, allow_null: false
end end
def down def down
......
...@@ -9,7 +9,7 @@ class AddUsageToPagesDomains < ActiveRecord::Migration[5.2] ...@@ -9,7 +9,7 @@ class AddUsageToPagesDomains < ActiveRecord::Migration[5.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :pages_domains, :usage, :integer, limit: 2, default: PAGES_USAGE, allow_null: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :pages_domains, :usage, :integer, limit: 2, default: PAGES_USAGE, allow_null: false
end end
def down def down
......
...@@ -12,9 +12,7 @@ class AddVersionToFeatureFlagsTable < ActiveRecord::Migration[6.0] ...@@ -12,9 +12,7 @@ class AddVersionToFeatureFlagsTable < ActiveRecord::Migration[6.0]
def up def up
# The operations_feature_flags table is small enough that we can disable this cop. # The operations_feature_flags table is small enough that we can disable this cop.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25552#note_291202882 # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25552#note_291202882
# rubocop: disable Migration/AddColumnWithDefault
add_column_with_default(:operations_feature_flags, :version, :smallint, default: FEATURE_FLAG_LEGACY_VERSION, allow_null: false) add_column_with_default(:operations_feature_flags, :version, :smallint, default: FEATURE_FLAG_LEGACY_VERSION, allow_null: false)
# rubocop: enable Migration/AddColumnWithDefault
end end
def down def down
......
...@@ -19,7 +19,7 @@ class RemoveStorageVersionColumnFromSnippets < ActiveRecord::Migration[5.2] ...@@ -19,7 +19,7 @@ class RemoveStorageVersionColumnFromSnippets < ActiveRecord::Migration[5.2]
def down def down
return if column_exists?(:snippets, :storage_version) return if column_exists?(:snippets, :storage_version)
add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:snippets, :snippets,
:storage_version, :storage_version,
:integer, :integer,
......
...@@ -16,7 +16,7 @@ class RemoveRepositoryStorageFromSnippets < ActiveRecord::Migration[6.0] ...@@ -16,7 +16,7 @@ class RemoveRepositoryStorageFromSnippets < ActiveRecord::Migration[6.0]
def down def down
return if column_exists?(:snippets, :repository_storage) return if column_exists?(:snippets, :repository_storage)
add_column_with_default( # rubocop:disable Migration/AddColumnWithDefault add_column_with_default(
:snippets, :snippets,
:repository_storage, :repository_storage,
:string, :string,
......
...@@ -6,10 +6,8 @@ class AddNeedsResyncToProjectRegistry < ActiveRecord::Migration[4.2] ...@@ -6,10 +6,8 @@ class AddNeedsResyncToProjectRegistry < ActiveRecord::Migration[4.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
# rubocop:disable Migration/AddColumnWithDefault
add_column_with_default(:project_registry, :resync_repository, :boolean, default: true) add_column_with_default(:project_registry, :resync_repository, :boolean, default: true)
add_column_with_default(:project_registry, :resync_wiki, :boolean, default: true) add_column_with_default(:project_registry, :resync_wiki, :boolean, default: true)
# rubocop:enable Migration/AddColumnWithDefault
end end
def down def down
......
...@@ -7,7 +7,7 @@ class AddFileRegistrySuccess < ActiveRecord::Migration[4.2] ...@@ -7,7 +7,7 @@ class AddFileRegistrySuccess < ActiveRecord::Migration[4.2]
def up def up
# Ensure existing rows are recorded as successes # Ensure existing rows are recorded as successes
add_column_with_default :file_registry, :success, :boolean, default: true, allow_null: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :file_registry, :success, :boolean, default: true, allow_null: false
change_column :file_registry, :success, :boolean, default: false change_column :file_registry, :success, :boolean, default: false
end end
......
...@@ -6,7 +6,7 @@ class AddMissingOnPrimaryToFileRegistry < ActiveRecord::Migration[4.2] ...@@ -6,7 +6,7 @@ class AddMissingOnPrimaryToFileRegistry < ActiveRecord::Migration[4.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :file_registry, :missing_on_primary, :boolean, default: false, allow_null: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :file_registry, :missing_on_primary, :boolean, default: false, allow_null: false
end end
def down def down
......
...@@ -6,7 +6,7 @@ class AddMissingOnPrimaryToJobArtifactRegistry < ActiveRecord::Migration[4.2] ...@@ -6,7 +6,7 @@ class AddMissingOnPrimaryToJobArtifactRegistry < ActiveRecord::Migration[4.2]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default :job_artifact_registry, :missing_on_primary, :boolean, default: false, allow_null: false # rubocop:disable Migration/AddColumnWithDefault add_column_with_default :job_artifact_registry, :missing_on_primary, :boolean, default: false, allow_null: false
end end
def down def down
......
...@@ -10,7 +10,37 @@ module RuboCop ...@@ -10,7 +10,37 @@ module RuboCop
class AddColumnWithDefault < RuboCop::Cop::Cop class AddColumnWithDefault < RuboCop::Cop::Cop
include MigrationHelpers include MigrationHelpers
WHITELISTED_TABLES = [:application_settings].freeze # Tables >= 10 GB on GitLab.com as of 02/2020
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
note_diff_files
notes
project_authorizations
projects
push_event_payloads
resource_label_events
sent_notifications
system_note_metadata
taggings
todos
users
web_hook_logs
].freeze
MSG = '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, ' \ MSG = '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, ' \
'see https://gitlab.com/gitlab-org/gitlab/issues/38060'.freeze 'see https://gitlab.com/gitlab-org/gitlab/issues/38060'.freeze
...@@ -23,21 +53,23 @@ module RuboCop ...@@ -23,21 +53,23 @@ module RuboCop
return unless in_migration?(node) return unless in_migration?(node)
add_column_with_default?(node) do |table, options| add_column_with_default?(node) do |table, options|
break if table_whitelisted?(table) || nulls_allowed?(options) add_offense(node, location: :selector) if offensive?(table, options)
add_offense(node, location: :selector)
end end
end end
private private
def offensive?(table, options)
table_blacklisted?(table) && !nulls_allowed?(options)
end
def nulls_allowed?(options) def nulls_allowed?(options)
options.find { |opt| opt.key.value == :allow_null && opt.value.true_type? } options.find { |opt| opt.key.value == :allow_null && opt.value.true_type? }
end end
def table_whitelisted?(symbol) def table_blacklisted?(symbol)
symbol && symbol.type == :sym && symbol && symbol.type == :sym &&
WHITELISTED_TABLES.include?(symbol.children[0]) BLACKLISTED_TABLES.include?(symbol.children[0])
end end
end end
end end
......
...@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do ...@@ -16,7 +16,7 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do
it 'does not register any offenses' do it 'does not register any offenses' do
expect_no_offenses(<<~RUBY) expect_no_offenses(<<~RUBY)
def up def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: false) add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true, allow_null: false)
end end
RUBY RUBY
end end
...@@ -29,10 +29,11 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do ...@@ -29,10 +29,11 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do
let(:offense) { '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, see https://gitlab.com/gitlab-org/gitlab/issues/38060' } let(:offense) { '`add_column_with_default` without `allow_null: true` may cause prolonged lock situations and downtime, see https://gitlab.com/gitlab-org/gitlab/issues/38060' }
context 'for blacklisted table' do
it 'registers an offense when specifying allow_null: false' do it 'registers an offense when specifying allow_null: false' do
expect_offense(<<~RUBY) expect_offense(<<~RUBY)
def up def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: false) add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true, allow_null: false)
^^^^^^^^^^^^^^^^^^^^^^^ #{offense} ^^^^^^^^^^^^^^^^^^^^^^^ #{offense}
end end
RUBY RUBY
...@@ -41,7 +42,7 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do ...@@ -41,7 +42,7 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do
it 'registers no offense when specifying allow_null: true' do it 'registers no offense when specifying allow_null: true' do
expect_no_offenses(<<~RUBY) expect_no_offenses(<<~RUBY)
def up def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true, allow_null: true) add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true, allow_null: true)
end end
RUBY RUBY
end end
...@@ -49,13 +50,15 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do ...@@ -49,13 +50,15 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do
it 'registers an offense when allow_null is not specified' do it 'registers an offense when allow_null is not specified' do
expect_offense(<<~RUBY) expect_offense(<<~RUBY)
def up def up
add_column_with_default(:ci_build_needs, :artifacts, :boolean, default: true) add_column_with_default(:merge_request_diff_files, :artifacts, :boolean, default: true)
^^^^^^^^^^^^^^^^^^^^^^^ #{offense} ^^^^^^^^^^^^^^^^^^^^^^^ #{offense}
end end
RUBY RUBY
end end
end
it 'registers no offense for application_settings (whitelisted table)' do context 'for tables not on the blacklist' do
it 'registers no offense for application_settings (not on blacklist)' do
expect_no_offenses(<<~RUBY) expect_no_offenses(<<~RUBY)
def up def up
add_column_with_default(:application_settings, :another_column, :boolean, default: true, allow_null: false) add_column_with_default(:application_settings, :another_column, :boolean, default: true, allow_null: false)
...@@ -63,4 +66,5 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do ...@@ -63,4 +66,5 @@ describe RuboCop::Cop::Migration::AddColumnWithDefault do
RUBY RUBY
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment