Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
commit0c872e02b2c822e3397515ec324051ff540f0cd5 (patch)
treece2fb6ce7030e4dad0f4118d21ab6453e5938cdd /rubocop/cop/migration
parentf7e05a6853b12f02911494c4b3fe53d9540d74fc (diff)
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'rubocop/cop/migration')
-rw-r--r--rubocop/cop/migration/add_column_with_default.rb23
-rw-r--r--rubocop/cop/migration/add_limit_to_text_columns.rb6
-rw-r--r--rubocop/cop/migration/batch_migrations_post_only.rb37
-rw-r--r--rubocop/cop/migration/safer_boolean_column.rb4
-rw-r--r--rubocop/cop/migration/versioned_migration_class.rb5
5 files changed, 44 insertions, 31 deletions
diff --git a/rubocop/cop/migration/add_column_with_default.rb b/rubocop/cop/migration/add_column_with_default.rb
deleted file mode 100644
index 36603e09263..00000000000
--- a/rubocop/cop/migration/add_column_with_default.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../../migration_helpers'
-
-module RuboCop
- module Cop
- module Migration
- class AddColumnWithDefault < RuboCop::Cop::Base
- include MigrationHelpers
-
- MSG = '`add_column_with_default` is deprecated, use `add_column` instead'
-
- def on_send(node)
- return unless in_migration?(node)
-
- name = node.children[1]
-
- add_offense(node.loc.selector) if name == :add_column_with_default
- end
- end
- end
- end
-end
diff --git a/rubocop/cop/migration/add_limit_to_text_columns.rb b/rubocop/cop/migration/add_limit_to_text_columns.rb
index 5c71fbbfaa2..2d3b5d5094f 100644
--- a/rubocop/cop/migration/add_limit_to_text_columns.rb
+++ b/rubocop/cop/migration/add_limit_to_text_columns.rb
@@ -44,11 +44,9 @@ module RuboCop
if text_operation_with_limit?(send_node)
add_offense(send_node.loc.selector, message: TEXT_LIMIT_ATTRIBUTE_NOT_ALLOWED) if version(node) < TEXT_LIMIT_ATTRIBUTE_ALLOWED_SINCE
- else
+ elsif text_limit_missing?(node, *table_and_attribute_name(send_node))
# We require a limit for the same table and attribute name
- if text_limit_missing?(node, *table_and_attribute_name(send_node))
- add_offense(send_node.loc.selector)
- end
+ add_offense(send_node.loc.selector)
end
end
end
diff --git a/rubocop/cop/migration/batch_migrations_post_only.rb b/rubocop/cop/migration/batch_migrations_post_only.rb
new file mode 100644
index 00000000000..3a1f3b64d75
--- /dev/null
+++ b/rubocop/cop/migration/batch_migrations_post_only.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that checks that no background batched migration helpers are called by regular migrations.
+ class BatchMigrationsPostOnly < RuboCop::Cop::Base
+ include MigrationHelpers
+
+ MSG = "This method must only be used in post-deployment migrations."
+
+ FORBIDDEN_METHODS = %w[
+ ensure_batched_background_migration_is_finished
+ queue_batched_background_migration
+ delete_batched_background_migration
+ finalize_batched_background_migration
+ ].freeze
+
+ SYMBOLIZED_MATCHER = FORBIDDEN_METHODS.map { |w| ":#{w}" }.join(' | ')
+
+ def_node_matcher :on_forbidden_method, <<~PATTERN
+ (send nil? {#{SYMBOLIZED_MATCHER}} ...)
+ PATTERN
+
+ def on_send(node)
+ on_forbidden_method(node) do
+ break if in_post_deployment_migration?(node)
+
+ add_offense(node, message: MSG)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/migration/safer_boolean_column.rb b/rubocop/cop/migration/safer_boolean_column.rb
index d3d77b16357..c5df21dc94a 100644
--- a/rubocop/cop/migration/safer_boolean_column.rb
+++ b/rubocop/cop/migration/safer_boolean_column.rb
@@ -21,9 +21,9 @@ module RuboCop
class SaferBooleanColumn < RuboCop::Cop::Base
include MigrationHelpers
- DEFAULT_OFFENSE = 'Boolean columns on the `%s` table should have a default. You may wish to use `add_column_with_default`.'
+ DEFAULT_OFFENSE = 'Boolean columns on the `%s` table should have a default.'
NULL_OFFENSE = 'Boolean columns on the `%s` table should disallow nulls.'
- DEFAULT_AND_NULL_OFFENSE = 'Boolean columns on the `%s` table should have a default and should disallow nulls. You may wish to use `add_column_with_default`.'
+ DEFAULT_AND_NULL_OFFENSE = 'Boolean columns on the `%s` table should have a default and should disallow nulls.'
def_node_matcher :add_column?, <<~PATTERN
(send nil? :add_column $...)
diff --git a/rubocop/cop/migration/versioned_migration_class.rb b/rubocop/cop/migration/versioned_migration_class.rb
index 648782f1735..572ddcd1b12 100644
--- a/rubocop/cop/migration/versioned_migration_class.rb
+++ b/rubocop/cop/migration/versioned_migration_class.rb
@@ -9,9 +9,10 @@ module RuboCop
include MigrationHelpers
ENFORCED_SINCE = 2021_09_02_00_00_00
+ CURRENT_DATABASE_MIGRATION_CLASS = 'Gitlab::Database::Migration[2.1]'
- MSG_INHERIT = 'Don\'t inherit from ActiveRecord::Migration but use Gitlab::Database::Migration[1.0] instead. See https://docs.gitlab.com/ee/development/migration_style_guide.html#migration-helpers-and-versioning.'
- MSG_INCLUDE = 'Don\'t include migration helper modules directly. Inherit from Gitlab::Database::Migration[1.0] instead. See https://docs.gitlab.com/ee/development/migration_style_guide.html#migration-helpers-and-versioning.'
+ MSG_INHERIT = 'Don\'t inherit from ActiveRecord::Migration but use Gitlab::Database::Migration[2.1] instead. See https://docs.gitlab.com/ee/development/migration_style_guide.html#migration-helpers-and-versioning.'
+ MSG_INCLUDE = 'Don\'t include migration helper modules directly. Inherit from Gitlab::Database::Migration[2.1] instead. See https://docs.gitlab.com/ee/development/migration_style_guide.html#migration-helpers-and-versioning.'
ACTIVERECORD_MIGRATION_CLASS = 'ActiveRecord::Migration'