Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /*DROP TABLE IF EXISTS `update_statements`;
  2. create table update_statements (
  3. commands varchar(1024)
  4. );*/
  5.  
  6. -- ------------------- UAA TO LDAP PROCEDURE FOR CLOUD FOUNDRY ---------------------------------------------------------
  7. DELIMITER $$
  8. DROP PROCEDURE IF EXISTS UAA_MIG$$
  9. CREATE PROCEDURE UAA_MIG()
  10. Begin
  11. DECLARE done INT DEFAULT FALSE;
  12. DECLARE var_id char(36);
  13. DECLARE var_external_id varchar(255);
  14. DECLARE loop_done INT DEFAULT 0;
  15. DECLARE loop_users CURSOR for
  16. select id, external_id from users where username not like "user2@myorg.com" and username not like "user1.%@myorg.com" and username not like "user3@myorg.com" and users.id in (
  17. select id from users where username like "%@myorg.com" or username like "%@externalcompany.com" or username like "%@myorg-sub1.com");
  18. DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  19. select count(id) into @nb_users_ldap_before from users where origin="ldap";
  20. select count(id) into @nb_users_uaa_before from users where origin="uaa";
  21. Open loop_users;
  22. read_loop: Loop
  23. SET done = FALSE ;
  24. FETCH loop_users INTO var_id, var_external_id;
  25. IF done THEN
  26. LEAVE read_loop;
  27. END IF;
  28. -- update command
  29. update users set origin="ldap", external_id=concat("uid=", var_external_id ,",ou=people,dc=myorg,dc=com") where users.id=var_id;
  30. -- solution with temp table
  31. -- insert into update_statements values (concat("update users set origin=\'ldap\', external_id=\"uid=", var_external_id ,",ou=people,dc=myorg,dc=com\" where users.id=\"", var_id,"\""));
  32. END LOOP;
  33. CLOSE loop_users;
  34.  
  35. select count(id) into @nb_users from users;
  36. select count(id) into @nb_users_ldap_after from users where origin="ldap";
  37. select count(id) into @nb_users_uaa_after from users where origin="uaa";
  38. select concat ('Before Migration : ', @nb_users_uaa_before, ' / ', @nb_users ,' | After Migration : ', @nb_users_uaa_after, ' / ', @nb_users ) as 'NB of users <UAA>';
  39. select concat ('Before Migration ', @nb_users_ldap_before, ' / ', @nb_users , ' | After Migration : ', @nb_users_ldap_after, ' / ', @nb_users) as 'NB of users <LDAP>';
  40. END;
  41. $$
  42. DELIMITER ;
  43. call UAA_MIG();
  44. -- END ------------------- Procedure pour la migration---------------------------------------------------------
  45.  
  46. DROP PROCEDURE IF EXISTS UAA_MIG;
  47. -- drop table update_statements;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement