RENAME TABLE `ohrm_saml_id_provider` TO `ohrm_saml_provider`;
ALTER TABLE `ohrm_saml_provider` ADD COLUMN `type` VARCHAR(10) AFTER `name`;
ALTER TABLE `ohrm_saml_provider` ADD COLUMN `file_name`  VARCHAR(255) DEFAULT NULL AFTER `status`;
ALTER TABLE `ohrm_saml_provider` ADD COLUMN `file_type` VARCHAR(255) DEFAULT NULL  AFTER `file_name`;
ALTER TABLE `ohrm_saml_provider` ADD COLUMN `file_size` VARCHAR(10) AFTER `file_type`;

CREATE TABLE IF NOT EXISTS `ohrm_saml_provider_attribute` (
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `provider_id` int(10) NOT NULL,
    `token_id` int(10) NOT NULL,
    `claim_name` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`id`),
    CONSTRAINT `fk_ohrm_saml_provider_attribute_provider_id` FOREIGN KEY (`provider_id`) REFERENCES `ohrm_saml_provider`(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT `fk_ohrm_saml_provider_attribute_token_id` FOREIGN KEY (`token_id`) REFERENCES `ohrm_token`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;


UPDATE `ohrm_saml_provider` SET `type` = 'SP';

SET @module_id := (SELECT `id`  FROM `ohrm_module` WHERE `name` = 'oauth');

INSERT INTO `ohrm_token` ( `name`, `display_name`, `class_name`, `entity_name`, `value_getters`, `data_group_id`, `is_date`, `localize`, `parameters`, `custom_field_id`) VALUES ( 'uid', 'unique ID', NULL, 'SystemUser', 'getUserName', NULL, '0', '0', NULL, NULL);

SET @token_id := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_restricted_module_token`(  `token_id`, `restricted_module`) VALUES ( @token_id ,@module_id);


INSERT INTO `ohrm_token` ( `name`, `display_name`, `class_name`, `entity_name`, `value_getters`, `data_group_id`, `is_date`, `localize`, `parameters`, `custom_field_id`) VALUES ( 'givenName', 'Given Name', NULL, 'Employee', 'getFirstName', NULL, '0', '0', NULL, NULL);

SET @token_id := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_restricted_module_token`(  `token_id`, `restricted_module`) VALUES ( @token_id ,@module_id);


INSERT INTO `ohrm_token` ( `name`, `display_name`, `class_name`, `entity_name`, `value_getters`, `data_group_id`, `is_date`, `localize`, `parameters`, `custom_field_id`) VALUES ( 'cn', 'Common Name', NULL, 'Employee', 'getFullName', NULL, '0', '0', NULL, NULL);

SET @token_id := (SELECT LAST_INSERT_ID());
INSERT INTO `ohrm_restricted_module_token`(  `token_id`, `restricted_module`) VALUES ( @token_id ,@module_id);


INSERT INTO `ohrm_token` ( `name`, `display_name`, `class_name`, `entity_name`, `value_getters`, `data_group_id`, `is_date`, `localize`, `parameters`, `custom_field_id`) VALUES ( 'email', 'Email', NULL, 'Employee', 'getEmpWorkEmail', NULL, '0', '0', NULL, NULL);

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

INSERT INTO `ohrm_restricted_module_token`(  `token_id`, `restricted_module`) VALUES ( @token_id ,@module_id);


SET @saml_configuration_data_group_id := (SELECT id FROM ohrm_data_group where `name` = 'saml_configuration');

UPDATE ohrm_data_group SET `description` = 'HR Administration - SAML Authentication Configuration'  where id= @saml_configuration_data_group_id;

INSERT INTO ohrm_user_role_type_data_group(user_role_type_id, data_group_id,can_read,can_create,can_update,can_delete) VALUES
(1, @saml_configuration_data_group_id,1,0,0,0);