8a72f5c427
This commit adds the module `FromUnion`, which provides the class method `from_union`. This simplifies the process of selecting data from the result of a UNION, and reduces the likelihood of making mistakes. As a result, instead of this: union = Gitlab::SQL::Union.new([foo, bar]) Foo.from("(#{union.to_sql}) #{Foo.table_name}") We can now write this instead: Foo.from_union([foo, bar]) This commit also includes some changes to make this new setup work properly. For example, a bug in Rails 4 (https://github.com/rails/rails/issues/24193) would break the use of `from("sub-query-here").includes(:relation)` in certain cases. There was also a CI query which appeared to repeat a lot of conditions from an outer query on an inner query, which isn't necessary. Finally, we include a RuboCop cop to ensure developers use this new module, instead of using Gitlab::SQL::Union directly. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/51307
39 lines
1.8 KiB
Ruby
39 lines
1.8 KiB
Ruby
# rubocop:disable Naming/FileName
|
|
require_relative 'cop/gitlab/module_with_instance_variables'
|
|
require_relative 'cop/gitlab/predicate_memoization'
|
|
require_relative 'cop/gitlab/httparty'
|
|
require_relative 'cop/gitlab/finder_with_find_by'
|
|
require_relative 'cop/gitlab/union'
|
|
require_relative 'cop/include_sidekiq_worker'
|
|
require_relative 'cop/avoid_return_from_blocks'
|
|
require_relative 'cop/avoid_break_from_strong_memoize'
|
|
require_relative 'cop/line_break_around_conditional_block'
|
|
require_relative 'cop/prefer_class_methods_over_module'
|
|
require_relative 'cop/migration/add_column'
|
|
require_relative 'cop/migration/add_concurrent_foreign_key'
|
|
require_relative 'cop/migration/add_concurrent_index'
|
|
require_relative 'cop/migration/add_index'
|
|
require_relative 'cop/migration/add_reference'
|
|
require_relative 'cop/migration/add_timestamps'
|
|
require_relative 'cop/migration/datetime'
|
|
require_relative 'cop/migration/hash_index'
|
|
require_relative 'cop/migration/remove_column'
|
|
require_relative 'cop/migration/remove_concurrent_index'
|
|
require_relative 'cop/migration/remove_index'
|
|
require_relative 'cop/migration/reversible_add_column_with_default'
|
|
require_relative 'cop/migration/safer_boolean_column'
|
|
require_relative 'cop/migration/timestamps'
|
|
require_relative 'cop/migration/update_column_in_batches'
|
|
require_relative 'cop/migration/update_large_table'
|
|
require_relative 'cop/project_path_helper'
|
|
require_relative 'cop/rspec/env_assignment'
|
|
require_relative 'cop/rspec/factories_in_migration_specs'
|
|
require_relative 'cop/sidekiq_options_queue'
|
|
require_relative 'cop/destroy_all'
|
|
require_relative 'cop/ruby_interpolation_in_translation'
|
|
require_relative 'code_reuse_helpers'
|
|
require_relative 'cop/code_reuse/finder'
|
|
require_relative 'cop/code_reuse/service_class'
|
|
require_relative 'cop/code_reuse/presenter'
|
|
require_relative 'cop/code_reuse/serializer'
|
|
require_relative 'cop/code_reuse/active_record'
|