fix user index to add name

this is to facilitate emails getting duplicated for proxy voters
This commit is contained in:
Kiara Grouwstra 2023-01-27 18:24:09 +01:00
parent 18efca8863
commit 5042a7f235
3 changed files with 8 additions and 4 deletions

View File

@ -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.' }

View File

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

View File

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