diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /lib/generators | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'lib/generators')
-rw-r--r-- | lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb | 12 | ||||
-rw-r--r-- | lib/generators/model/model_generator.rb | 25 |
2 files changed, 32 insertions, 5 deletions
diff --git a/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb b/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb index 58d3257d07e..8cd03978f27 100644 --- a/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb +++ b/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb @@ -8,15 +8,17 @@ module Gitlab desc 'Generates a metric definition .yml file with defaults for Redis HLL.' argument :category, type: :string, desc: "Category name" - argument :event, type: :string, desc: "Event name" + argument :events, type: :array, desc: "Unique event names", banner: 'event_one event_two event_three' class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if metric is for ee' def create_metrics - weekly_params = ["#{key_path}_weekly", '--dir', '7d', '--class_name', 'RedisHLLMetric'] + weekly_key_paths = key_paths.map { |key_path| "#{key_path}_weekly" } + weekly_params = [*weekly_key_paths, '--dir', '7d', '--class_name', 'RedisHLLMetric'] weekly_params << '--ee' if ee? Gitlab::UsageMetricDefinitionGenerator.start(weekly_params) - monthly_params = ["#{key_path}_monthly", '--dir', '28d', '--class_name', 'RedisHLLMetric'] + monthly_key_paths = key_paths.map { |key_path| "#{key_path}_monthly" } + monthly_params = [*monthly_key_paths, '--dir', '28d', '--class_name', 'RedisHLLMetric'] monthly_params << '--ee' if ee? Gitlab::UsageMetricDefinitionGenerator.start(monthly_params) end @@ -27,8 +29,8 @@ module Gitlab options[:ee] end - def key_path - "redis_hll_counters.#{category}.#{event}" + def key_paths + events.map { |event| "redis_hll_counters.#{category}.#{event}" } end end end diff --git a/lib/generators/model/model_generator.rb b/lib/generators/model/model_generator.rb new file mode 100644 index 00000000000..533b2ce679d --- /dev/null +++ b/lib/generators/model/model_generator.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'rails/generators' +require 'rails/generators/active_record/model/model_generator' + +module Model + class ModelGenerator < ActiveRecord::Generators::ModelGenerator + source_root File.expand_path('../../../generator_templates/active_record/migration/', __dir__) + + def create_migration_file + return if skip_migration_creation? + + if options[:indexes] == false + attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } + end + + migration_template "create_table_migration.rb", File.join(db_migrate_path, "create_#{table_name}.rb") + end + + # Override to find templates from superclass as well + def source_paths + super + [self.class.superclass.default_source_root] + end + end +end |