create table `ohrm_external_app` (
    `id` int(11) not null auto_increment,
    `name` varchar(255) not null,
    `client_id` varchar(80) null,
    primary key (id),
    CONSTRAINT `fk_ohrm_external_app_oauth_client` FOREIGN KEY (`client_id`) REFERENCES `ohrm_oauth_client` (`client_id`) ON DELETE SET NULL ON UPDATE CASCADE
) engine=innodb default charset=utf8;

INSERT INTO `ohrm_external_app` (`id`,`name`, `client_id`) VALUES
(1, 'Web', 'public_rest_api_client'),
(2, 'Mobile', 'mobile_rest_api_client'),
(3, 'System Task', NULL),
(4, 'Upgrader', NULL);

create table `ohrm_external_usage_log` (
    `id` int(11) not null auto_increment,
    `from_screen` text null,
    `to_screen` text null,
    `api` text null,
    `api_version` int(11) null,
    `action` varchar(255) null,
    `description` text null,
    `user` text null,
    `ip` varchar(255) null,
    `user_agent` varchar(255) null,
    `session` varchar(255) null,
    `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `app_id` int(11) null,
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `published_to_warehouse` boolean not null default false,
    `current_menu` varchar(1000) default null,
    `clicked_on` varchar(255) default null,
    primary key (id),
    CONSTRAINT `fk_ohrm_external_usage_log_app` FOREIGN KEY (`app_id`) REFERENCES `ohrm_external_app` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) engine=innodb default charset=utf8;

INSERT INTO `ohrm_module`(`name`, `status`) VALUES ('navigation', 1);

SET @event_listener_max_position := (SELECT MAX(`position`) FROM `ohrm_event_listener`);
INSERT INTO `ohrm_event_listener` (`event`, `listener_class`, `enabled`, `position`) VALUES ('leave.change', 'UserActionListener', '1', @event_listener_max_position + 1);
INSERT INTO `ohrm_event_listener` (`event`, `listener_class`, `enabled`, `position`) VALUES ('user_navigation', 'NavigationAndAPICallListener', '1', @event_listener_max_position + 2);

INSERT INTO `ohrm_cleanup_entities_config` ( `entity_name`, `configuration`, `delete_days_after`, `date_configuration_getter`, `delete_strategy`)
VALUES ('UsageLog', '{"rowDelete":true}', '90', 'time', 'BaseDataDeletionStrategyDao');
