From 76c8041b9a496959df7310b7b9be8c908e768314 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 24 Oct 2018 16:33:19 -0700 Subject: Fix "rails g migration" not always using migration templates 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. With this change, we skip the initializing of metrics and eager loading if generators are in use. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/52651 --- config/initializers/8_metrics.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'config/initializers') diff --git a/config/initializers/8_metrics.rb b/config/initializers/8_metrics.rb index eccf82ab8dc..ad779a4ef06 100644 --- a/config/initializers/8_metrics.rb +++ b/config/initializers/8_metrics.rb @@ -98,7 +98,11 @@ end # check: https://github.com/rspec/rspec-mocks#settings-mocks-or-stubs-on-any-instance-of-a-class # # Related issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/33587 -if Gitlab::Metrics.enabled? && !Rails.env.test? +# +# In development mode, we turn off eager loading when we're running +# `rails generate migration` because eager loading short-circuits the +# loading of our custom migration templates. +if Gitlab::Metrics.enabled? && !Rails.env.test? && !(Rails.env.development? && defined?(Rails::Generators)) require 'pathname' require 'influxdb' require 'connection_pool' -- cgit v1.2.3