diff options
author | Valery Sizov <vsv2711@gmail.com> | 2014-11-27 14:34:39 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2014-12-04 14:03:55 +0300 |
commit | 3a5ed5260b24051939575d1934ce9b8392cac09f (patch) | |
tree | 04d361e52d16234f00e5cdd27b5ebfef9a503579 /db/migrate | |
parent | 1a80d13a3990937580c97e2b0ba8fb98f69bc055 (diff) |
Supporting for multiple omniauth provider for the same user
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20141121161704_add_identity_table.rb | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/db/migrate/20141121161704_add_identity_table.rb b/db/migrate/20141121161704_add_identity_table.rb index 7d019c65ee1..243958039af 100644 --- a/db/migrate/20141121161704_add_identity_table.rb +++ b/db/migrate/20141121161704_add_identity_table.rb @@ -8,14 +8,25 @@ class AddIdentityTable < ActiveRecord::Migration add_index :identities, :user_id - User.where("provider is not NULL").find_each do |user| + User.where("provider IS NOT NULL").find_each do |user| execute "INSERT INTO identities(provider, extern_uid, user_id) VALUES('#{user.provider}', '#{user.extern_uid}', '#{user.id}')" end - #TODO remove user's columns extern_uid and provider + remove_column :users, :extern_uid + remove_column :users, :provider end def down -#TODO + add_column :users, :extern_uid, :string + add_column :users, :provider, :string + + User.where("id IN(SELECT user_id FROM identities)").find_each do |user| + identity = user.identities.last + user.extern_uid = identity.extern_uid + user.provider = identity.provider + user.save + end + + drop_table :identities end end |