diff options
-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 |