summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-10-24 16:33:19 -0700
committerStan Hu <stanhu@gmail.com>2018-10-25 14:09:27 -0700
commit76c8041b9a496959df7310b7b9be8c908e768314 (patch)
tree5943762fa3e9d14921d97c1f3eb72c88e05bc95c /config
parentf5d71ad8f3d1899a29bc12c4fcc8847b14195e3a (diff)
downloadgitlab-ce-76c8041b9a496959df7310b7b9be8c908e768314.tar.gz
Fix "rails g migration" not always using migration templatessh-fix-generators-not-always-working
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
Diffstat (limited to 'config')
-rw-r--r--config/initializers/8_metrics.rb6
1 files changed, 5 insertions, 1 deletions
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'