/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 *                                                                             *
 * Create a role in user_role for every group_name in user_group               *
 *                                                                             *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
Enable the ti_user_role trigger to generate user_role_id
*/

INSERT INTO user_role (
      user_role_id
    , user_role_name
    , agent_code
) (
    SELECT 0
         , rtrim (group_name)
         , agent_code
    FROM user_group
    WHERE (rtrim (group_name), agent_code) NOT IN (SELECT user_role_name, agent_code FROM user_role)
    GROUP BY agent_code ,rtrim (group_name)
);

