Browse files

work around mysql limitation in favorite dup removal

test plan:
 * migration should apply on mysql

Change-Id: I1710a054d6d13cd3ba357ef74ae8e3e4823399e0
Reviewed-by: Cody Cutrer <>
Tested-by: Jenkins <>
  • Loading branch information...
1 parent f7d8a0b commit b54c7406039845d160a1a914e5b925b12f827a19 @jstanley0 jstanley0 committed Jul 27, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 db/migrate/20120705144244_add_unique_index_on_favorites.rb
@@ -3,7 +3,8 @@ class AddUniqueIndexOnFavorites < ActiveRecord::Migration
def self.up
# cleanup must happen synchronously in order to create the unique index
- Favorite.delete_all("id NOT IN (SELECT MIN(id) FROM favorites GROUP BY user_id, context_id, context_type)")
+ # the extra subquery is necessary to avoid error 1093 on mysql
+ Favorite.delete_all("id NOT IN (SELECT * FROM (SELECT MIN(id) FROM favorites GROUP BY user_id, context_id, context_type) x)")
add_index :favorites, [:user_id, :context_id, :context_type], :unique => true, :name => "index_favorites_unique_user_object"

0 comments on commit b54c740

Please sign in to comment.