From e45d5f7f44060e13b9aac830b3062d3ede327342 Mon Sep 17 00:00:00 2001
From: Marin Jankovski <maxlazio@gmail.com>
Date: Fri, 7 Nov 2014 13:50:54 +0100
Subject: [PATCH] Fix broken ldap migration.

---
 ...3133925_rename_ldap_group_to_ldap_group_link.rb | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb b/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb
index f070c22c733..d3e940a96df 100644
--- a/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb
+++ b/db/migrate/20140813133925_rename_ldap_group_to_ldap_group_link.rb
@@ -4,16 +4,10 @@ class RenameLdapGroupToLdapGroupLink < ActiveRecord::Migration
 
     # NOTE: we use the old_ methods because the new methods are overloaded
     # for backwards compatibility
-
-    Group.where.not(ldap_cn: nil).each do |group|
-      # Make sure we use the database column, not the model methods
-      ldap_cn = group.read_attribute(:ldap_cn)
-      ldap_access = group.read_attribute(:ldap_access)
-
-      group.ldap_group_links.where(cn: ldap_cn).first_or_create do |ldap_group_link|
-        ldap_group_link.group_access = ldap_access
-      end
-    end
+    time = Time.now.strftime('%Y-%m-%d %H:%M:%S')
+    execute "INSERT INTO ldap_group_links ( group_access, cn, group_id, created_at, updated_at )
+             SELECT ldap_access, ldap_cn, id, DATE('#{time}'), DATE('#{time}') FROM namespaces
+             WHERE ldap_cn IS NOT NULL;"
   end
 
   def down
-- 
2.30.9