Add uniq_ip_or_user_id_topic_views index concurrently.

This commit is contained in:
Guo Xiang Tan 2018-07-16 23:45:18 +08:00
parent c0c263405a
commit 59e72b466a
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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