-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add migration to add existing group creators as owners #9031
base: main
Are you sure you want to change the base?
Conversation
07bcd36
to
5a0c7c9
Compare
op.execute( | ||
update(user_group_table) | ||
.where( | ||
user_group_table.c.id.in_( | ||
select(user_group_table.c.id) | ||
.where(user_group_table.c.group_id == group_table.c.id) | ||
.where(user_group_table.c.user_id == user_table.c.id) | ||
.where(user_table.c.id == group_table.c.creator_id) | ||
) | ||
) | ||
.values(roles=["owner"]) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all existing groups will have creators. There are three cases:
- The user account of the group's creator has been deleted. In this case
"group".creator_id
isNULL
. There's nothing to do in this case. - The creator is no longer a member of the group. In this case
"group".creator_id
will still correspond to an existing"user".id
but there will be nouser_group
row with a matchinggroup_id
anduser_id
. Again there's nothing to do in this case. - The creator is still a member of the group. In this case we find the right
user_group
row and updateroles
to["owner"]
.
And of course we need to not update user_group
roles for non-creator memberships.
I'm hoping I can get away with updating all the rows at once as in the SQL query above. In the production DB there are 191,571 rows matching:
SELECT count(*)
FROM "group", "user", user_group
WHERE
"group".id = user_group.group_id
AND "user".id = user_group.user_id
AND "group".creator_id = "user".id;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping I can get away with updating all the rows at once as in the SQL query above. In the production DB there are 191,571 rows matching:
I reckon it would be fine but we should run it early in the morning just in case.
Depends on #9032