gitlab-org--gitlab-foss/lib/gitlab/database
Yorick Peterse 8a72f5c427
Added FromUnion to easily select from a UNION
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
2018-09-17 12:39:43 +02:00
..
rename_reserved_paths_migration [Rails5] Disable inheritance_column for Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Namespace 2018-06-16 13:11:50 +11:00
arel_methods.rb [Rails5] Fix Arel::UpdateManager 2018-04-29 12:54:58 +11:00
count.rb Fix fast admin counters not working when PostgreSQL has secondaries 2018-05-25 22:58:43 -07:00
date_time.rb
grant.rb Added FromUnion to easily select from a UNION 2018-09-17 12:39:43 +02:00
median.rb Rails5 fix arel from in mysql_median_datetime_sql 2018-06-26 00:35:47 +02:00
migration_helpers.rb disable_statement_timeout doesn't require any argument anymore 2018-08-11 04:15:59 +02:00
multi_threaded_migration.rb Prepare for zero downtime migrations 2017-04-12 18:15:19 +02:00
read_only_relation.rb Fix setting share_with_group_lock 2017-09-15 17:38:46 +02:00
sha_attribute.rb [Rails5] Update `type_cast_*_database` methods 2018-04-06 10:57:19 +00:00