20160119145451_add_ldap_email_to_users.rb 847 Bytes
Newer Older
1
# rubocop:disable all
2
class AddLdapEmailToUsers < ActiveRecord::Migration[4.2]
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  def up
    add_column :users, :ldap_email, :boolean, default: false, null: false

    if Gitlab::Database.mysql?
      execute %{
        UPDATE users, identities
        SET users.ldap_email = TRUE
        WHERE identities.user_id = users.id
        AND users.email LIKE 'temp-email-for-oauth%'
        AND identities.provider LIKE 'ldap%'
        AND identities.extern_uid IS NOT NULL
      }
    else
      execute %{
        UPDATE users
        SET ldap_email = TRUE
        FROM identities
        WHERE identities.user_id = users.id
        AND users.email LIKE 'temp-email-for-oauth%'
        AND identities.provider LIKE 'ldap%'
        AND identities.extern_uid IS NOT NULL
      }
    end
  end

  def down
    remove_column :users, :ldap_email
  end
end