Open zachmullen opened 3 years ago
Users -> Quotas is an injective but not bijective function
To clarify, the current implementation (all quotas are user-level) is indeed bijective (i.e. every user has a quota, every quota has a user). The future feature of project-level quotas will relax this (i.e. every user will still have a quota, but every quota will not have a user).
2. Create a dedicated associative relation
(user_id, quota_id)
, both of which columns have independent unique constraints.
I'm not clear on how this would provide any additional DB-level integrity. It would still be theoretically possible to have a user without a quota, right? Is there another additional guarantee which this provides?
It'll be theoretically possible in the database to have a user without a quota unless we are able to modify the user relation itself (which would be great except Django says no), or else add custom database triggers or functions (which probably aren't worth our time to maintain). This is really only in the interest of good database design: avoiding nullable columns where possible, and trying to avoid overpacking null values with semantics.
Users -> Quotas is an injective but not bijective function, so the ideal place for this would be a field in the User model, but Django's built-in user framework makes it difficult to add fields to the user relation itself. Two possible solutions that have been proposed:
Profile
model that could also be used to store other one-to-one user columns that are not present in the built-in relation. (At this time it's unclear if we have any other such requirements, but they are generally common.)(user_id, quota_id)
, both of which columns have independent unique constraints.