From 5b18f3641edf953d4c8069a31c7e130fc7e850b7 Mon Sep 17 00:00:00 2001 From: Jonathan Chen Date: Wed, 31 Aug 2016 15:52:59 -0400 Subject: [PATCH 1/2] Add unique index to email Why: Keep data consistent with multiple processes and match devise gem implementation References: https://robots.thoughtbot.com/the-perils-of-uniqueness-validations https://github.com/plataformatec/devise/blob/master/lib/generators/active_record/templates/migration.rb#L13 --- .../templates/devise_token_auth_create_users.rb.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb b/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb index a6651dbfe..6a380a467 100644 --- a/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +++ b/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb @@ -45,7 +45,7 @@ class DeviseTokenAuthCreate<%= user_class.pluralize %> < ActiveRecord::Migration t.timestamps end - add_index :<%= user_class.pluralize.underscore %>, :email + add_index :<%= user_class.pluralize.underscore %>, :email, :unique => true add_index :<%= user_class.pluralize.underscore %>, [:uid, :provider], :unique => true add_index :<%= user_class.pluralize.underscore %>, :reset_password_token, :unique => true # add_index :<%= user_class.pluralize.underscore %>, :confirmation_token, :unique => true From 06db9ad0adc6e10fb4bfb83677bc3c499e4e6d60 Mon Sep 17 00:00:00 2001 From: Jonathan Chen Date: Wed, 31 Aug 2016 15:57:06 -0400 Subject: [PATCH 2/2] Update Ruby hash syntax --- .../templates/devise_token_auth_create_users.rb.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb b/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb index 6a380a467..c773a2ce7 100644 --- a/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb +++ b/lib/generators/devise_token_auth/templates/devise_token_auth_create_users.rb.erb @@ -45,10 +45,10 @@ class DeviseTokenAuthCreate<%= user_class.pluralize %> < ActiveRecord::Migration t.timestamps end - add_index :<%= user_class.pluralize.underscore %>, :email, :unique => true - add_index :<%= user_class.pluralize.underscore %>, [:uid, :provider], :unique => true - add_index :<%= user_class.pluralize.underscore %>, :reset_password_token, :unique => true - # add_index :<%= user_class.pluralize.underscore %>, :confirmation_token, :unique => true - # add_index :<%= user_class.pluralize.underscore %>, :unlock_token, :unique => true + add_index :<%= user_class.pluralize.underscore %>, :email, unique: true + add_index :<%= user_class.pluralize.underscore %>, [:uid, :provider], unique: true + add_index :<%= user_class.pluralize.underscore %>, :reset_password_token, unique: true + # add_index :<%= user_class.pluralize.underscore %>, :confirmation_token, unique: true + # add_index :<%= user_class.pluralize.underscore %>, :unlock_token, unique: true end end