summaryrefslogtreecommitdiff
path: root/db/migrate/20160119145451_add_ldap_email_to_users.rb
blob: bf8c27900b8ee40cb17059b5f6f6523bb3ea3498 (plain)
1
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
# rubocop:disable all
class AddLdapEmailToUsers < ActiveRecord::Migration[4.2]
  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