Open zenovich opened 1 month ago
The first case have been fixed by https://github.com/France-ioi/AlgoreaBackend/pull/1098 , it shouldn't happen again. I noticed the transition
system later on. Would it be possible to add database constraints to make sure group_membership_changes
and group_pending_requests
are consistent?
@GeoffreyHuck, unfortunately, I don't think it's possible to add such constraints.
group_membership_changes
is a changes log, it's latest row for (group_id
, member_id
) pair is related to the row in group_pending_requests
for the same pair with the same value in at
. At the same time, there can be several rows in group_membership_changes
with the same (group_id
, member_id
, at
) triple. So, as it's impossible to use a SELECT statement in foreign key constraint definitions in MySQL, we cannot create such constraints.
Ok, then we should at least have a short documentation about this Transition system, how it works and how to use it.
And something that would prevent adding/modifying rows without using this Transition system. Because it's so easy to put the database in an inconsistent state. Maybe writing it down in the PR review process? Do you have any idea?
For the documentation, I would start from reading this list of constants: https://pkg.go.dev/github.com/France-ioi/AlgoreaBackend/v2@v2.21.1/app/database#GroupGroupTransitionAction (probably you did that already) If it's not enough, let's decide what else we should document.
Adding a note about preventing modifications of group_pending_request/group_membership_changes in the PR review process would be really helpful. But, at the same time, we still add new rows into group_membership_changes and remove rows from group_pending_requests outside of the transition system: https://github.com/France-ioi/AlgoreaBackend/blob/master/app/api/groups/update_group.go#L342
In our dev DB (don't now about the prod) there is a pending invitation without corresponding group_membership_changes logged:
Also, there is a pending 'join_request' without a corresponding group membership change:
This needs to be investigated as it affects the invitationsView and groupRequestsView services.