diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-01-31 19:27:55 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-02-01 10:47:54 +0100 |
commit | 6f54419a71bcc7a1153f3fbca4ffd73161c8096c (patch) | |
tree | 4cdc5b8db6b10f1a81077b1edc8030b5623c7046 | |
parent | b4d8facb14520b2c98cf7313ca47fddc42561a4b (diff) | |
download | gitlab-ce-32283-trending-projects-unique-constraint.tar.gz |
WIP: Different solution for MySQL.32283-trending-projects-unique-constraint
-rw-r--r-- | db/migrate/20180131101039_remove_duplicates_in_trending_projects.rb | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/db/migrate/20180131101039_remove_duplicates_in_trending_projects.rb b/db/migrate/20180131101039_remove_duplicates_in_trending_projects.rb index b68f3a8167f..a0dc77d4a75 100644 --- a/db/migrate/20180131101039_remove_duplicates_in_trending_projects.rb +++ b/db/migrate/20180131101039_remove_duplicates_in_trending_projects.rb @@ -4,16 +4,22 @@ class RemoveDuplicatesInTrendingProjects < ActiveRecord::Migration DOWNTIME = false def up - connection.execute <<-SQL - DELETE FROM trending_projects WHERE id IN ( - SELECT id FROM ( - SELECT - id, - ROW_NUMBER() OVER (PARTITION BY project_id) AS row_number - FROM trending_projects - ) t WHERE t.row_number > 1 - ) - SQL + if Gitlab::Database.postgresql? + execute <<~SQL + DELETE FROM trending_projects WHERE id IN ( + SELECT id FROM ( + SELECT + id, + ROW_NUMBER() OVER (PARTITION BY project_id) AS row_number + FROM trending_projects + ) t WHERE t.row_number > 1 + ) + SQL + else + # No window functions in Mysql 5.x + # We can't modify a table we are selecting from on MySQL + fail 'TODO' + end end def down |