-- Search User + Font Settings (run once on existing DB)

CREATE TABLE IF NOT EXISTS `app_settings` (
  `setting_key` varchar(80) NOT NULL,
  `setting_value` text NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `app_settings` (`setting_key`, `setting_value`, `updated_at`)
VALUES ('ui_font_family', 'ibm_plex', NOW());

INSERT IGNORE INTO `app_modules` (`module_key`, `module_name`, `module_group`, `route`, `sort_order`) VALUES
('search_user_report', 'Search User Report', 'Users', 'report/search_user_report', 165),
('manage_font_settings', 'Font Settings', 'Administration', 'settings', 930);

-- Copy Search User perms from User Report
INSERT IGNORE INTO `app_role_permissions` (`role_id`, `module_key`, `can_view`, `can_export`)
SELECT `role_id`, 'search_user_report', `can_view`, `can_export`
FROM `app_role_permissions`
WHERE `module_key` = 'user_report';

-- Grant Font Settings to roles that can manage permissions (and superadmin via Install/grant_all)
INSERT IGNORE INTO `app_role_permissions` (`role_id`, `module_key`, `can_view`, `can_export`)
SELECT `role_id`, 'manage_font_settings', `can_view`, 0
FROM `app_role_permissions`
WHERE `module_key` = 'manage_permissions';
