Don't delete facebook invitations
This commit is contained in:
parent
f8b7307441
commit
3afd529379
2 changed files with 7 additions and 5 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
class EliminateStrayUserRecords < ActiveRecord::Migration
|
class EliminateStrayUserRecords < ActiveRecord::Migration
|
||||||
def self.up
|
def self.up
|
||||||
duplicated_emails = execute("SELECT LOWER(email) from users GROUP BY LOWER(email) HAVING COUNT(*) > 1").to_a
|
duplicated_emails = execute("SELECT LOWER(email) from users WHERE users.email != '' GROUP BY LOWER(email) HAVING COUNT(*) > 1").to_a
|
||||||
duplicated_emails.each do |email|
|
duplicated_emails.each do |email|
|
||||||
records = execute("SELECT users.id, users.username, users.created_at from users WHERE LOWER(users.email) = '#{email}'").to_a
|
records = execute("SELECT users.id, users.username, users.created_at from users WHERE LOWER(users.email) = '#{email}'").to_a
|
||||||
with_username = records.select { |r| !r[1].blank? }
|
with_username = records.select { |r| !r[1].blank? }
|
||||||
if with_username.length == 1
|
if with_username.length == 1
|
||||||
execute("DELETE FROM users WHERE LOWER(users.email) = '#{email}' AND users.username IS NULL")
|
execute("DELETE FROM users WHERE LOWER(users.email) = '#{email}' AND users.username IS NULL")
|
||||||
end
|
end
|
||||||
if with_username.length == 0
|
if with_username.length == 0 && !email.blank?
|
||||||
newest_record = records.sort_by{|r| r[2].to_i}.last
|
newest_record = records.sort_by{|r| r[2].to_i}.last
|
||||||
execute("DELETE FROM users WHERE LOWER(users.email) = '#{email}' AND users.id != #{newest_record[0]}")
|
execute("DELETE FROM users WHERE LOWER(users.email) = '#{email}' AND users.id != #{newest_record[0]}")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110507212759) do
|
ActiveRecord::Schema.define(:version => 20110513175000) do
|
||||||
|
|
||||||
create_table "aspect_memberships", :force => true do |t|
|
create_table "aspect_memberships", :force => true do |t|
|
||||||
t.integer "aspect_id", :null => false
|
t.integer "aspect_id", :null => false
|
||||||
|
|
@ -357,9 +357,11 @@ ActiveRecord::Schema.define(:version => 20110507212759) do
|
||||||
t.string "language"
|
t.string "language"
|
||||||
t.string "email", :default => "", :null => false
|
t.string "email", :default => "", :null => false
|
||||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||||
t.string "password_salt", :default => "", :null => false
|
t.string "invitation_token", :limit => 60
|
||||||
t.string "invitation_token", :limit => 20
|
|
||||||
t.datetime "invitation_sent_at"
|
t.datetime "invitation_sent_at"
|
||||||
|
t.integer "invitation_limit"
|
||||||
|
t.integer "invited_by_id"
|
||||||
|
t.string "invited_by_type"
|
||||||
t.string "reset_password_token"
|
t.string "reset_password_token"
|
||||||
t.string "remember_token"
|
t.string "remember_token"
|
||||||
t.datetime "remember_created_at"
|
t.datetime "remember_created_at"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue