START TRANSACTION;

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT DISTINCT rp.role_id, target.id
FROM role_permissions rp
JOIN permissions source ON source.id = rp.permission_id
JOIN permissions target ON target.code = 'spk.terminals.manage'
WHERE source.code = 'spk.manage_departments';

COMMIT;
