Skip to content

A platform for community discussion. Free, open, simple.

Add uniq_ip_or_user_id_topic_views index concurrently.

Guo Xiang Tan59e72b466a61
diff --git a/db/migrate/20180521175611_change_indexes_topic_view_item.rb b/db/migrate/20180521175611_change_indexes_topic_view_item.rb
index 718377d758f..97f5afe8432 100644
--- a/db/migrate/20180521175611_change_indexes_topic_view_item.rb
+++ b/db/migrate/20180521175611_change_indexes_topic_view_item.rb
@@ -11,13 +11,11 @@ class ChangeIndexesTopicViewItem < ActiveRecord::Migration[5.1]
column: [:ip_address, :topic_id],
name: :ip_address_topic_id_topic_views,
unique: true
+
remove_index :topic_views,
column: [:user_id, :topic_id],
name: :user_id_topic_id_topic_views,
unique: true
- add_index :topic_views, [:user_id, :ip_address, :topic_id],
- name: :uniq_ip_or_user_id_topic_views,
- unique: true
end
def down
diff --git a/db/migrate/20180716140323_add_uniq_ip_or_user_id_topic_views.rb b/db/migrate/20180716140323_add_uniq_ip_or_user_id_topic_views.rb
new file mode 100644
index 00000000000..4b33877ee6f
--- /dev/null
+++ b/db/migrate/20180716140323_add_uniq_ip_or_user_id_topic_views.rb
@@ -0,0 +1,15 @@
+class AddUniqIpOrUserIdTopicViews < ActiveRecord::Migration[5.2]
+ disable_ddl_transaction!
+
+ def change
+ unless index_exists?(:topic_views, [:user_id, :ip_address, :topic_id],
+ name: :uniq_ip_or_user_id_topic_views
+ )
+
+ add_index :topic_views, [:user_id, :ip_address, :topic_id],
+ name: :uniq_ip_or_user_id_topic_views,
+ unique: true,
+ algorithm: :concurrently
+ end
+ end
+end