discourse/db/migrate/20150914021445_create_user_profile_views.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

18 lines
718 B
Ruby

# frozen_string_literal: true
class CreateUserProfileViews < ActiveRecord::Migration[4.2]
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, [:viewed_at, :ip_address, :user_profile_id], where: "user_id IS NULL", unique: true, name: 'unique_profile_view_ip'
add_index :user_profile_views, [:viewed_at, :user_id, :user_profile_id], where: "user_id IS NOT NULL", unique: true, name: 'unique_profile_view_user'
end
end