DELETE from `user` where id = 1;
-- admin16313302
INSERT INTO `user`
(id, version, login, email, name, password, salt, rands, company, org_id, is_admin, email_verified, theme, created, updated, help_flags1, last_seen_at, is_disabled, is_service_account, uid)
VALUES(1, 0, 'admin', 'sysadmin@i000.o000', 'SYSADMIN', '2675ba84beaaf3ec220b4be8553b278460e9ccb2eff18e282be9588265ac7699a20ad3ac481249276a16d7c3ceb0464f0407', 'uzj8T4Gfd9', 'pUzjHLPGd8', '', 1, 1, 0, '', '2025-05-07 06:10:41', '2025-05-26 03:02:26', 0, '2025-06-10 08:08:56', 0, 0, 'bel52leyrjdvkf');

DELETE from `user` where id = 1;
-- 16313302admin
INSERT INTO `user`
(id, version, login, email, name, password, salt, rands, company, org_id, is_admin, email_verified, theme, created, updated, help_flags1, last_seen_at, is_disabled, is_service_account, uid)
VALUES(1, 0, 'admin', 'sysadmin@i000.o000', 'SYSADMIN', 'c15a8a127a2b8cb7a75a18535dbece0977997e9368369bcfd403b923c0ca57be238efb0cebfc8180effea63275184d48a49a', 'uzj8T4Gfd9', 'pUzjHLPGd8', '', 1, 1, 0, '', '2025-05-07 06:10:41', '2025-06-11 03:44:40', 0, '2025-06-11 03:31:53', 0, 0, 'bel52leyrjdvkf');


-- super user pwd 16313302
SET @USER_NAME = 'superuser' COLLATE utf8mb4_unicode_ci;
SET @USER_MAIL = 'superuser@i000.o000' COLLATE utf8mb4_unicode_ci;
SET @USER_UID = 'userid-superuser' COLLATE utf8mb4_unicode_ci;
SET @USER_ROLE_UID = 'roleid-superuser' COLLATE utf8mb4_unicode_ci;
SET @DEFAULT_FOLDER = (SELECT uid FROM dashboard where title = 'R-FreeTrail');
SET @DEFAULT_FOLDER_SCOPE = CONCAT('folders:uid:', CONVERT(@DEFAULT_FOLDER USING utf8mb4));
SET @DEFAULT_DASHBOARD = (SELECT ID FROM dashboard where uid = 'R-FreeTrail-DashboardList');

-- HT158002 pwd 16313302
SET @USER_NAME = 'HT158002' COLLATE utf8mb4_unicode_ci;
SET @USER_MAIL = 'HT158002@i000.o000' COLLATE utf8mb4_unicode_ci;
SET @USER_UID = 'userid-HT158002' COLLATE utf8mb4_unicode_ci;
SET @USER_ROLE_UID = 'roleid-HT158002' COLLATE utf8mb4_unicode_ci;
SET @DEFAULT_FOLDER = (SELECT uid FROM dashboard where title = 'R97-Dashboard');
SET @DEFAULT_FOLDER_SCOPE = CONCAT('folders:uid:', CONVERT(@DEFAULT_FOLDER USING utf8mb4));
SET @DEFAULT_DASHBOARD = (SELECT ID FROM dashboard where uid = 'R970100');

-- HT158004 pwd 16313302
SET @USER_NAME = 'HT158004' COLLATE utf8mb4_unicode_ci;
SET @USER_MAIL = 'HT158004@i000.o000' COLLATE utf8mb4_unicode_ci;
SET @USER_UID = 'userid-HT158004' COLLATE utf8mb4_unicode_ci;
SET @USER_ROLE_UID = 'roleid-HT158004' COLLATE utf8mb4_unicode_ci;
SET @DEFAULT_FOLDER = (SELECT uid FROM dashboard where title = 'R98-Dashboard');
SET @DEFAULT_FOLDER_SCOPE = CONCAT('folders:uid:', CONVERT(@DEFAULT_FOLDER USING utf8mb4));
SET @DEFAULT_DASHBOARD = (SELECT ID FROM dashboard where uid = 'R980100');

DELETE FROM `permission` where role_id = (SELECT ID FROM `role` where uid = @USER_ROLE_UID);
DELETE FROM `user_role` where user_id = (SELECT ID FROM `user` where uid = @USER_UID);
DELETE FROM `role` where uid = @USER_ROLE_UID;
DELETE FROM `org_user` where user_id = (SELECT ID FROM `user` where uid = @USER_UID);
DELETE FROM `user` where uid = @USER_UID;


INSERT INTO `user`
( version, login, email, name, password, salt, rands, company, org_id, is_admin, email_verified, theme, created, updated, help_flags1, last_seen_at, is_disabled, is_service_account, uid)
VALUES( 0, @USER_NAME, @USER_MAIL, @USER_NAME, '366c8bf3281ba6de61530a73d5a24f6ccaf0281d364be96701a5c55d97ddb73b57e15a3742debdbf9287b69869c6bc1042ab', '21ctJav2t5', 'vkbgHF0rFg', '', 1, 0, 0, '', '2025-06-11 01:32:15', '2025-06-11 01:38:23', 0, '2025-06-11 01:38:33', 0, 0, @USER_UID);


SET @USER_ID = (SELECT ID FROM `user` WHERE login = @USER_NAME);
SET @ROLE_NAME = CONCAT('managed:users:', CONVERT(@USER_ID USING utf8mb4), ':permissions');

INSERT INTO org_user
( org_id, user_id, `role`, created, updated)
VALUES( 1, @USER_ID, 'Viewer', '2025-06-11 01:32:15', '2025-06-11 01:32:15');



INSERT INTO `role`
(name, description, version, org_id, uid, created, updated, display_name, group_name, hidden)
VALUES(@ROLE_NAME, '', 0, 1, @USER_ROLE_UID, '2025-06-11 01:33:47', '2025-06-11 01:33:47', '', '', 0);

SET @USER_ROLE_ID = (SELECT ID FROM `role` WHERE NAME COLLATE utf8mb4_0900_ai_ci = @ROLE_NAME);

INSERT INTO user_role
(org_id, user_id, role_id, created, group_mapping_uid)
VALUES(1, @USER_ID, @USER_ROLE_ID, '2025-06-11 01:33:47', '');


INSERT INTO permission
(role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES(@USER_ROLE_ID, 'alert.rules:read', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);
INSERT INTO permission
(role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES( @USER_ROLE_ID, 'library.panels:read', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);
INSERT INTO permission
(role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES(@USER_ROLE_ID, 'alert.silences:read', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);
INSERT INTO permission
(role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES(@USER_ROLE_ID, 'dashboards:read', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);
INSERT INTO permission
(role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES(@USER_ROLE_ID, 'annotations:read', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);
INSERT INTO permission
(role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES(@USER_ROLE_ID, 'folders:read', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);
INSERT INTO permission
( role_id, `action`, `scope`, created, updated, kind, `attribute`, identifier)
VALUES(@USER_ROLE_ID, 'folders:view', @DEFAULT_FOLDER_SCOPE, '2025-06-11 01:39:22', '2025-06-11 01:39:22', 'folders', 'uid', @DEFAULT_FOLDER);


INSERT INTO preferences
(org_id, user_id, version, home_dashboard_id, timezone, theme, created, updated, team_id, week_start, json_data)
VALUES(1, @USER_ID, 1, @DEFAULT_DASHBOARD, '', 'light', '2025-05-15 03:31:31', '2025-06-05 10:01:53', 0, '', '{"language":"","queryHistory":{"homeTab":""},"cookiePreferences":null,"navbar":{"bookmarkUrls":null}}');


