From 02a66466fe5f9f8f381c5fca57a6a5e5c8c659ba Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Fri, 11 Feb 2011 15:01:47 -0800 Subject: [PATCH] Abort migration if there are post-visibilities left, so that the db is not left with no index --- db/migrate/20110211204804_unique_index_post_visibilities.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20110211204804_unique_index_post_visibilities.rb b/db/migrate/20110211204804_unique_index_post_visibilities.rb index 2d2bbebc9..70b7f2164 100644 --- a/db/migrate/20110211204804_unique_index_post_visibilities.rb +++ b/db/migrate/20110211204804_unique_index_post_visibilities.rb @@ -22,6 +22,8 @@ class UniqueIndexPostVisibilities < ActiveRecord::Migration end 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] add_index :post_visibilities, [:aspect_id, :post_id], :unique => true