CREATE TABLE `ohrm_data_group_restriction` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `map_xml` TEXT NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

ALTER TABLE  `ohrm_user_role_data_group` ADD  `restriction_id` INT( 11 )  NULL AFTER  `self` ;
ALTER TABLE  `ohrm_user_role_data_group` ADD INDEX (  `restriction_id` ) ;
ALTER TABLE ohrm_user_role_data_group ADD CONSTRAINT fk_ohrm_user_role_data_group_restriction FOREIGN KEY (restriction_id) REFERENCES ohrm_data_group_restriction(id);

SET @moduleId := (SELECT `id` FROM `ohrm_module` where `name`='admin');
SET @admin_role_id := (SELECT `id` FROM `ohrm_user_role` WHERE `name` = 'Admin');

INSERT INTO `ohrm_screen` (`name`, `module_id`, `action_url`) VALUES
('Restricted UserRoles', @moduleId, 'addRestrictedUserRoles');

SET @screenId := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_data_group` (`name`, `description`, `can_read`, `can_create`, `can_update`, `can_delete`) VALUES
('data_group_restriction', 'Data Group Restriction', '1', '1', '1', '1');

SET @dataGroupId := (SELECT LAST_INSERT_ID());

INSERT INTO `ohrm_user_role_data_group` (`user_role_id`,`data_group_id`,`can_read`,`can_create`,`can_update`,`can_delete`,`self`,`restriction_id`)
VALUES (@admin_role_id,@dataGroupId, 1, 1, 1, 1, 0, null);

INSERT INTO `ohrm_user_role_screen` (`user_role_id`,`screen_id`,`can_read`,`can_create`,`can_update`,`can_delete`)
VALUES (@admin_role_id,@screenId , 1, 1, 1, 1);

INSERT INTO `ohrm_data_group_screen` (`data_group_id`,`screen_id`,`permission`,`self`)
VALUES(@dataGroupId, @screenId ,1,1);