Abort migration if there are post-visibilities left, so that the db is not left with no index
This commit is contained in:
parent
31fef1a55d
commit
02a66466fe
1 changed files with 2 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue