Abort migration if there are post-visibilities left, so that the db is not left with no index

This commit is contained in:
Raphael Sofaer 2011-02-11 15:01:47 -08:00
parent 31fef1a55d
commit 02a66466fe

View file

@ -22,6 +22,8 @@ class UniqueIndexPostVisibilities < ActiveRecord::Migration
end end
execute("DELETE FROM `post_visibilities` WHERE `post_visibilities`.id IN (#{undesired_ids.join(",")});") unless undesired_ids.empty? execute("DELETE FROM `post_visibilities` WHERE `post_visibilities`.id IN (#{undesired_ids.join(",")});") unless undesired_ids.empty?
new_result = execute(sql)
raise "Not all violating visibilities deleted" unless new_result.to_a.empty?
remove_index :post_visibilities, [:aspect_id, :post_id] remove_index :post_visibilities, [:aspect_id, :post_id]
add_index :post_visibilities, [:aspect_id, :post_id], :unique => true add_index :post_visibilities, [:aspect_id, :post_id], :unique => true