kitware-resonant / dkc-next

Apache License 2.0
3 stars 0 forks source link

Move Quota.user field to a separate relation #135

Open zachmullen opened 3 years ago

zachmullen commented 3 years ago

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:

  1. Create an auxiliary 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.)
  2. Create a dedicated associative relation (user_id, quota_id), both of which columns have independent unique constraints.
brianhelba commented 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).

brianhelba commented 3 years ago

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?

zachmullen commented 3 years ago

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.