Skip to content

Fix Rubocop fails for regular migrations

What does this MR do and why?

This MR fixes a Rubocop bug caused by !165146 (merged), where we try to access Rails not only for batched migrations but for all migrations, but it is not available in regular Rubocop. Therefore, we need to also checked that the Rails constant is defined.

Failing rubocop job example: https://gitlab.com/gitlab-org/gitlab/-/jobs/7842778306

Running bundle exec rubocop -d db/post_migrate/20240605193707_queue_backfill_vulnerability_state_transitions_project_id.rb on branch 471811-set-vulnerability_state_transitions-schema-to-gitlab_sec:

An error occurred while BackgroundMigration/DictionaryFile cop was inspecting /Users/kev/development/gitlab/gdk/gitlab/db/post_migrate/20240605193707_queue_backfill_vulnerability_state_transitions_project_id.rb:3:0.
uninitialized constant #<Class:Gitlab::Utils::BatchedBackgroundMigrationsDictionary>::Rails
/Users/kev/development/gitlab/gdk/gitlab/lib/gitlab/utils/batched_background_migrations_dictionary.rb:12:in `entries'
/Users/kev/development/gitlab/gdk/gitlab/lib/gitlab/utils/batched_background_migrations_dictionary.rb:70:in `entry'
/Users/kev/development/gitlab/gdk/gitlab/lib/gitlab/utils/batched_background_migrations_dictionary.rb:60:in `milestone'
/Users/kev/development/gitlab/gdk/gitlab/rubocop/cop/background_migration/dictionary_file.rb:83:in `validate_dictionary_file'
/Users/kev/development/gitlab/gdk/gitlab/rubocop/cop/background_migration/dictionary_file.rb:48:in `on_class'

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Kev Kloss

Merge request reports

Loading