fix user index to add name
this is to facilitate emails getting duplicated for proxy voters
This commit is contained in:
parent
18efca8863
commit
5042a7f235
|
@ -171,9 +171,8 @@ class UsersController < ApplicationController
|
|||
users = CSV.parse(users_csv, :headers => true).map { |row|
|
||||
fields = row.to_hash
|
||||
fields[:room_id] = room_id
|
||||
fields
|
||||
User.upsert(fields, unique_by: [:room_id, :email, :name])
|
||||
}
|
||||
User.upsert_all(users, unique_by: [:room_id, :email])
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to room_users_url(room_id), notice: 'Users were successfully created.' }
|
||||
|
|
|
@ -7,6 +7,5 @@ class User < ApplicationRecord
|
|||
attribute :vote, :boolean, default: true
|
||||
attribute :proxy, :boolean, default: false
|
||||
|
||||
validates :email, uniqueness: { scope: :room_id }
|
||||
validates :room_id, uniqueness: { scope: :email }
|
||||
validates :name, uniqueness: { scope: [:room_id, :email] }
|
||||
end
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class UpsertableProxyProofUsers < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
remove_index :users, column: [:room_id, :email]
|
||||
add_index :users, [:room_id, :email, :name], unique: true
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue