Commit 474186b6 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'rails5-fix-group-by-ee' into 'master'

[Rails5] Fix GROUP BY for mysql

Closes #6932

See merge request gitlab-org/gitlab-ee!6747
parents b5cc8c42 6234d035
...@@ -97,18 +97,27 @@ class Burndown ...@@ -97,18 +97,27 @@ class Burndown
::Issue ::Issue
.select("*") .select("*")
.from(internal_clause.select('DISTINCT ON (issues.id) issues.id, issues.state, issues.weight, e.created_at AS closed_at')) .from(internal_clause.select('DISTINCT ON (issues.id) issues.id, issues.state, issues.weight, e.created_at AS closed_at'))
.order('closed_at ASC')
.pluck('closed_at, weight, state')
else else
# In rails 5 mysql's `only_full_group_by` option is enabled by default,
# this means that `GROUP` clause must include all columns used in `SELECT`
# clause. Adding all columns to `GROUP` means that we have now
# duplicates (by issue ID) in records. To get rid of these, we unify them
# on ruby side by issue id. Finally we drop the issue id attribute from records
# because this is not accepted when creating Issue object.
::Issue ::Issue
.select("*") .select("*")
.from(internal_clause.select('issues.id, issues.state, issues.weight, e.created_at AS closed_at')) .from(internal_clause.select('issues.id, issues.state, issues.weight, e.created_at AS closed_at'))
.group('id') .group(:id, :closed_at, :weight, :state)
.having('closed_at = MIN(closed_at) OR closed_at IS NULL') .having('closed_at = MIN(closed_at) OR closed_at IS NULL')
.order('closed_at ASC')
.pluck('id, closed_at, weight, state')
.uniq(&:first)
.map { |attrs| attrs.drop(1) }
end end
rel rel.map { |attrs| Issue.new(*attrs) }
.order('closed_at ASC')
.pluck('closed_at, weight, state')
.map { |attrs| Issue.new(*attrs) }
end end
end end
end end
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