diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
commit | 3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch) | |
tree | 3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /rubocop/cop/migration | |
parent | 9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff) |
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'rubocop/cop/migration')
5 files changed, 35 insertions, 9 deletions
diff --git a/rubocop/cop/migration/prevent_index_creation.rb b/rubocop/cop/migration/prevent_index_creation.rb index 185f36cb24b..4c39032eb0f 100644 --- a/rubocop/cop/migration/prevent_index_creation.rb +++ b/rubocop/cop/migration/prevent_index_creation.rb @@ -10,7 +10,7 @@ module RuboCop FORBIDDEN_TABLES = %i[ci_builds].freeze - MSG = "Adding new index to #{FORBIDDEN_TABLES.join(", ")} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886" + MSG = "Adding new index to #{FORBIDDEN_TABLES.join(", ")} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886".freeze def on_new_investigation super diff --git a/rubocop/cop/migration/schema_addition_methods_no_post.rb b/rubocop/cop/migration/schema_addition_methods_no_post.rb index 5bb5bb63f0c..53b47dc99dc 100644 --- a/rubocop/cop/migration/schema_addition_methods_no_post.rb +++ b/rubocop/cop/migration/schema_addition_methods_no_post.rb @@ -5,7 +5,7 @@ require_relative '../../migration_helpers' module RuboCop module Cop module Migration - # Cop that checks that no background batched migration helpers are called by regular migrations. + # Cop that checks that no schema migration methods are called by post-deployment migrations. class SchemaAdditionMethodsNoPost < RuboCop::Cop::Base include MigrationHelpers @@ -22,13 +22,25 @@ module RuboCop (send nil? {#{SYMBOLIZED_MATCHER}} ...) PATTERN + def_node_matcher :rolling_back_migration, <<~PATTERN + (def :down ...) + PATTERN + def on_send(node) return unless time_enforced?(node) + return if rolling_back_migration?(node) + on_forbidden_method(node) do add_offense(node, message: MSG) end end + + private + + def rolling_back_migration?(node) + node.each_ancestor(:def).any? { |a| rolling_back_migration(a) } + end end end end diff --git a/rubocop/cop/migration/update_column_in_batches.rb b/rubocop/cop/migration/update_column_in_batches.rb index 7f4479c62e3..e97f51361a9 100644 --- a/rubocop/cop/migration/update_column_in_batches.rb +++ b/rubocop/cop/migration/update_column_in_batches.rb @@ -10,20 +10,24 @@ module RuboCop class UpdateColumnInBatches < RuboCop::Cop::Base include MigrationHelpers - MSG = 'Migration running `update_column_in_batches` must have a spec file at' \ - ' `%s`.' + MSG = 'Migration running `update_column_in_batches` must have a spec file at `%s`.' + + RESTRICT_ON_SEND = %i[update_column_in_batches].freeze def on_send(node) return unless in_migration?(node) - return unless node.children[1] == :update_column_in_batches spec_path = spec_filename(node) - return if File.exist?(File.expand_path(spec_path, rails_root)) add_offense(node, message: format(MSG, spec_path)) end + # Used by RuboCop to invalidate its cache if specs change. + def external_dependency_checksum + @external_dependency_checksum ||= checksum_filenames('{,ee/}spec/migrations/**/*_spec.rb') + end + private def spec_filename(node) @@ -39,6 +43,16 @@ module RuboCop def rails_root Pathname.new(File.expand_path('../../..', __dir__)) end + + def checksum_filenames(pattern) + digest = Digest::SHA256.new + + rails_root.glob(pattern) do |path| + digest.update(path.relative_path_from(rails_root).to_path) + end + + digest.hexdigest + end end end end diff --git a/rubocop/cop/migration/versioned_migration_class.rb b/rubocop/cop/migration/versioned_migration_class.rb index 27f1c0e16a1..d078acedb37 100644 --- a/rubocop/cop/migration/versioned_migration_class.rb +++ b/rubocop/cop/migration/versioned_migration_class.rb @@ -12,10 +12,10 @@ module RuboCop DOC_LINK = "https://docs.gitlab.com/ee/development/migration_style_guide.html#migration-helpers-and-versioning" MSG_INHERIT = "Don't inherit from ActiveRecord::Migration or old versions of Gitlab::Database::Migration. " \ - "Use Gitlab::Database::Migration[2.1] instead. See #{DOC_LINK}." + "Use Gitlab::Database::Migration[2.1] instead. See #{DOC_LINK}.".freeze MSG_INCLUDE = "Don't include migration helper modules directly. " \ - "Inherit from Gitlab::Database::Migration[2.1] instead. See #{DOC_LINK}." + "Inherit from Gitlab::Database::Migration[2.1] instead. See #{DOC_LINK}.".freeze GITLAB_MIGRATION_CLASS = 'Gitlab::Database::Migration' ACTIVERECORD_MIGRATION_CLASS = 'ActiveRecord::Migration' diff --git a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb index 5c96b38dcdc..1b0d5ed9324 100644 --- a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb +++ b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb @@ -31,7 +31,7 @@ module RuboCop create_trigger_to_sync_tables ].sort.freeze - MSG = "The method is not allowed to be called within the `with_lock_retries` block, the only allowed methods are: #{ALLOWED_MIGRATION_METHODS.join(', ')}" + MSG = "The method is not allowed to be called within the `with_lock_retries` block, the only allowed methods are: #{ALLOWED_MIGRATION_METHODS.join(', ')}".freeze MSG_ONLY_ONE_FK_ALLOWED = "Avoid adding more than one foreign key within the `with_lock_retries`. See https://docs.gitlab.com/ee/development/migration_style_guide.html#examples" def_node_matcher :send_node?, <<~PATTERN |