Created
November 1, 2021 14:10
-
-
Save webarchitect609/c692525b72134d43214764370d4db91f to your computer and use it in GitHub Desktop.
Удаляет персональные данные Битрикс пользователей
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Собрать id пользователей, данные которых требуется сохранить. | |
-- (вместо "ID not in(6)" следует описать условие выборки групп пользователей для сохранения) | |
create temporary table if not exists `tmp_keep_users_id_list` (`ID` int(18) NOT NULL); | |
truncate `tmp_keep_users_id_list`; | |
insert into `tmp_keep_users_id_list` ( | |
select U.ID | |
from b_user as U | |
inner join b_user_group as UG | |
on U.ID = UG.USER_ID | |
where | |
UG.GROUP_ID in( | |
select ID from b_group where ID <> 2 and ID not in(6) | |
) | |
or U.ID = 1 | |
group by U.ID | |
); | |
-- Удалить всех пользователей кроме тех, которых надо сохранить, вместе со всеми связанными данными. | |
delete from b_user where ID not in(select * from tmp_keep_users_id_list); | |
delete from b_uts_user where VALUE_ID not in(select * from tmp_keep_users_id_list); | |
delete from b_rating_user where ENTITY_ID not in(select * from tmp_keep_users_id_list); | |
delete from b_user_group where USER_ID not in(select * from tmp_keep_users_id_list); | |
delete from b_user_access where USER_ID not in(select * from tmp_keep_users_id_list); | |
delete from b_user_access_check where USER_ID not in(select * from tmp_keep_users_id_list); | |
delete from b_user_option where USER_ID not in(select * from tmp_keep_users_id_list); | |
-- Удалить временную таблицу. | |
drop temporary table `tmp_keep_users_id_list`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Скрипт хоть и правильный, но запросы на удаление в нём крайне неоптимальные и долгие. Не рекомендуется использовать на крупных объёмах данных.