Organization transfer: Reassign todos where bot is the author

What does this MR do and why?

When transferring users to a new organization we need to reassign any todos authored by internal bots. Each org has its own distinct internal bots. Of note, when querying for a bot by organization, the bot will be auto-created if it doesn't exist.

This code change adds functionality to handle "todo" items when transferring groups between organizations in GitLab.

When a group moves from one organization to another, the system now automatically updates any todo items that were created by automated bot accounts (like support bots, security bots, etc.) so they point to the equivalent bots in the new organization. This ensures that todo notifications and assignments remain properly connected after the transfer.

The change also includes comprehensive tests to verify that bot-authored todos get updated correctly while human-authored todos remain unchanged, and that only todos belonging to users in the transferred group are affected.

Many thanks to @atevans for your work on Organization level Internal bot Users (#442780 - closed). It makes this change a lot easier.

References

Todos transfer edge case (#574004 - closed)

Database

Explain: https://postgres.ai/console/gitlab/gitlab-production-main/sessions/44868/commands/137731

The above explain used GitLab user IDs and the GitLab.com Duo bot. Bot users should author relatively few Todos so I added the author filter first, followed by the user ID batch which will be max 50 users. This should ensure very quick/performant queries.

UPDATE todos
SET
    author_id = 3650
WHERE
    todos.author_id = 3641 AND
    todos.user_id IN ( 3616, 3611, 3615 );
-- Formatted by Pg::SQL::PrettyPrinter

Screenshots or screen recordings

Before After

How to set up and validate locally

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Drew Blessing

Merge request reports

Loading