FIX: add unique index for 'vote_count' topic custom fields.

FIX: add unique index for ‘vote_count’ topic custom fields.

It shouldn’t have duplicates else it breaks the code.

diff --git a/db/migrate/20190625085735_add_vote_count_index_to_topic_custom_fields.rb b/db/migrate/20190625085735_add_vote_count_index_to_topic_custom_fields.rb
new file mode 100644
index 0000000..e968d5a
--- /dev/null
+++ b/db/migrate/20190625085735_add_vote_count_index_to_topic_custom_fields.rb
@@ -0,0 +1,13 @@
+class AddVoteCountIndexToPostCustomFields < ActiveRecord::Migration[5.2]
+  def change
+    execute <<~SQL
+      DELETE FROM topic_custom_fields f
+      WHERE name = 'vote_count' AND id > (
+        SELECT MIN(f2.id) FROM topic_custom_fields f2
+          WHERE f2.topic_id = f.topic_id AND f2.name = f.name
+      )
+    SQL
+
+    add_index :topic_custom_fields, :topic_id, unique: true, where: "name = 'vote_count'"
+  end
+end

GitHub sha: f552e249