impress/db/migrate/20120321222001_index_closet_hanger_query.rb
Matchu b2a027fbbf Oops, should've used migration version 4.2
Oh I didn't realize the lowest version Rails had for this is 4.2. I wish running `rake db:migrate` checked this, but I'm running into it on another branch when I try to create a *new* migration which for some reason leads it to inspect the old migrations and notice the issue. Weird!
2023-10-23 19:05:08 -07:00

22 lines
910 B
Ruby

class IndexClosetHangerQuery < ActiveRecord::Migration[4.2]
def self.up
# SELECT COUNT(DISTINCT `closet_hangers`.`id`) FROM `closet_hangers` INNER
# JOIN `users` ON `users`.`id` = `closet_hangers`.`user_id` LEFT OUTER JOIN
# `closet_lists` ON `closet_lists`.`id` = `closet_hangers`.`list_id` WHERE
# `closet_hangers`.`owned` = XXX AND (`closet_hangers`.item_id = XXX) AND
# ((`closet_hangers`.`list_id` IS NULL AND
# `users`.`owned_closet_hangers_visibility` >= XXX OR
# `closet_lists`.`visibility` >= XXX));
# It's not a huge improvement over the association index, but it's nice to
# be able to scan fewer rows for so little penalty, right?
remove_index :closet_hangers, :item_id
add_index :closet_hangers, [:item_id, :owned]
end
def self.down
remove_index :closet_hangers, [:item_id, :owned]
add_index :closet_hangers, :item_id
end
end