diff --git a/db/migrate/20140715013018_correct_post_number_index.rb b/db/migrate/20140715013018_correct_post_number_index.rb new file mode 100644 index 000000000..5aeb03f7a --- /dev/null +++ b/db/migrate/20140715013018_correct_post_number_index.rb @@ -0,0 +1,26 @@ +class CorrectPostNumberIndex < ActiveRecord::Migration + def change + + begin + a = execute < 1 + ) pp ON p1.topic_id = pp.topic_id AND + p1.post_number >= pp.post_number AND + p1.id <> pp.min_id + ) +SQL + end until a.cmdtuples == 0 + + remove_index :posts, [:topic_id, :post_number] + add_index :posts, [:topic_id, :post_number], unique: true + end +end