Commit 76c8041b authored by Stan Hu's avatar Stan Hu

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
parent f5d71ad8
......@@ -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'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment