Skip to content

Fix "rails g migration" not always using migration templates

Stan Hu requested to merge sh-fix-generators-not-always-working into master

Normally, this is what's supposed to happen when you invoke rails g generate migration:

  1. Rails.application.load_generators is called here: https://github.com/rails/rails/blob/v4.2.10/railties/lib/rails/commands/commands_tasks.rb#L129
  2. This loads the local generator_templates path in https://github.com/rails/rails/blob/v4.2.10/railties/lib/rails/generators.rb#L69.

However, when metrics are enabled, the application is eager loaded here in the initializer. This short-circuits the load_generators and loads ActiveRecord::Generators::MigrationGenerator automatically, so the custom path is never loaded properly.

We fix this by disabling metrics and eager loading when the migration generators are being used.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/52651

Edited by Stan Hu

Merge request reports