2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
class CreateUserProfileViews < ActiveRecord::Migration[4.2]
|
2015-09-13 23:41:22 -04:00
|
|
|
def change
|
|
|
|
create_table :user_profile_views do |t|
|
|
|
|
t.integer :user_profile_id, null: false
|
|
|
|
t.datetime :viewed_at, null: false
|
|
|
|
t.inet :ip_address, null: false
|
|
|
|
t.integer :user_id
|
|
|
|
end
|
|
|
|
|
|
|
|
add_index :user_profile_views, :user_profile_id
|
|
|
|
add_index :user_profile_views, :user_id
|
|
|
|
add_index :user_profile_views,
|
|
|
|
%i[viewed_at ip_address user_profile_id],
|
|
|
|
where: "user_id IS NULL",
|
|
|
|
unique: true,
|
|
|
|
name: "unique_profile_view_ip"
|
|
|
|
add_index :user_profile_views,
|
|
|
|
%i[viewed_at user_id user_profile_id],
|
|
|
|
where: "user_id IS NOT NULL",
|
|
|
|
unique: true,
|
|
|
|
name: "unique_profile_view_user"
|
|
|
|
end
|
|
|
|
end
|